gpt4 book ai didi

java - 如何在 OWLAPI 中同步推理器

转载 作者:行者123 更新时间:2023-12-01 09:57:28 30 4
gpt4 key购买 nike

我得到了一个关于个体的小本体。其中一些个体应该通过对称 ObjectProperty 相互连接。

我需要使用 Pellet Reasoner,以便它可以同步并将对称 ObjectProperty 附加到个体。

我使用 OWLAPI 来创建本体。我创建 ObjectProperty 的代码是:

// create the OWLObjectProperty isLinkedTo
OWLObjectProperty isLinkedTo = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#" +hasLinkStr));
// create a set for the axioms (OPAS - Obj.Prop.Axioms Set)
Set<OWLAxiom> isLinkedOPAS = new HashSet<OWLAxiom>();
// add the OWLObjectProperty isLinkedTo to the set isLinkedOPAS
OWLNamedIndividual prevNamedInd = factory.getOWLNamedIndividual(prevIndividual, pm);
isLinkedOPAS.add(factory.getOWLSymmetricObjectPropertyAxiom(isLinkedTo));
//setting the object property for the current (namedInd) and previous (prevNamedInd)individuals
isLinkedOPAS.add(factory.getOWLObjectPropertyAssertionAxiom(isLinkedTo, namedInd, prevNamedInd));
manager.addAxioms(ontology, isLinkedOPAS);

个体是一个接一个被创建的。每个下一个isLinkedTo前一个具有对称属性。

然后,我启动推理机,但我不确定我是否以正确的方式执行:

OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, config);
// I am not sure which of these commands is necessary for checking the ObjectProperty assertions
reasoner.precomputeInferences();
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY);
boolean consistent = reasoner.isConsistent();
System.out.println("Consistent: " + consistent);

当我在 Protege 中打开这个本体时,它向我显示了个体,但没有与 ObjectProperty isLinkedTo 对称地“连接”:

enter image description here

只有在Protege中运行reasoner后才显示正确的方式:

enter image description here

所以问题是:我应该在代码中编写什么才能获得推理器同步对象属性的本体?

最佳答案

这三行:

reasoner.precomputeInferences();
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY);

可以替换为:

reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS,
InferenceType.OBJECT_PROPERTY_HIERARCHY);

但是,对于大多数推理者来说,这与:

reasoner.precomputeInferences(InferenceType.values());

为了在不运行推理器的情况下查看推断的公理,您可以使用 org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator :

InferredPropertyAssertionGenerator generator = new InferredPropertyAssertionGenerator();
Set<OWLAxiom> axioms = generator.createAxioms(factory, reasoner);

这将提供推断的公理以添加到本体中。

关于java - 如何在 OWLAPI 中同步推理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37075467/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com