如何使用owlapi从加载的本体中获取所有类?这里我有一个关于如何获得一个类的示例,但我对访问本体中定义的所有类感兴趣。
OWLOntologyManager manager = WLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntology(IRI.create(fileURI));
OWLDataFactory owlDF = manager.getOWLDataFactory();
//Example to get ONE class, but I want ALL!
OWLClass stringDocuClass = owlDF.getOWLClass(IRI.create("http://example.com/my_ontology.owl#StringDocu"));
我正在使用java owlapi 4.2.3(参见API:http://owlapi.sourceforge.net/javadoc/)
答案 0 :(得分:4)
使用
Set<OWLClass> classes = ontology.getClassesInSignature();
答案 1 :(得分:2)
从OWLAPI 5.0开始,可以使用流迭代器:
ArrayList<OWLClass> classes = new ArrayList<OWLClass>();
ontology.classesInSignature().forEach(classes::add);