[英]sparql query about object to find another object
鉴于此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>
如何获取有关对象的查询的startTime和endTime? 我试图使用:
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 .
}
但这只为我提供了对象Good
的Subject的第一个?startTime
和?endTime
。
我需要以下答案:
?s,?p,?o,?startTime,?endTime
Fadi,not,Good,00:00:19,00:00:21
She,be,Good,00:00:21,00:00:24
您的查询未选择该数据,所以为什么您不惊讶它没有返回? 正如我在评论中所建议的那样,请阅读SPARQL等优秀的SPARQL教程,例如Example或从O'Reilly那里获得优秀的Learning SPARQL书籍的副本。
您编写的查询会选择三元组,其中对象与正则表达式匹配,并且只有那些三元组。 如果您还想选择开始时间和结束时间,则需要向查询中添加其他模式,例如
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.