我正在重写一个Java程序,该程序读取OWL文件并构建图形数据库。该程序使用了较旧的OWLAPI版本,现已弃用了许多get方法。我已经重构了代码以使用Stream。现在,我正在尝试检索OWL文件中每个类的子类。
使用OWLSubClassOfAxiom可以检索所需的子类,但仍需要过滤结果以仅获取子类
final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = load(manager);
//--create a reasoner to check that the ontology is consistent
OWLReasonerFactory reasonerFactory = new
StructuralReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
reasoner.precomputeInferences();
boolean consistent = reasoner.isConsistent();
if (consistent) {
//--get all classes in the ontology
for (OWLClass oc : ontology.classesInSignature().collect(Collectors.toSet())) {
System.out.println( "Class: " + oc.toString() );
//--get all the SubClassOfAxiom of each class
for (OWLSubClassOfAxiom sca: ontology.subClassAxiomsForSuperClass(oc).collect(Collectors.toSet())) {
System.out.println( " Subclass: " + sca.toString() );
}
}
}
输出示例如下:
Class: <http://www.nist.gov/el/ontologies/kitting.owl#PoseLocation>
Subclass: SubClassOf(<http://www.nist.gov/el/ontologies/kitting.owl#PoseLocationIn> <http://www.nist.gov/el/ontologies/kitting.owl#PoseLocation>)
在此示例中,使用owlapi 5.1,如何检索PoseLocationIn
的子类PoseLocation
?
答案 0 :(得分:0)
使用Searcher
类,是为了方便地替换从OWLAPI 3到5删除的方法。Searcher::getSubClasses
可以完成相同的工作。