I am trying to write a SPARQL query that counts the occurrences of an object in multiple graphs. Sample data and expected result below:
Name graph g1:
@prefix g1: <http://example.com/g1
Name graph g2:
@prefix g2: <http://example.com/g2
Expected result of the SPARQL query:
?label ?g1count ?g2count a 2 1 b 1 1 c 0 1 d 1 0
I can get the total for both graphs by combining rdfs: labels and counting occurrences:
prefix g1: <http://example.com/g1#> prefix g2: <http://example.com/g2#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema
I thought that from here I could use subqueries in each UNION block to get separate calculations, but, apart from the possible inefficiency of such a query, I was not lucky to get the expected results.
source share