gpt4 book ai didi

java - Java中OWL 2本体不一致的解释

转载 作者:行者123 更新时间:2023-11-30 03:22:16 27 4
gpt4 key购买 nike

我试图找出本体是否不一致,如果不一致,则打印哪些是导致不一致的类/公理。我得到了关于不一致检查的正确结果,但是在打印不一致背后的公理列表时我被卡住了。我尝试了stackoverflow问题中提到的方法,但它不起作用。

我检查过,问题是 explanations 变量中没有存储任何解释列表。你能指出我错在哪里吗?

    package com.tcs.HermiT;

import java.io.File;
import java.util.Set;





import org.semanticweb.HermiT.Configuration;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.HermiT.Reasoner.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;

import com.clarkparsia.owlapi.explanation.BlackBoxExplanation;
import com.clarkparsia.owlapi.explanation.ExplanationGenerator;
import com.clarkparsia.owlapi.explanation.HSTExplanationGenerator;

public class Demo {

public void reason() throws OWLOntologyCreationException {
// First, we create an OWLOntologyManager object. The manager will load and save ontologies.
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory=m.getOWLDataFactory();

File inputOntologyFile = new File("C:\\Users\\1047785\\Desktop\\HermiT\\Input10.owl");
OWLOntology o=m.loadOntologyFromOntologyDocument(inputOntologyFile);// Now, we instantiate HermiT by creating an instance of the Reasoner class in the package org.semanticweb.HermiT.



ReasonerFactory factory = new ReasonerFactory();
Configuration configuration=new Configuration();
configuration.throwInconsistentOntologyException = false;
OWLReasoner reasoner=factory.createReasoner(o, configuration);

System.out.println("Consistency : "+reasoner.isConsistent());
System.out.println("Computing explanations for the inconsistency...");
factory=new Reasoner.ReasonerFactory() {
protected OWLReasoner createHermiTOWLReasoner(org.semanticweb.HermiT.Configuration configuration,OWLOntology o) {
// don't throw an exception since otherwise we cannot compte explanations
configuration.throwInconsistentOntologyException=false;
return new Reasoner(configuration,o);
}
};


BlackBoxExplanation exp=new BlackBoxExplanation(o, factory, reasoner);
HSTExplanationGenerator multExplanator=new HSTExplanationGenerator(exp);
// Now we can get explanations for the inconsistency
Set<Set<OWLAxiom>> explanations=multExplanator.getExplanations(dataFactory.getOWLThing());

// Let us print them. Each explanation is one possible set of axioms that cause the
// unsatisfiability.
for (Set<OWLAxiom> explanation : explanations) {
System.out.println("------------------");
System.out.println("Axioms causing the inconsistency: ");
for (OWLAxiom causingAxiom : explanation) {
System.out.println(causingAxiom);
}
System.out.println("------------------");
}


}
}

输出如下

一致性:true/false(正确结果)

不一致的计算解释

最佳答案

owl api 中的解释类很古老并且效率不高。 GitHub 上 Matthew Horridge 维护的 owlexplanation 项目中有替代品。您可以尝试调整代码以使用它们。不幸的是,我没有方便的例子。

关于java - Java中OWL 2本体不一致的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31068183/

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