寻找创建紧凑表的SPARQL查询

时间:2013-04-23 13:18:04

标签: rdf sparql

我有一些使用新Data Cube vocabulary的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

提前致谢!

1 个答案:

答案 0 :(得分: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()avg()而不是sample(),如果您有多个收获数字会更有意义。

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

相关问题