从java中的owl获取所有类、子类
我有本体文件。猫头鹰 由此我需要从 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());
}
}
谢谢
I have ontology file. owl
from that i need to get all classes, subclasses from 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);
then what should i write? i checked OWLAPI, but i am very new on semantic. In order to get ,
like following example, using owl2api i need a code ,
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());
}
}
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否是您所需要的,但
返回用于在当前本体中构建公理的所有类的集合。
另外,一旦你有了 OwlClass,你就可以使用它来获取它的子类
Not sure if that's what you need, but
returns the set of all classes that are used to build axioms in the current ontology.
Also once you have OwlClass you can get it's subclasses using