简体   繁体   English

sparql有关对象的查询以查找另一个对象

[英]sparql query about object to find another object

Given This RDF: 鉴于此RDF:

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
         xml:base="http://www.example.org/" 
         xmlns:dnr="http://www.dotnetrdf.org/configuration#" 
         xmlns:nss="http://www.example.org/startTime" 
         xmlns:nse="http://www.example.org/endTime#" 
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 >
  <rdf:Description rdf:about="Fadi">
    <ns2914:be xmlns:ns2914="http://example.org/">May</ns2914:be>
    <nss:startTime>00:00:13</nss:startTime>
    <nse:endTime>00:00:16</nse:endTime>
  </rdf:Description>
  <rdf:Description rdf:about="Fadi">
    <ns194:not xmlns:ns194="http://example.org/">Good</ns194:not>
    <nss:startTime>00:00:19</nss:startTime>
    <nse:endTime>00:00:21</nse:endTime>
  </rdf:Description>
  <rdf:Description rdf:about="She">
    <ns195:be xmlns:ns195="http://example.org/">Good</ns195:be>
    <nss:startTime>00:00:21</nss:startTime>
    <nse:endTime>00:00:24</nse:endTime>
   </rdf:Description>
</rdf:RDF>

how to get the startTime and endTime with query about Object? 如何获取有关对象的查询的startTime和endTime? i Tried to use: 我试图使用:

 PREFIX nss: <http://www.example.org/startTime>
 PREFIX nse: <http://www.example.org/endTime#> 
 SELECT * 
 WHERE 
 { 
   ?s ?p ?o .
   FILTER(REGEX(?o, 'Good', 'i'))
   ?s nss:startTime ?startTime ;
      nse:endTime ?endTime .
 }

But it only gave me the first ?startTime and ?endTime For The Subject it find for Object Good . 但这只为我提供了对象Good的Subject的第一个?startTime?endTime

I need The following answers: 我需要以下答案:

?s,?p,?o,?startTime,?endTime
Fadi,not,Good,00:00:19,00:00:21
She,be,Good,00:00:21,00:00:24

Your query doesn't select that data so why are you surprised it isn't returned? 您的查询未选择该数据,所以为什么您不惊讶它没有返回? As I suggested in the comment go read a good SPARQL tutorial like SPARQL by Example or pick up a copy of the excellent Learning SPARQL book from O'Reilly 正如我在评论中所建议的那样,请阅读SPARQL等优秀的SPARQL教程,例如Example或从O'Reilly那里获得优秀的Learning SPARQL书籍的副本。

The query you wrote selects triples where the object matches a regular expression and only those triples. 您编写的查询会选择三元组,其中对象与正则表达式匹配,并且只有那些三元组。 If you want to select the start and end times as well you need to add additional patterns to your queries eg 如果您还想选择开始时间和结束时间,则需要向查询中添加其他模式,例如

PREFIX nss: <http://www.example.org/startTime>
PREFIX nse: <http://www.example.org/endTime#>
SELECT *
WHERE
{
  ?s ?p ?o .
  FILTER(REGEX(?o, "May", "i"))
  ?s nss:startTime ?startTime ;
     nse:endTime ?endTime .
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM