2015-12-24 52 views
0

我有一隻貓頭鷹的文件,我試圖運行查詢就可以了,但沒有得到任何結果請有人幫助我弄清楚並說明基本的查詢SPARQL查詢使用RDF:身份證不返回任何結果

public static void main(String[] args) { 
     String filename="H:/Samson_study/nodeTest/hRESTS-TC3/ontology/ApothecaryOntology.owl"; 
     Model model=ModelFactory.createDefaultModel(); 
     OntModel model1=ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model); 

     try 
     {   File file=new File(filename); 
      FileInputStream reader=new FileInputStream(file); 
      model.read(reader,null); 


      String query1=" PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX my: <http://127.0.0.1/ontology/ApothecaryOntology.owl#> SELECT ?result WHERE { ?result rdf:ID my:HealthInsuranceNumber .}"; 

      Query query=QueryFactory.create(query1); 
      QueryExecution exe=QueryExecutionFactory.create(query, model1); 
      ResultSet RES=exe.execSelect(); 
      ResultSetFormatter.out(System.out, RES, query); 
     }catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 

的本體是如下:

<?xml version="1.0"?> 
<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:owl="http://www.w3.org/2002/07/owl#" 
    xmlns="http://127.0.0.1/ontology/ApothecaryOntology.owl#" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
    xml:base="http://127.0.0.1/ontology/ApothecaryOntology.owl"> 
    <owl:Ontology rdf:about=""/> 
    <owl:Class rdf:ID="Costs"/> 
    <owl:Class rdf:ID="HealthInsuranceNumber"> 
    <owl:disjointWith> 
     <owl:Class rdf:ID="TelephoneNumber"/> 
    </owl:disjointWith> 
    <rdfs:subClassOf> 
     <owl:Class rdf:ID="Number"/> 
    </rdfs:subClassOf> 
    </owl:Class> 
    <owl:Class rdf:ID="Room"> 
    <rdfs:subClassOf> 
     <owl:Class rdf:ID="Ward"/> 
    </rdfs:subClassOf> 
    </owl:Class> 
    <owl:Class rdf:about="#Ward"> 
    <rdfs:subClassOf> 
     <owl:Class rdf:ID="Hospital"/> 
    </rdfs:subClassOf> 
    </owl:Class> 
    <owl:Class rdf:ID="PhysicianID"> 
    <rdfs:subClassOf rdf:resource="#Number"/> 
    </owl:Class> 
    <owl:Class rdf:ID="HospitalPhysician"> 
    <rdfs:subClassOf> 
     <owl:Class rdf:ID="Physician"/> 
    </rdfs:subClassOf> 
    </owl:Class> 
    <owl:Class rdf:ID="Name"/> 
    <owl:Class rdf:ID="Symptom"/> 
    <owl:Class rdf:about="#Hospital"> 
    <owl:disjointWith> 
     <owl:Class rdf:ID="EmergencyStation"/> 
    </owl:disjointWith> 
    <rdfs:subClassOf> 
     <owl:Class rdf:ID="MedicalOrganisation"/> 
    </rdfs:subClassOf> 
    </owl:Class> 
    <owl:Class rdf:ID="Patient"> 
    <rdfs:subClassOf> 
     <owl:Class rdf:ID="Person"/> 
    </rdfs:subClassOf> 
    </owl:Class> 
    <owl:Class rdf:about="#Physician"> 
    <rdfs:subClassOf rdf:resource="#Person"/> 
    </owl:Class> 
    <owl:Class rdf:ID="EmergencyPhysician"> 
    <rdfs:subClassOf rdf:resource="#Physician"/> 
    </owl:Class> 
    <owl:Class rdf:ID="Treatment"/> 
    <owl:Class rdf:about="#EmergencyStation"> 
    <rdfs:subClassOf> 
     <owl:Class rdf:about="#MedicalOrganisation"/> 
    </rdfs:subClassOf> 
    <owl:disjointWith rdf:resource="#Hospital"/> 
    </owl:Class> 
    <owl:Class rdf:ID="CostAndHealingPlan"/> 
    <owl:Class rdf:ID="OperatingRoom"> 
    <rdfs:subClassOf rdf:resource="#Ward"/> 
    </owl:Class> 
    <owl:Class rdf:ID="Disease"/> 
    <owl:Class rdf:ID="Organisation"/> 
    <owl:Class rdf:ID="PersonName"> 
    <rdfs:subClassOf rdf:resource="#Name"/> 
    </owl:Class> 
    <owl:Class rdf:ID="PublicOrganisation"> 
    <rdfs:subClassOf rdf:resource="#Organisation"/> 
    </owl:Class> 
    <owl:Class rdf:about="#TelephoneNumber"> 
    <owl:disjointWith rdf:resource="#HealthInsuranceNumber"/> 
    <rdfs:subClassOf rdf:resource="#Number"/> 
    </owl:Class> 
    <owl:Class rdf:ID="Drug"/> 
    <owl:Class rdf:ID="DateTime"/> 
    <owl:Class rdf:ID="Diagnosis"/> 
    <owl:Class rdf:about="#MedicalOrganisation"> 
    <rdfs:subClassOf rdf:resource="#PublicOrganisation"/> 
    </owl:Class> 
    <owl:ObjectProperty rdf:ID="Drug_treatDisease"> 
    <rdfs:range rdf:resource="#Disease"/> 
    <rdfs:domain rdf:resource="#Drug"/> 
    </owl:ObjectProperty> 
    <owl:ObjectProperty rdf:ID="ListOfHospitals_consistsOf"> 
    <rdfs:range rdf:resource="#Hospital"/> 
    </owl:ObjectProperty> 
    <owl:ObjectProperty rdf:ID="Disease_medicatedByTreatment"> 
    <rdfs:range rdf:resource="#Treatment"/> 
    <rdfs:domain rdf:resource="#Disease"/> 
    </owl:ObjectProperty> 
    <owl:FunctionalProperty rdf:ID="Drug_hasCosts"> 
    <rdfs:range rdf:resource="#Costs"/> 
    <rdfs:domain rdf:resource="#Drug"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    </owl:FunctionalProperty> 
    <owl:FunctionalProperty rdf:ID="Organisation_isAt"> 
    <rdfs:domain rdf:resource="#Organisation"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    </owl:FunctionalProperty> 
    <owl:FunctionalProperty rdf:ID="Physician_hasID"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#InverseFunctionalProperty"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    <rdfs:range rdf:resource="#PhysicianID"/> 
    <rdfs:domain rdf:resource="#Physician"/> 
    </owl:FunctionalProperty> 
    <owl:FunctionalProperty rdf:ID="Patient_hasDisease"> 
    <rdfs:domain rdf:resource="#Patient"/> 
    <rdfs:range rdf:resource="#Disease"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    </owl:FunctionalProperty> 
    <owl:FunctionalProperty rdf:ID="Organisation_hasTelephoneNumber"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    <rdfs:range rdf:resource="#TelephoneNumber"/> 
    <rdfs:domain rdf:resource="#Organisation"/> 
    </owl:FunctionalProperty> 
    <owl:FunctionalProperty rdf:ID="Person_hasName"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    <rdfs:range rdf:resource="#PersonName"/> 
    <rdfs:domain rdf:resource="#Person"/> 
    </owl:FunctionalProperty> 
    <owl:FunctionalProperty rdf:ID="Disease_hasSymptom"> 
    <rdfs:domain rdf:resource="#Disease"/> 
    <rdfs:range rdf:resource="#Symptom"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> 
    </owl:FunctionalProperty> 
</rdf:RDF> 

<!-- Created with Protege (with OWL Plugin 3.3.1, Build 430) http://protege.stanford.edu --> 

我沒有收到錯誤,但我不知道如何查詢貓頭鷹文件請幫助

+0

將文件加載到「模型」對象中,然後查詢「模型1」。請嘗試使用model1.read(reader,null)。 –

+0

還沒有得到任何迴應 –

+1

你有沒有在本體中的任何個人還是你只是有架構? –

回答

3

您的查詢,添加了對可讀性換行,方法是:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX my: <http://127.0.0.1/ontology/ApothecaryOntology.owl#> 

SELECT ?result WHERE { 
    ?result rdf:ID my:HealthInsuranceNumber . 
} 

當你看到RDF:在您的RDF/XML文件的ID,這不是真正的RDF三元組的屬性;相反,它用於指示RDF圖中資源的IRI是什麼。例如,片段:

<owl:Class rdf:ID="Costs"/> 

編碼的RDF三元:

...#Costs rdf:type owl:Class 

其中...是你的本體論的基礎IRI。這在RDF/XML規範的2.14 Abbreviating URIs: rdf:ID and xml:base部分中有描述。這個規範很長很複雜,就像RDF/XML一樣。不過,RDF/XML僅僅是RDF的序列化格式。 RDF本身非常簡單。只要有可能,我建議你不要直視RDF圖的RDF/XML序列化。相反,嘗試保存爲海龜。它更具人類可讀性,並且您將更好地瞭解圖中實際的三元組。例如,你在烏龜的本體是這樣的(我沒有複製整個東西):

@prefix :  <http://127.0.0.1/ontology/ApothecaryOntology.owl#> . 
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . 
@prefix owl: <http://www.w3.org/2002/07/owl#> . 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 

:Person a  owl:Class . 

:Patient a    owl:Class ; 
     rdfs:subClassOf :Person . 

:HospitalPhysician a owl:Class ; 
     rdfs:subClassOf :Physician . 

:TelephoneNumber a  owl:Class ; 
     rdfs:subClassOf :Number ; 
     owl:disjointWith :HealthInsuranceNumber . 

:Physician_hasID a owl:FunctionalProperty , owl:InverseFunctionalProperty , owl:ObjectProperty ; 
     rdfs:domain :Physician ; 
     rdfs:range :PhysicianID . 

:Disease_hasSymptom a owl:FunctionalProperty , owl:ObjectProperty ; 
     rdfs:domain :Disease ; 
     rdfs:range :Symptom . 

這幾乎與相應的SPARQL語法相同。

0

檢查本體和查詢都精確匹配的光圈。您正在搜索rdf:ID等於http://127.0.0.1/ontology/ApothecaryOntology.owl#HealthInsuranceNumber,但您的基本IRI沒有#字符,並且rdf:ID值也不是。這可能意味着文件中的值看起來像http://127.0.0.1/ontology/ApothecaryOntology.owlHealthInsuranceNumber而不是您所期望的。

+0

我試過你的建議仍然沒有返回任何值 –

+0

@Ignazio rdf:id通常不被用作RDF中的謂詞(事實上,它可能被禁止)。相反,它的使用與rdf相同:about;它是RDF的RDF/XML序列化中使用的特殊IRI。 –

+0

@Joshua確實,我想知道的一樣。我將複製這個並打印出實際的三元組,我懷疑該查詢正在尋找錯誤的模式。 – Ignazio