Skip to content

Instantly share code, notes, and snippets.

@tatiana
Created March 19, 2013 14:10
Show Gist options
  • Save tatiana/5196401 to your computer and use it in GitHub Desktop.
Save tatiana/5196401 to your computer and use it in GitHub Desktop.
Can I build a single SPARQL query for listing items and counting them?
DEFINE input:inference <http://tatipedia.org/property_ruleset>
SELECT DISTINCT ?subject ?label count(distinct ?subject) as ?total
WHERE {
?subject a <http://tatipedia.org/Place>;
rdfs:label ?label .
FILTER (langMatches(lang(?label), "pt"))
}
LIMIT 2
@tatiana
Copy link
Author

tatiana commented Mar 19, 2013

I'd like a SINGLE query that would:

  • list results
  • provide total items found

Provided:

@prefix tpedia: <http://tatipedia.org/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

tpedia:new_york a tpedia:Place ;
                rdfs:label "Nova Iorque"@pt ;
                rdfs:label "New York"@en .

tpedia:london a tpedia:Place ;
                rdfs:label "Londres"@pt ;
                rdfs:label "London"@en .

tpedia:name rdf:type owl:DatatypeProperty ;
            rdfs:subPropertyOf rdfs:label .

tpedia:munich a tpedia:Place ;
                tpedia:name "Munique"@pt ;
                tpedia:name "Munich"@en .

Would respond:

+-----------------+------------------+-------+
|     subject     |      label       | total |
+-----------------+------------------+-------+
| tpedia:london   | "Londres"@pt     |     3 |
| tpedia:munich   | "Munique"@pt     |     3 |
+-----------------+------------------+-------+

However, the query above returns:

+-----------------+------------------+-------+
|     subject     |      label       | total |
+-----------------+------------------+-------+
| tpedia:london   | "Londres"@pt     |     1 |
| tpedia:munich   | "Munique"@pt     |     1 |
+-----------------+------------------+-------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment