我使用 OWL API 4.1.3 来加载我的本体并不大。由于我需要使用推断信息,我还使用 Hermit 1.3.8.413 库进行推理。以下代码显示了我是如何完成它的。
public class ReasonRDF {
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
readRDF("C:/Users/workspace/Ontology_matching/NVDB_Matching_v18_H_4_1_CONVERTYING/results/NewInstantiated/owl/OSM1.owl");
}
public static void readRDF(String address) throws OWLOntologyCreationException, OWLOntologyStorageException{
OWLOntologyManager manager =OWLManager.createOWLOntologyManager();
File file = new File (address);
OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create(file));
System.out.println("Ontology Loaded...");
System.out.println("Logical IRI : " + ont.getOntologyID());
System.out.println("Format : " + manager.getOntologyFormat(ont));
System.out.println("Runtime memory: " + Runtime.getRuntime().totalMemory());
ReasonerFactory reasonerFactory = new ReasonerFactory();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
Configuration config = new Configuration();
config.ignoreUnsupportedDatatypes=true;
config.reasonerProgressMonitor= progressMonitor;
OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);
long t0 = System.nanoTime();
System.out.println("Starting to add axiom generators");
OWLDataFactory datafactory = manager.getOWLDataFactory();
List> inferredAxioms = new ArrayList>();
//inferredAxioms.add(new InferredSubClassAxiomGenerator());
inferredAxioms.add(new InferredClassAssertionAxiomGenerator());
//inferredAxioms.add(new InferredDataPropertyCharacteristicAxiomGenerator());
//inferredAxioms.add(new InferredObjectPropertyCharacteristicAxiomGenerator());
//inferredAxioms.add(new InferredEquivalentClassAxiomGenerator());
//inferredAxioms.add(new InferredPropertyAssertionGenerator());
//inferredAxioms.add(new InferredInverseObjectPropertiesAxiomGenerator());
inferredAxioms.add(new InferredSubDataPropertyAxiomGenerator());
inferredAxioms.add(new InferredSubObjectPropertyAxiomGenerator());
System.out.println("finished adding axiom generators");
// List> individualAxioms= new ArrayList>();
// inferredAxioms.addAll(individualAxioms);
// for writing inferred axioms to the new ontology
OWLOntology infOnt = manager.createOntology(IRI.create(ont.getOntologyID().getOntologyIRI().get()+"_inferred"));
// use generator and reasoner to infer some axioms
System.out.println("Starting to infer");
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, inferredAxioms);
//InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
System.out.println("Inferrence is over");
System.out.println("Storing the results");
iog.fillOntology(datafactory,infOnt);
System.out.println("Results are stored");
long elapsed_time = System.nanoTime()-t0;
System.out.println(elapsed_time);
// save the ontology
manager.saveOntology(infOnt, IRI.create("file:///C:/Users/ontologies/NVDB4_test.rdf"));
}
}
它不会抛出任何错误,但需要将推断的本体存储在新文件中。事实上,即使在 2 天之后它也无法完成工作。我的 IDE 是 eclipse EE,我已经提供了 6 到 12 GB 的内存来运行这个应用程序。我发现我的代码或本体没有任何问题。
有人可以建议优化,甚至可能是更好的实施方式或其他 api?
这里是我的本体论,以防有人想测试它。