sparql如何计算变量对

sparql how to count variable pairs

我有以下查询获取 class 及其 label/names 的实例。我想计算总共有多少个结果。但是,我不知道如何制定count声明。

select ?s ?l {
   ?s a <http://dbpedia.org/ontology/Ship> . 
   {?s <http://www.w3.org/2000/01/rdf-schema#label> ?l}
   union
   {?s <http://xmlns.com/foaf/0.1/name> ?l} 
}

我试过了

select ?s ?l (count (?s) as ?count) {
   ?s a <http://dbpedia.org/ontology/Ship> . 
   {?s <http://www.w3.org/2000/01/rdf-schema#label> ?l}
   union 
   {?s <http://xmlns.com/foaf/0.1/name> ?l} 
}

但这给出了每个 ?s ?l 对的计数,相反我需要知道有多少 ?s ?l 对。或者我根本不应该使用 count ?如前所述,我需要知道的是一个查询总共有多少结果returns(不管服务器设置的硬限制如何,例如,DBPedia returns 每个查询最多 50000 个结果) .

有什么建议吗?

非常感谢!

要计算匹配数,请使用

SELECT (COUNT(*) AS ?count)
WHERE {
   ?s <http://www.w3.org/2000/01/rdf-schema#label> | <http://xmlns.com/foaf/0.1/name> ?l .
}

请注意,我正在使用 属性 路径 "or" (|) 来获取属性的并集。