[英]OWL: get Class from an existent Antology
How can I get an existing Class from an Ontology with the OWL-API? 如何使用OWL-API从本体中获取现有的类? This is a fragment of my ontology:
这是我的本体的一部分:
<owl:Class rdf:ID="StringDocu">
<owl:equivalentClass>
<owl:Restriction>
<owl:someValuesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<owl:onProperty rdf:resource="#hasContent"/>
</owl:Restriction>
</owl:equivalentClass>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>String Docu</rdfs:label>
<rdfs:subClassOf rdf:resource="#Docu"/>
<owl:disjointWith rdf:resource="#URIDocu"/>
<rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>This class concerns a docu with the content specified as common text.</rdfs:comment>
</owl:Class>
I start with this code: 我从以下代码开始:
String ontologyUri = "http://mysite.com/my_ontology.owl";
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(IRI.create(ontologyUri));
OWLDataFactory factory = manager.getOWLDataFactory();
and now I want to retrieve the StringDocu
class. 现在我想检索
StringDocu
类。 How can I get this? 我怎么能得到这个?
continuing from the code you showed in your question, you can get a direct reference to the class as follows (I assume that your class URI is "http://mysite.com/my_ontology.owl#StringDocu"): 从问题中显示的代码继续,您可以按如下方式直接访问该类(假定您的类URI为“ http://mysite.com/my_ontology.owl#StringDocu”):
OWLClass stringDocuClass = factory.getOWLClass(IRI.create("http://mysite.com/my_ontology.owl#StringDocu"))
That gives you a direct reference to the class you are after and you can take it from there. 这样可以直接引用您要上的课程,然后可以从那里上课。
Hope this helps! 希望这可以帮助!
I think this will give you all classes referenced in the ontology you loaded: 我认为这将为您提供加载的本体中引用的所有类:
String ontologyUri = "http://mysite.com/my_ontology.owl";
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(IRI.create(ontologyUri));
Set <OWLClass> classes = ontology.getClassesInSignature();
Then you can process/filter/find whatever you need on that set of OWLClass
. 然后,您可以
OWLClass
集合进行所需的处理/过滤/查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.