gpt4 book ai didi

java - Hermit 和 OWLApi 用于检索对象属性断言

转载 作者:行者123 更新时间:2023-12-02 11:37:36 25 4
gpt4 key购买 nike

我尝试从 Reasoner (hermit 1.3.8.4) 和 OWLApi (3.4.10) 检索属性断言。在这张图片中,我想检索“isGrandfather Sandro,isGrandfather Sergio”。

Picture - object property assertions

我尝试在 https://stackoverflow.com/a/37497541/3760251 中使用 Ignazio 答案:

以 Horridge 为例,但 OWL API 更改了签名,我不知道如何使用它。 https://www.javatips.net/api/Owl-master/owlapi-master/tools/src/main/java/org/semanticweb/owlapi/util/InferredSubObjectPropertyAxiomGenerator.java

所以,如果您有来自 InferredObjectPropertyAxiomGenerator 的 addAxioms 方法的示例,我很感激。

InferredObjectPropertyAxiomGenerator 生成器 = new InferredObjectPropertyAxiomGenerator() { @覆盖 protected void addAxioms(OWLEntity 实体, OWLReasoner 推理机, OWLDataFactory dataFactory, 设置结果) { }}

谢谢

最佳答案

我在 Ignazio 中找到了一段很棒的代码:https://github.com/owlcs/owlapi/issues/643

我对您的代码进行了细微更改,并使用 OWLAPI 4.3.1-SNAPSHOT 和 HermiT 1.3.8.431-SNAPSHOT 运行它(这些版本包含问题 #646 中详细说明的修复)

输出文件包含对象属性:

public static void main(String[] args) throws Exception {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntology(
IRI.create("https://raw.githubusercontent.com/owlcs/pizza-ontology/master/pizza.owl"));
OWLDataFactory df = manager.getOWLDataFactory();

Configuration configuration = new Configuration();
configuration.ignoreUnsupportedDatatypes = true;
ReasonerFactory rf = new ReasonerFactory();

OWLReasoner reasoner = rf.createReasoner(ontology, configuration);
boolean consistencyCheck = reasoner.isConsistent();
if (consistencyCheck) {
reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY,
InferenceType.CLASS_ASSERTIONS, InferenceType.OBJECT_PROPERTY_HIERARCHY,
InferenceType.DATA_PROPERTY_HIERARCHY, InferenceType.OBJECT_PROPERTY_ASSERTIONS);

List<InferredAxiomGenerator<? extends OWLAxiom>> generators = new ArrayList<>();
generators.add(new InferredSubClassAxiomGenerator());
generators.add(new InferredClassAssertionAxiomGenerator());
generators.add(new InferredDataPropertyCharacteristicAxiomGenerator());
generators.add(new InferredEquivalentClassAxiomGenerator());
generators.add(new InferredEquivalentDataPropertiesAxiomGenerator());
generators.add(new InferredEquivalentObjectPropertyAxiomGenerator());
generators.add(new InferredInverseObjectPropertiesAxiomGenerator());
generators.add(new InferredObjectPropertyCharacteristicAxiomGenerator());

// NOTE: InferredPropertyAssertionGenerator significantly slows down
// inference computation
generators.add(new org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator());

generators.add(new InferredSubClassAxiomGenerator());
generators.add(new InferredSubDataPropertyAxiomGenerator());
generators.add(new InferredSubObjectPropertyAxiomGenerator());
List<InferredIndividualAxiomGenerator<? extends OWLIndividualAxiom>> individualAxioms =
new ArrayList<>();
generators.addAll(individualAxioms);

generators.add(new InferredDisjointClassesAxiomGenerator());
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, generators);
OWLOntology inferredAxiomsOntology = manager.createOntology();
iog.fillOntology(df, inferredAxiomsOntology);
File inferredOntologyFile = new File("output.txt");
// Now we create a stream since the ontology manager can then write to that stream.
try (OutputStream outputStream = new FileOutputStream(inferredOntologyFile)) {
// We use the same format as for the input ontology.
manager.saveOntology(inferredAxiomsOntology, outputStream);
}
} // End if consistencyCheck
else {
System.out.println("Inconsistent input Ontology, Please check the OWL File");
}
}

关于java - Hermit 和 OWLApi 用于检索对象属性断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48812279/

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