SPARQL 未绑定变量

SPARQL Unbound Variables

我需要帮助才能准确理解此 sparql 查询的作用(要求):

SELECT ?subject ?object
    WHERE { ?subject onto:personName ?object . ?w ?q ?s}

这是来自 ontology 的人。第一部分很容易理解;某些未知主题必须有一个具有某些未知值的 personName,但为什么第二部分相关?

以下是我需要帮助理解的内容:当有两种模式(“.”之前和之后)时,这是否意味着节点必须匹配第一个和第二个模式?如果是这样,这种情况下的第二个模式会说:"some unknown subject must have some unknown predicate and some unknwon object",这将 return RDF 图中的所有三元组......所以在这种情况下,第二个模式将匹配所有三元组,但结果将受到第一个模式的限制..

我的问题是,为什么第二个模式那么重要,因为它似乎只等同于第一个模式。但是当我 运行 它时,我得到 "all" ontology 中的三元组,所以我需要准确理解查询的作用。

另外:如果我用 ?object 替换 ?w 会发生什么,从而将 ?object 绑定到 boh 模式,所以它看起来像:?object 必须有一些谓词 ?q 和一些对象 ?s,所以如果我用 ?object 替换 ?w,它会找到 [=12] 的传递对象(?s) =] 在模式 1 中...换句话说:?subject --> onto:personName --> ?object --> ?q --> ?s.

Here is what i need help understanding: when there are two patterns (before and after the ".") does this mean the nodes must match both the first AND the second pattern?

是的。

If so, the second pattern in this case seams to say: "some unknown subject must have some unknown predicate and some unknwon object", which would return all the tripples in the RDF graph...

正确。

so in this case, the second pattern would match on all tripples, but the result would then be restricted by the first pattern..

实际上,第二个模式的结果完全不受第一个模式的限制——因为模式不共享变量。您没有取回数据集中所有三元组的原因很简单,在 SELECT 子句中,您只指定了第一个模式中的变量。如果你说 SELECT *SELECT ?subject ?object ?w ?q ?s 你会得到所有的东西。

My question is, why the second pattern then matters at all, as it would seem to be equivalent to just the first pattern.

不等价,因为第二个模式匹配 所有 个可能的三元组,而第一个模式只匹配那些以 onto:personName 作为谓词的三元组。

虽然为 ?w?q?s 找到的值中有 none 显示在您的查询结果中,但包含此模式确实具有对你结果的影响。通过指定两个模式,您可以有效地表达两个模式之间的连接。由于这两个模式不共享变量,所以可以说没有 "join condition"。这样做的结果是您的查询结果将是匹配第一个模式的所有三元组和匹配第二个模式的所有三元组的 Carthesian 乘积。

所以您将在查询结果中看到的是,您将获得 ?subject?object 的许多重复行:每对将重复 N 次,其中 N 是三元组的数量匹配第二个模式。

所以总而言之,除非你有一个非常奇特的用例,否则第二种模式比无用更糟糕,因为它不仅不会在结果中产生任何有用的数据,而且会确保结果包含大量重复项(并且可能还会导致您的查询执行时间比实际需要的时间长得多)。

Also: what would happen if I replaced ?w with ?object, thereby binding ?object to boh patterns, and so it would seem like: ?object must have some predicate ?q and some object ?s, and so if I replaced ?w with ?object, it would find the transitive object (?s) of ?object in pattern 1... in other words: ?subject --> onto:personName --> ?object --> ?q --> ?s.

确实如此。如果这样做,您将拥有一个共享变量,因此将拥有两个模式之间的连接条件。对查询结果的影响是,您现在不再收到存在 onto:personName 谓词的 all ?subject ?object 对,而只收到 onto:personName 谓词存在的那些 true ?object 值作为数据集中某处其他三元组的主题出现。