2010-08-14 42 views
1

讀出從OWL本體具體數值我有一個OWL本體:如何使用Java

<?xml version="1.0"?> 
<rdf:RDF 
    xmlns="http://www.owl-ontologies.com/Ontology1272923485.owl#" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" 
    xml:base="http://www.owl-ontologies.com/Ontology1272923485.owl"> 
    <owl:Ontology rdf:about=""/> 
    <owl:Class rdf:ID="studypath"> 
    <owl:disjointWith> 
     <owl:Class rdf:ID="module"/> 
    </owl:disjointWith> 
    <owl:disjointWith> 
     <owl:Class rdf:ID="docent"/> 
    </owl:disjointWith> 
    </owl:Class> 
    <owl:Class rdf:about="#docent"> 
    <owl:disjointWith> 
     <owl:Class rdf:about="#module"/> 
    </owl:disjointWith> 
    <owl:disjointWith rdf:resource="#studypath"/> 
    <rdfs:subClassOf> 
     <owl:Restriction> 
     <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int" 
          >1</owl:minCardinality> 
     <owl:valuesFrom> 
      <owl:Class rdf:about="#module"/> 
     </owl:valuesFrom> 
     <owl:onProperty> 
      <owl:ObjectProperty rdf:ID="responsiblefor"/> 
     </owl:onProperty> 
     </owl:Restriction> 
    </rdfs:subClassOf> 
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/> 
    </owl:Class> 
    <owl:Class rdf:about="#module"> 
    <rdfs:subClassOf> 
     <owl:Restriction> 
     <owl:onProperty> 
      <owl:ObjectProperty rdf:ID="predecessor_module"/> 
     </owl:onProperty> 
     <owl:someValuesFrom rdf:resource="#module"/> 
     </owl:Restriction> 
    </rdfs:subClassOf> 
    <rdfs:subClassOf> 
     <owl:Restriction> 
     <owl:someValuesFrom rdf:resource="#module"/> 
     <owl:onProperty> 
      <owl:ObjectProperty rdf:ID="folgemodule"/> 
     </owl:onProperty> 
     </owl:Restriction> 
    </rdfs:subClassOf> 
    <rdfs:subClassOf> 
     <owl:Restriction> 
     <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#int" 
          >1</owl:minCardinality> 
     <owl:onProperty> 
      <owl:ObjectProperty rdf:ID="offeredfor"/> 
     </owl:onProperty> 
     <owl:valuesFrom rdf:resource="#studypath"/> 
     </owl:Restriction> 
    </rdfs:subClassOf> 
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/> 
    <owl:disjointWith rdf:resource="#docent"/> 
    <owl:disjointWith rdf:resource="#studypath"/> 
    </owl:Class> 
    <owl:ObjectProperty rdf:about="#predecessor_module"> 
    <rdfs:range rdf:resource="#module"/> 
    <rdfs:domain rdf:resource="#module"/> 
    <owl:inverseOf> 
     <owl:ObjectProperty rdf:about="#folgemodule"/> 
    </owl:inverseOf> 
    </owl:ObjectProperty> 
    <owl:ObjectProperty rdf:about="#folgemodule"> 
    <owl:inverseOf rdf:resource="#predecessor_module"/> 
    <rdfs:range rdf:resource="#module"/> 
    <rdfs:domain rdf:resource="#module"/> 
    </owl:ObjectProperty> 
    <owl:ObjectProperty rdf:about="#offeredfor"> 
    <rdfs:range rdf:resource="#studypath"/> 
    <rdfs:domain rdf:resource="#module"/> 
    </owl:ObjectProperty> 
    <owl:ObjectProperty rdf:about="#responsiblefor"> 
    <rdfs:domain rdf:resource="#docent"/> 
    <rdfs:range rdf:resource="#module"/> 
    </owl:ObjectProperty> 
    <module rdf:ID="Datenbanken"> 
    <offeredfor> 
     <studypath rdf:ID="WIN"/> 
    </offeredfor> 
    </module> 
    <docent rdf:ID="John_Smith"> 
    <responsiblefor rdf:resource="#Datenbanken"/> 
    </docent> 
    <module rdf:ID="Softwaretechnik"/> 
    <docent rdf:ID="Wayne_Smith"> 
    <responsiblefor rdf:resource="#Softwaretechnik"/> 
    </docent> 
</rdf:RDF> 

現在我使用的Java API進行查詢的本體。例如,如果我有Wayne_Smith,我該如何查詢他負責的模塊?

回答

1

Wayne,你正在使用哪種api?如果是曼徹斯特貓頭鷹API,你會在他們的文檔here中找到一些代碼示例,這應該可以幫助你解決這個問題。

1

如果我理解正確你的問題,你指的是Java API的是OWL API,這應該做的伎倆:

/*Load your ontology from a local file and do the initialisations*/ 
File inputfile = new File("ontologyPath"); 
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); ; 
OWLDataFactory dataFactory = manager.getOWLDataFactory(); 
OWLOntology yourOntology = manager.loadOntologyFromOntologyDocument(inputfile); 
IRI ontologyIRI = yourOntology.getOntologyID().getOntologyIRI(); 

/*Get the object property and the individual you're interested in*/ 
OWLObjectProperty o_p_responsible_for = dataFactory.getOWLObjectProperty(IRI.create(ontologyIRI + "#"+"Responsiblefor")); 
OWLIndividual ind_Wayne = dataFactory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#"+"Wayne_Smith")); 
/*return the value*/ 
Set<OWLIndividual> responsibilities_of_Wayne= ind_Wayne.getObjectPropertyValues(o_p_responsible_for, yourOntology); 
0

另一種方法:一個SPARQL查詢可以用來查詢本體得到Wayne_Smith負責的模塊。還有Java SPARQL庫(例如:Apache Jena ARQ)。希望這可以幫助。