SPARQL:每个命名图中的语句数

SPARQL: Number of Statements in each Named Graph

以下查询 returns 存储库中的语句数:

SELECT (COUNT(*) AS ?count) 
WHERE {
  ?s ?p ?o
}

有没有办法 return 每个命名图的语句数?

下面的查询不起作用,只是一个例子:

SELECT ?graphName ?count 
WHERE {
  GRAPH ?graphName { 
    ?s ?p ?o. 
    BIND(COUNT(?s ?p ?o.) AS ?count)
  }
}

只需在您的查询中添加一个 GROUP BY 子句 --

SELECT ?graphName
       ( COUNT ( * ) AS ?count )
WHERE
  {
    GRAPH ?graphName
      {
        ?s ?p ?o
      }
  }
GROUP BY ?graphName

the query and its live results on DBpedia