SPARQL计算一次关系数

时间:2016-11-01 13:48:15

标签: sparql

是否有可能在单个查询中获得多个关系数量的计数? e.g。

SELECT (COUNT(?friendid) as ?friends) (COUNT(?cousinid) as ?cousins)  (COUNT(?sonid) as ?sons)
WHERE
{
  ex:person1 ex:friendOf ?friendid .
  ex:person1 ex:cousinOf ?cousinid .
  ex:person1 ex:fatherOf ?sonid .
}

如果需要一个包含多个查询的复杂查询,理论上当然应该比执行不同的SELECT更快吗?

1 个答案:

答案 0 :(得分:2)

以下查询检索所有谓词及其编号:

SELECT ?p (COUNT(?p) as ?pCount) WHERE { ex:person1 ?p ?o} GROUP BY ?p

这个限制了谓词(AKSW的建议):

SELECT ?p (COUNT(?p) as ?pCount) WHERE { ex:person1 ?p ?o. VALUES (?p) {(:p1)}} GROUP BY ?p

以下是一个例子:

SELECT ?p (COUNT(?p) as ?pCount) WHERE
{
  <http://dbpedia.org/resource/Category:Museums_in_Italy> ?p ?o .
  VALUES (?p) {(skos:altLabel) (owl:sameAs)}
}
GROUP BY ?p

以下是结果:

Results