2016-07-06 81 views
1

我有以下查詢獲取類的實例和它們的標籤/名稱。我想統計有多少總結果。但是,我不知道如何制定count聲明。sparql如何計數變量對

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} 
} 

但是,給出了每個?的?l對計數,而不是我需要知道有多少的?的?l對有。或者,也許我不應該使用count?正如前面所提到的,我需要知道的是,查詢返回的結果總數有多少(不管服務器放置的硬性限制如何,例如,DBPedia每次查詢最多返回50000個結果)。

有什麼建議嗎?

非常感謝!

回答

2

要計算匹配的數量,使用

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

注意我使用屬性路徑「或」(|),以獲得性能的結合。

+0

太棒了!謝謝! – Ziqi