我有本体文件。猫头鹰 从那里我需要从owl
获取所有类,子类File file = new File("myontology.owl");
OWLOntology myontology = manager.loadOntologyFromOntologyDocument(file);
System.out.println("Loaded ontology: " + myontology);
// We can always obtain the location where an ontology was loaded from
IRI documentIRI = manager.getOntologyDocumentIRI(myontology);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLClass clsOwl = factory.getOWLClass(documentIRI);
那我该怎么写?我检查了OWLAPI,但我对语义非常新。为了得到,
如下面的例子,使用owl2api我需要一个代码,
String uri = "http://protege.cim3.net/file/pub/ontologies/travel/travel.owl";
OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
Collection classes = owlModel.getUserDefinedOWLNamedClasses();
for (Iterator it = classes.iterator(); it.hasNext();) {
OWLNamedClass cls = (OWLNamedClass) it.next();
Collection instances = cls.getInstances(false);
System.out.println("Class " + cls.getBrowserText() + " (" + instances.size() + ")");
for (Iterator jt = instances.iterator(); jt.hasNext();) {
OWLIndividual individual = (OWLIndividual) jt.next();
System.out.println(" - " + individual.getBrowserText());
}
}
谢谢
答案 0 :(得分:2)
不确定这是否是您需要的,但
OwlOntology.getClassesInSignature()
返回用于在当前本体中构建公理的所有类的集合。
一旦你拥有了OwlClass,你就可以使用
获得它的子类 OwlClass.getSubClasses(OWLOntology)