简体   繁体   English

从java中的owl获取所有classess,sub classess

[英]get all classess, sub classess from owl in java

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. 我检查了OWLAPI,但我对语义非常新。 In order to get , 为了得到 ,

like following example, using owl2api i need a code , 像下面的例子,使用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());
    }
}

thank you 谢谢

Not sure if that's what you need, but 不确定这是否是你需要的,但是

OwlOntology.getClassesInSignature() 

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 一旦你拥有了OwlClass,你就可以使用它来获得它的子类

 OwlClass.getSubClasses(OWLOntology)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM