2017-10-02 16 views
-1

Ich habe eine OntologieJava owlapi extrahieren

<owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000050"> 
    <owl:inverseOf rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/> 
    <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">BFO:0000050</oboInOwl:hasDbXref> 
    <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">external</oboInOwl:hasOBONamespace> 
    <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part_of</oboInOwl:id> 
    <oboInOwl:shorthand rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part_of</oboInOwl:shorthand> 
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part of</rdfs:label> 
</owl:ObjectProperty> 

Ich versuche, alle ObjectProperties zu extrahieren,

for (OWLObjectProperty obp : ont.getObjectPropertiesInSignature()){ 
    System.out.println(obp.toString()); 
} 

diese den Namen von Object gedruckt wird, zum Beispiel http://purl.obolibrary.org/obo/BFO_0000050.

Ich frage mich, wie man die rdfs: label, z.B. Teil von

Antwort

0

Die rdfs:label in OWL ist eine annotation. Um die label zu erhalten, müssen Sie die Annotation der gewünschten objectProperty abfragen.

Um alle Anmerkungen einer Ontologie zeigen Sie so etwas tun kann:

final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(my_file)); 

final List<OWLAnnotation> annotations = ontology.objectPropertiesInSignature()// 
    .filter(objectProperty -> objectProperty.equals(the_object_property_I_want))// 
    .flatMap(objectProperty -> ontology.annotationAssertionAxioms(objectProperty.getIRI()))// 
    .map(OWLAnnotationAssertionAxiom::getAnnotation)// 
    .collect(Collectors.toList()); 

for (final OWLAnnotation annotation : annotations) 
    System.out.println(annotation.getProperty() + "\t" + annotation.getValue()); 

getObjectPropertiesInSignature() ist veraltet in der modernen (mehr als ein Jahr) Version von owlapi (5). Bitte beachten Sie die stream Version objectPropertiesInSignature von java-8. java-9 wurden vor wenigen Tagen veröffentlicht, so ist es eine gute Zeit, um die stream Funktionalität zu lernen.

NB: Die Anmerkungen sind fast frei, aber OWL2 haben etwas mehr Standardisierung darauf gesetzt, also gibt es Anmerkungen mit 'vordefinierter Semantik'.

+0

Dies ist eine großartige Lösung. Ich bin neu in diesem und anderen Klassen hängt schwer von owlapi 4.3. Gibt es eine Chance, dass Sie eine 4.3 Version dieser Lösung erstellen können? – ThanksMate

+0

für (endgültige OWLObjectProperty OProp: ontology.getObjectPropertiesInSignature()) für (endgültige OWLAnnotationAssertionAxiom Axiom: ontology.getAnnotationAssertionAxioms (oprop.getIRI())) \t \t \t System.out.printin (OProp + "\ t" + axiom.getAnnotation ().Wert erhalten()); Sorry, ich übergebe das mit alten Versionen. – Galigator

+0

Tut mir leid Kumpel, ich habe dein Beispiel in, ich habe, 'code' \t [email protected], Könnten Sie Hilf mir, das zu lösen? – ThanksMate

Verwandte Themen