SPARQL查询中空白节点和变量之间的区别 [英] The difference between blank nodes and variables in SPARQL queries

查看:129
本文介绍了SPARQL查询中空白节点和变量之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了 SPARQL规范关于该主题,还找到了此答案挺有意思的.但是定义非常复杂,因此我仍然看不到我的问题的答案.

I've studied SPARQL specification on the topic and also found this answer rather interesting. However definitions are complicated enough, so I still don't see the answer for my question.

我找不到任何带有空白节点的查询示例,该示例返回的结果不同于具有变量代替空白节点的相同查询的结果.

I can't find any example of query with blank nodes that returns different results than the same query with variables in place of blank nodes.

例如,在任何情况下,以下查询返回不同的结果:

For example is there any case when the following queries return different results:

SELECT ?a ?b
WHERE {
    ?a :predicate _:blankNode .
    _:blankNode :otherPredicate ?b .
}

  • SELECT ?a ?b
    WHERE {
        ?a :predicate ?variable .
        ?variable :otherPredicate ?b .
    }
    

  • 也许有更复杂的查询会导致不同的行为?

    Maybe there are more complex queries that cause different behavior?

    特别是我想知道是否存在在没有空白节点的RDF图上执行查询的不同结果的示例.

    In particular I wonder is there any examples of different results of queries executed on an RDF graph that doesn't have blank nodes.

    谢谢.

    PS.是的,我知道空白节点只能在一个BasicGraphPattern中使用,而不是变量.但这不是我在说的区别.

    PS. Yes, I know that blank nodes can be used only in one BasicGraphPattern as opposed to variables. But this is not the difference I'm talking about.

    推荐答案

    您链接到的答案与正在查询的数据中的空白节点有关,而不是与查询中的空白节点有关.绝对正确,查询中的空白节点就像变量一样.规范对此进行了说明(强调):

    The answer that you linked to is about blank nodes in the data that is being queried, not about blank nodes in the query. You're absolutely right that blank nodes in the query act just like variables. The specification says this (emphasis added):

    4.1.4空白节点的语法

    图形模式中的空白节点充当变量,而不是对 要查询的数据中的特定空白节点.

    4.1.4 Syntax for Blank Nodes

    Blank nodes in graph patterns act as variables, not as references to specific blank nodes in the data being queried.

    空白节点用标签形式表示,例如"_:abc", 或缩写形式"[]".仅在一个节点中使用的空白节点 查询语法中的位置可以用[]表示.独特的空白 节点将用于形成三重模式.空白节点标签为 对于带有标签"abc"的空白节点,写为"_:abc".一样的空白 节点标签不能在以下两个不同的基本图形模式中使用 相同的查询.

    Blank nodes are indicated by either the label form, such as "_:abc", or the abbreviated form "[]". A blank node that is used in only one place in the query syntax can be indicated with []. A unique blank node will be used to form the triple pattern. Blank node labels are written as "_:abc" for a blank node with label "abc". The same blank node label cannot be used in two different basic graph patterns in the same query.

    因此,您的查询

    SELECT ?a ?b
    WHERE {
        ?a :predicate _:blankNode .
        _:blankNode :otherPredicate ?b .
    }
    

    SELECT ?a ?b
    WHERE {
        ?a :predicate ?variable .
        ?variable :otherPredicate ?b .
    }
    

    表现相同.使用空白节点而不是变量的好处是可以使用一些更紧凑的语法.在这种情况下,您可以编写:

    behave identically. The benefit of using a blank node instead of a variable is that you can use some more compact syntax. In this case, you could write:

    SELECT ?a ?b
    WHERE {
        ?a :predicate [ :otherPredicate ?b ] .
    }
    

    实际上,在这种情况下,由于您只在空白节点匹配的事物上寻找一个属性,因此可以使用属性路径:

    Actually, in this case, since you're only looking for one property on the thing that the blank node matches, you could use a property path:

    SELECT ?a ?b
    WHERE {
        ?a :predicate/:otherPredicate ?b .
    }
    

    这篇关于SPARQL查询中空白节点和变量之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆