1

我有一些使用新的Data Cube 词汇的 RDF 数据。对于可视化,我需要将数据作为一个扁平且紧凑的表格。但我无法找到执行此操作的正确 SPARQL 查询。

我将尝试举一个最小的例子......

给定以下 RDF 数据:

o1
 :year "2007";
 :fruit :apples;
 :harvest "200";
 .
o2
 :year "2007";
 :fruit :pears;
 :harvest "180";
 . 
o3
 :year "2008";
 :fruit :apples;
 :harvest "205";
.
o4
 :year "2008";
 :fruit :pears;
 :harvest "176";
. 

是否有可以将数据返回为下表的 SPARQL 查询?

Year | Apples | Pears
2007 | 200    | 180
2008 | 205    | 176

提前致谢!

4

1 回答 1

3

尝试:

select ?year (sample(?num_apples) as ?apples) (sample(?num_pears) as ?pears)
where
{
    { ?s :year ?year ; :fruit :apples; :harvest ?num_apples }
    union
    { ?s :year ?year ; :fruit :pears; :harvest ?num_pears }
}
group by ?year

您可以使用sum()oravg()而不是sample(),如果您有多个收获数字,这将更有意义。

(警告:您的值是字符串而不是数字!)

于 2013-04-23T14:05:34.180 回答