1

如何使用 OWL-API 从本体中获取现有类?这是我本体的一个片段:

<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>

我从这段代码开始:

String ontologyUri = "http://mysite.com/my_ontology.owl";
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(IRI.create(ontologyUri));
OWLDataFactory factory = manager.getOWLDataFactory();

现在我想检索StringDocu课程。我怎样才能得到这个?

4

2 回答 2

2

从您在问题中显示的代码继续,您可以获得对类的直接引用,如下所示(我假设您的类 URI 是“http://mysite.com/my_ontology.owl#StringDocu”):

OWLClass stringDocuClass = factory.getOWLClass(IRI.create("http://mysite.com/my_ontology.owl#StringDocu"))

这使您可以直接参考您所学的课程,并且可以从那里学习。

希望这可以帮助!

于 2010-12-30T16:21:34.840 回答
1

我认为这将为您提供加载的本体中引用的所有类:

String ontologyUri = "http://mysite.com/my_ontology.owl";
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology(IRI.create(ontologyUri));
Set <OWLClass> classes = ontology.getClassesInSignature();

然后,您可以处理/过滤/查找该组所需的任何内容OWLClass

于 2010-07-21T09:40:07.433 回答