SPARQL 一次计算关系数
SPARQL count number of relations at once
是否可以在单个查询中获取多个关系的数量?例如
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 更快吗?
以下查询检索所有谓词及其编号:
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
结果如下:
是否可以在单个查询中获取多个关系的数量?例如
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 更快吗?
以下查询检索所有谓词及其编号:
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
结果如下: