[英]Print the hierarchy of an ontology using HermiT
I'm having a problem using the HermiT reasoner library. 使用HermiT推理程序库时遇到问题。
Is there anyone who understands what I am doing wrong here? 这里有人知道我在做什么错吗?
public static void main(String[] args) {
try {
// First, we create an OWLOntologyManager object. The manager will load and
// save ontologies.
OWLOntologyManager manager=OWLManager.createOWLOntologyManager();
// Now, we create the file from which the ontology will be loaded.
File inputOntologyFile = new File("SchoolESTGExample.owl");
// We use the OWL API to load the ontology.
OWLOntology ontology=manager.loadOntologyFromOntologyDocument(inputOntologyFile);
// Now we can start and create the reasoner. Here we create an instance of HermiT
// OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
//OWLReasoner owlReasoner = reasonerFactory.createReasoner(ontology);
Reasoner reasoner = new Reasoner(ontology);
reasoner.precomputeInferences();
// We can determine if the ontology is actually consistent
if (reasoner.isConsistent()) {
// Now we create an output stream that HermiT can use to write the axioms. The output stream is
// a wrapper around the file into which the axioms are written.
File prettyPrintHierarchyFile=new File("prettyPrint.owl");
if (!prettyPrintHierarchyFile.exists())
prettyPrintHierarchyFile.createNewFile();
// turn to an absolute file, so that we can write to it
prettyPrintHierarchyFile=prettyPrintHierarchyFile.getAbsoluteFile();
BufferedOutputStream prettyPrintHierarchyStreamOut=new BufferedOutputStream(new FileOutputStream(prettyPrintHierarchyFile));
// The output stream is wrapped into a print write with autoflush.
PrintWriter output=new PrintWriter(prettyPrintHierarchyStreamOut,true);
// Now we let HermiT pretty print the hierarchies. Since all parameters are set to true,
// HermiT will print the class and the object property and the data property hierarchy.
long t=System.currentTimeMillis();
t=System.currentTimeMillis()-t;
reasoner.printHierarchies(output, true, true, true);
// Now save a copy in OWL/XML format
//File f = new File("example.xml");
//IRI documentIRI2 = IRI.create(f);
//manager.saveOntology(school, new OWLXMLOntologyFormat(), documentIRI2);
//System.out.println("Ontology saved in XML format.");
} else {
System.out.println("Ontology malformed.");
}
// Remove the ontology from the manager
//manager.removeOntology(ontology);
} catch (OWLOntologyCreationException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Console output: 控制台输出:
Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyID.getDefaultDocumentIRI()Lorg/semanticweb/owlapi/model/IRI;
at org.semanticweb.HermiT.structural.OWLClausification.preprocessAndClausify(Unknown Source)
at org.semanticweb.HermiT.Reasoner.loadOntology(Unknown Source)
at org.semanticweb.HermiT.Reasoner.<init>(Unknown Source)
at org.semanticweb.HermiT.Reasoner.<init>(Unknown Source)
at App.main(App.java:34)
Thanks. 谢谢。
After some another researches i found the problem. 经过另一番研究,我发现了问题所在。 HermiT 3.4 or 3.5 even not works with OWL API 4.0.
HermiT 3.4或3.5甚至不适用于OWL API 4.0。 I just change to OWL API 3.5 and everything works well.
我只是更改为OWL API 3.5,一切正常。 Feel free to use it.
随意使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.