설명 된 구조 유형을 포함하는 온톨로지를 다시 작성하고 관심있는 특수 효과 속성 값을 검색하는 방법을 보여주는 코드입니다. getSampleOntology()
은 온톨로지를 만들고 (인쇄하고) main
x
에서 시작하여 hasSynonym
값을 찾은 다음 그 값 중 rdfs:label
초를 찾을 수있는 방법을 보여줍니다. 이는 설명서의 OWL API code examples을 기반으로합니다.
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget;
import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnnotationSubject;
import org.semanticweb.owlapi.model.OWLAnonymousIndividual;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyFormat;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
public class OWLAPIAnnotations {
final static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
final static OWLDataFactory factory = manager.getOWLDataFactory();
final static String ns = "http://example.org/";
final static OWLNamedIndividual x = factory.getOWLNamedIndividual(IRI.create(ns+"x"));
final static OWLAnonymousIndividual y = factory.getOWLAnonymousIndividual();
final static OWLObjectProperty hasSynonym = factory.getOWLObjectProperty(IRI.create(ns + "hasSynonym"));
public static OWLOntology getSampleOntology() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntology ontology = manager.createOntology();
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(factory.getOWLClass(IRI.create(ns + "Synonym")), y));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasSynonym, x, y));
OWLAnnotation ann = factory.getOWLAnnotation(factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()), factory.getOWLLiteral("Endocardium", "en"));
manager.addAxiom(ontology, factory.getOWLAnnotationAssertionAxiom(y, ann));
manager.saveOntology(ontology, System.out);
return ontology;
}
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntology ontology = getSampleOntology();
for(OWLIndividual object : x.getObjectPropertyValues(hasSynonym, ontology)) {
for (OWLAnnotationAssertionAxiom aAxiom : ontology.getAnnotationAssertionAxioms((OWLAnnotationSubject) object)) {
if (aAxiom.getProperty().equals(factory.getRDFSLabel())) {
System.out.println(aAxiom.getValue());
}
}
}
}
}
(주석 값 것을 나타낸다) 단부에서의 출력은 :
"Endocardium"@en
생성 된 온톨로지 (주석 공간을 제거하여)이다
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.w3.org/2002/07/owl"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:example="http://example.org/">
<ObjectProperty rdf:about="http://example.org/hasSynonym"/>
<Class rdf:about="http://example.org/Synonym"/>
<NamedIndividual rdf:about="http://example.org/x">
<example:hasSynonym>
<rdf:Description>
<rdf:type rdf:resource="http://example.org/Synonym"/>
<rdfs:label xml:lang="en">Endocardium</rdfs:label>
</rdf:Description>
</example:hasSynonym>
</NamedIndividual>
</rdf:RDF>
I을 온톨로지를 더 많이 보여줘야한다고 생각해. 보여준 단편은 3 중 일부에 지나지 않습니다. 'oboInOwl : hasSynonym'은 속성이고, 객체는'rdf : type'과'rdfs : label'을 가진 공백 노드입니다. 트리플의 주제가 무엇인지 아는 것이 도움이 될 수 있습니다. 왜냐하면 그 때 우리는 그것을 개인으로 식별하고 그 속성에 대해 물을 수 있기 때문입니다. –