使用SPARQL查询返回的个人数量减少

时间:2015-06-04 14:22:57

标签: rdf sparql jena owl ontology

我有一个ontology,我对下图所示的类感兴趣:

enter image description here

我创建了两个观察类个体(即观察1和观察2),因此有两个其他类的个体(sensoroutput,observationvalue),如下所示:

<!-- http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Observation1 -->
       <owl:NamedIndividual rdf:about="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Observation1">
        <rdf:type rdf:resource="&j.3;Observation"/>
        <j.3:observationResult rdf:resource="&j.3;SensorOutput1"/>
        <j.3:observedBy rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Co2Sensor_Diningroom"/>
        <j.3:observationSamplingTime rdf:resource="&j.2;Instant1"/>
    </owl:NamedIndividual>

     <!-- http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Observation2 -->
         <owl:NamedIndividual rdf:about="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Observation2">
        <rdf:type rdf:resource="&j.3;Observation"/>
        <j.3:observationResult rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput2"/>
    </owl:NamedIndividual>

     <!-- http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue1 -->
     <owl:NamedIndividual rdf:about="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue1">
        <rdf:type rdf:resource="&j.3;ObservationValue"/>
        <j.1:hasRegionDataValue rdf:datatype="&xsd;decimal">216.56</j.1:hasRegionDataValue>
    </owl:NamedIndividual>

     <!-- http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue2 -->
     <Owl: NamedIndividual rdf:about="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue2">
        <rdf:type rdf:resource="&j.3;ObservationValue"/>
        <j.1:hasRegionDataValue rdf:datatype="&xsd;string">121212</j.1:hasRegionDataValue>
    </owl:NamedIndividual>

     <!-- http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput1 -->
     <owl:NamedIndividual rdf:about="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput1">
        <rdf:type rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Co2SensorOutput"/>
        <j.3:hasValue rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue1"/>
    </owl:NamedIndividual>

     <!-- http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput2 -->
         <owl:NamedIndividual rdf:about="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput2">
        <rdf:type rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Co2SensorOutput"/>
        <j.3:hasValue rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue2"/>
    </owl:NamedIndividual>

现在,当我使用SPARQL获取与两次观察相关联的observationValues时,我过去只得到与observation2相关的值,并且没有获得有关observation1的任何信息。 Sparql查询是:

PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dul: <http://www.loa-cnr.it/ontologies/DUL.owl#>
      SELECT  ?x ?r ?val
       WHERE
        { ?x  rdf:type ssn:Observation.
          ?x  ssn:observationResult ?d.
          ?d ssn:hasValue ?r.
          ?r dul:hasRegionDataValue ?val.
        }

我想知道我在哪里做错了,为什么只返回一个(即观察2而不是观察1)个人?

2 个答案:

答案 0 :(得分:2)

您的文件中有错误。您的实例在不同位置以不同方式命名。要使您的查询有效,请使用完整的uri:o_flags 1581 行重命名单个O_CREAT | O_RDWR, S_IRUSR | S_IWUSR。更具体一点:

第1581行

改变这个:

&j.3;SensorOutput1

对此:

http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput1

鉴于上述更改,查询返回:

<j.3:observationResult rdf:resource="&j.3;SensorOutput1"/>

不要忘记正确输入数据中的原始值,即<j.3:observationResult rdf:resource="http://www.iiitd.edu.in/~haroonr/ontologies/DGO#SensorOutput1"/> 输入为十进制,而x | r | val <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Observation2> <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue2> "121212"^^<http://www.w3.org/2001/XMLSchema#string> <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#Observation1> <http://www.iiitd.edu.in/~haroonr/ontologies/DGO#ObservationValue1> 216.56 输入为String。

答案 1 :(得分:2)

Observation1与您的查询不符,因为其ssn:observationResult,(ssn:SensorOutput1)的值没有ssn:hasValue属性。因此,结果只返回Observation2