在构造 sparql 查询中使用 union
我有一个包含多个条目的 rdf 图。现在我想获取给定 id 的所有相关三元组。这是我的 sparql 查询:
select ?s ?p ?o from <http://localhost:8890/DAV/ranking> where {
{<http://seekda.com/providers/cdyne.com/PhoneNotify> so:hasEndpoint ?s.
?s ?p ?o} union
{<http://seekda.com/providers/cdyne.com/PhoneNotify> ?p ?o}
}
本例中的 ID 为
。
但我需要一个图形查询(construct
或 describe
)。所以我想我必须用一个union
将它们打包在一起。我该怎么做?
I have an rdf
graph with several entries. Now I want to get all related triples to a given id. This is my sparql query:
select ?s ?p ?o from <http://localhost:8890/DAV/ranking> where {
{<http://seekda.com/providers/cdyne.com/PhoneNotify> so:hasEndpoint ?s.
?s ?p ?o} union
{<http://seekda.com/providers/cdyne.com/PhoneNotify> ?p ?o}
}
The ID in this case is <seekda.com/providers/cdyne.com/PhoneNotify>
.
But I need a graph query (construct
or describe
). So I think I have to pack them togheter with an union
. How do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答是:没有区别。
更长的答案是:将 SPARQL 查询视为由两部分组成。
查询 (WHERE) 部分,生成变量绑定列表(尽管某些变量可能未绑定)。
查询 (WHERE)
将结果组合在一起的部分。
SELECT
、ASK
、CONSTRUCT
或DESCRIBE
。SELECT *
实际上是查询返回的内容。SELECT ?v1 ?v2
获取结果并生成另一个结果集,并删除其他变量。ASK
只是查看是否有任何结果。CONSTRUCT
使用模板根据结果生成 RDF。对于每个结果行,它绑定变量并将语句添加到结果模型中。如果模板三元组包含未绑定变量,则会跳过该变量。DESCRIBE
是最不寻常的,因为它获取每个结果节点,找到与其关联的三元组,并将它们添加到结果模型中。与其他的不同,它可以包含比查询匹配更多的信息。因此,所有形式都允许在查询中使用
UNION
、OPTIONAL
等。由于未绑定的变量,它们可能会导致三元组丢失。您的查询没有多大意义。这与好吧,现在更有意义了。{?s ?p ?o}
没有什么不同。你想做什么?鉴于下面的澄清,听起来您想要以下内容:
The short answer is: there is no difference.
The longer answer is: think about SPARQL queries as having two parts.
The query (WHERE) part, which produces a list of variable bindings (although some variables may be unbound).
The part which puts together the results.
SELECT
,ASK
,CONSTRUCT
, orDESCRIBE
.SELECT *
is effectively what the query returns.SELECT ?v1 ?v2
takes results and produces another result set with the other variables removed.ASK
just looks to see if there are any results.CONSTRUCT
uses a template to make RDF from the results. For each result row it binds the variables and adds the statements to the result model. If a template triple contains an unbound variable it is skipped.DESCRIBE
is the most unusual, since it takes each result node, finds triples associated with it, and adds them to a result model. Unlike the others it can contain more information than the query matches.So having
UNION
,OPTIONAL
, whatever, in the query is allowed for all forms. They may lead to missing triples due to unbound variables.Your query doesn't make much sense. It's no different toOk, makes more sense now.{?s ?p ?o}
. What are you trying to do?Given clarifications below it sounds like you want the following: