[英]SPARQL same predicates with different values
I am using SPARQL to query my data from the triplestore.我正在使用 SPARQL 从三元组查询我的数据。 In the triplestore I have a form containing a table, the table has different table entries.
在三元组中,我有一个包含表格的表格,该表格具有不同的表格条目。 Each entry has a number of predicates.
每个条目都有多个谓词。 I want to use the predicates index and cost.
我想使用谓词索引和成本。 My query needs to catch the first 2 rows, indices 0 and 1 and save the cost under a specific variable for each.
我的查询需要捕获前 2 行,索引 0 和 1,并将成本保存在每个特定变量下。
So I have tried the following (prefix ext is ommited):所以我尝试了以下方法(省略了前缀 ext):
SELECT DISTINCT ?entry ?priceOne ?priceTwo
WHERE {
?form ext:table ?table.
?table ext:entry ?entry.
?entry ext:index 0;
ext:cost ?priceOne.
?entry ext:index 1;
ext:cost ?priceTwo.
}
This however does not show any values, if I remove the second part (with index 1) than I do get?priceOne.然而,如果我删除第二部分(索引为 1)而不是我得到的,这不会显示任何值?priceOne。 How can I get both values?
我怎样才能得到这两个值?
Your current query finds each ?entry
that has both ext:index
values, 0 and 1. You could avoid this by using something like ?entry0
and ?entry1
, essentially duplicating your triple patterns.您当前的查询找到每个
?entry
都具有ext:index
值 0 和 1。您可以通过使用类似?entry0
和?entry1
的东西来避免这种情况,本质上是复制您的三重模式。
But typically, you would match alternatives with UNION
:但通常情况下,您会将备选方案与
UNION
匹配:
SELECT DISTINCT ?entry ?priceOne ?priceTwo
WHERE {
# a shorter way to specify this, if you don’t need the ?table variable
?form ext:table/ext:entry ?entry .
{
?entry ext:index 0 ;
ext:cost ?priceOne .
}
UNION
{
?entry ext:index 1 ;
ext:cost ?priceTwo .
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.