简体   繁体   English

sparql:如何避免访问主题

[英]sparql: how to avoid visited subject

and I am trying to write SPARQL query to find distinct object. 并且我正在尝试编写SPARQL查询来查找不同的对象。

here is the dataset: 这是数据集:

<https://permid.org/1-36436064275> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://permid.org/1-34414203048> .

<https://permid.org/1-34414203048> <http://permid.org/ontology/person/hasTenureInOrganization> <https://permid.org/1-36436064275> .

my sparql query is like this: 我的sparql查询是这样的:

select distinct ?n where {

      <https://permid.org/1-36436064275> ?a ?b .
      ?b ?c ?d . 
      ?d ?e ?n .                     
}

From the dataset, "?d" is https://permid.org/1-36436064275 , which is the visited subject. 在数据集中,“?d”是https://permid.org/1-36436064275 ,它是被访问的主题。 I want to skip visited subject, so that "?d" is empty, thus "?n" is also empty. 我想跳过访问的主题,因此“?d”为空,因此“?n”也为空。

There's a couple of things to address here: 这里有几件事要解决:

From the dataset, "?d" is https://permid.org/1-36436064275 , which is the visited subject. 在数据集中,“?d”是https://permid.org/1-36436064275 ,它是被访问的主题。

This happens because your RDF graph is a cycle. 发生这种情况是因为您的RDF图是一个循环。 The first bit of your SPARQL query is: 您的SPARQL查询的第一位是:

<https://permid.org/1-36436064275> ?a ?b .

This binds ?a to rdf:type , and ?b to 1-34414203048 . 这将?a绑定到rdf:type ,并将?b 1-344142030481-34414203048 The second part of your query pattern is: 查询模式的第二部分是:

?b ?c ?d .

Since ?b is already bound to 1-34414203048 by the previous pattern, there's only one option for ?c ( hasTenureInOrganization ) and ?d ( 1-36436064275 ). 由于?b已通过以前的模式绑定到1-34414203048 ,所以?chasTenureInOrganization )和?d1-36436064275 )只有一个选项。 Then the third bit of your query is: 然后查询的第三位是:

?d ?e ?n . 

?d is already bound by the previous pattern, so there's one option for ?e ( rdf:type again) and ?n ( 1-36436064275 again). ?d已被先前的模式绑定,因此?e (再次为rdf:type )和?n (再次为1-36436064275 )具有一个选项。

I want to skip visited subject, so that "?d" is empty, thus "?n" is also empty. 我想跳过访问的主题,因此“?d”为空,因此“?n”也为空。

That's not how SPARQL works. 这不是SPARQL的工作方式。 SPARQL only returns a query result if the entire pattern has a result. 如果整个模式都有结果,则SPARQL仅返回查询结果。 If ?n has no value, the query will return an empty result. 如果?n没有值,查询将返回空结果。

Having said that, if you want to ensure that ?d is never equal to the subject that you started your query with, you could simply add a FILTER condition: 话虽如此,如果您想确保?d永远不等于您开始查询的主题,则可以简单地添加一个FILTER条件:

FILTER (?d != <https://permid.org/1-36436064275>)

But, like I said in the comments as well, I think you may need to rethink your data model a little bit, and consider the purpose of your query as well. 但是,就像我在评论中所说的那样,我认为您可能需要重新考虑一下数据模型,并考虑一下查询的目的。

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

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