使用rdf:ID的SPARQL查询不返回任何结果 [英] SPARQL query using rdf:ID returns no results

查看:90
本文介绍了使用rdf:ID的SPARQL查询不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个猫头鹰文件,我正在尝试对它进行查询,但没有得到任何结果,请有人帮助我弄清楚它并解释基本查询

I have an owl file and I am trying to run queries on it but not getting any results please some one help me to figure it out and explain basic querying

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

我没有收到错误,但是我不知道如何查询猫头鹰文件,请帮忙

I am not getting error but I dont know how to query owl file please help

推荐答案

您的查询(其中添加了换行符以提高可读性)是

Your query, with newlines added for readability, is:

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/XML文件中看到rdf:ID,但实际上它不是RDF三元组中的属性;相反,它用于指示RDF图中资源的IRI是什么.例如,代码段:

While you see rdf:ID in your RDF/XML file, it's not actually a property in the RDF triples; instead, it's used to indicate what the IRI of a resource in the RDF graph is. For instance, the snippet:

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

对RDF三元组进行编码:

encode the RDF triple:

...#Costs rdf:type owl:Class

...是本体的基本IRI.在 2.14缩写URI:rdf中对此进行了描述RDF/XML规范的:ID和xml:base .该规范有点长而复杂,例如RDF/XML.但是,RDF/XML只是RDF的序列化格式. RDF本身非常简单.只要有可能,我建议您不要直接看RDF图的RDF/XML序列化.相反,请尝试另存为Turtle.它更具人类可读性,您将对图中的三元组有一个更好的了解.例如,您在Turtle中的本体看起来像这样(我没有复制整个内容):

where the ... is the base IRI of your ontology. This is described in section 2.14 Abbreviating URIs: rdf:ID and xml:base of the RDF/XML specification. That specification is kind of long and complicated, like RDF/XML. RDF/XML is just a serialization format for RDF, though. RDF itself is pretty simple. Whenever possible, I'd advise that you don't look directly at the RDF/XML serialization of an RDF graph. Instead, try saving as Turtle. It's much more human readable, and you'll have a much better idea of what triples are actually in the graph. E.g., your ontology in Turtle looks like this (I haven't copied the whole thing):

@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语法几乎相同.

That's almost identical to the corresponding SPARQL syntax.

这篇关于使用rdf:ID的SPARQL查询不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆