我的本体有以下三元组,其中主语是本体本身。 Protégé 在“活动本体”选项卡(“本体标题”部分)中将它们可视化为“注释”。
<http://myOntology/testOnto> rdf:type owl:Ontology ;
<http://purl.org/dc/elements/1.1/creator> "Andrea"@it ;
<http://purl.org/dc/elements/1.1/title> "test"@it ;
rdfs:label "Andrea"@it .
如何使用 OWL API 检索它们?
OWLOntology
实现了HasAnnotations
接口,这些是本体本身的注释。因此,您可以使用 annotations
(或 annotationsAsList
)方法来实现:
StringDocumentSource source = new StringDocumentSource("""
<http://myOntology/testOnto> rdf:type owl:Ontology ;
<http://purl.org/dc/elements/1.1/creator> "Andrea"@it ;
<http://purl.org/dc/elements/1.1/title> "test"@it ;
rdfs:label "Andrea"@it .""");
OWLOntologyManager ontologyManager; // Init ontology manager
OWLOntology loaded = ontologyManager.loadOntologyFromOntologyDocument(source);
List<OWLAnnotation> annotations = loaded.annotationsAsList();
System.out.println(annotations);