자바

2017-10-02 3 views
-1

를 추출 owlapi 나는 온톨로지이을 ObjectProperty, 예를 들어,의 이름을 인쇄합니다자바

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

나는 모든 ObjectProperties를 추출하기 위해 노력하고있어

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

에게,이 http://purl.obolibrary.org/obo/BFO_0000050.

나는 어떻게 rdfs : label을 얻는 지 궁금해.

답변

0

OWL의 rdfs:label 부분은 annotation입니다. label을 얻으려면 원하는 objectProperty의 주석을 쿼리해야합니다.

당신이 그런 식으로 뭔가를 할 수 온톨로지의 모든 주석을 표시하려면 :

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()는 owlapi의 현대 (이상 1 년) 버전에서 더 이상 사용되지 않습니다 (5). 따라서 stream 버전 objectPropertiesInSignaturejava-8으로 사용하시기 바랍니다. java-9이 며칠 전에 출시되었으므로 stream 기능을 익히는 좋은시기입니다.

NB : 주석은 거의 무료이지만, OWL2에는 더 많은 표준화가 적용되어 있으므로 '미리 ​​정의 된 의미'가있는 주석이 있습니다.

+0

이것은 훌륭한 해결책입니다. 나는 이것에 익숙하지 않고 다른 클래스는 owlapi 4.3에 무겁다. 이 솔루션의 4.3 버전을 만들 수있는 기회가 있습니까? 위한 – ThanksMate

+0

(최종 OWLObjectProperty의 oprop : ontology.getObjectPropertiesInSignature())에 대한 (최종 OWLAnnotationAssertionAxiom 공리 : ontology.getAnnotationAssertionAxioms (oprop.getIRI())) \t \t \t에서 System.out.println (oprop + "\ t"+ axiom.getAnnotation () .getValue()); 죄송합니다. 구 버전에서이 작업을 수행합니다. – Galigator

+0

죄송합니다. 당신의 예를 들어 보겠습니다. 'code' \t [email protected], 이 문제를 해결하도록 도와 주시겠습니까? – ThanksMate