Created
June 17, 2011 13:39
-
-
Save adorsk-whoi/1031428 to your computer and use it in GitHub Desktop.
SPARQL: Multiple facets in one query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This SPARQL query could be used to calculate facets for SPARQL result set. | |
# The base result is defined as a subquery. | |
# Facets are calculated for the result set, and are returned as rows consisting of a facet id, a label, | |
# and a count. | |
# This query works against Virtuoso SPARQL endpoints. | |
# You can try it the against dbpedia virtuoso sparql endpoint, but it will probably fail due to the DBPedia endpoint's | |
# performance limitations. | |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> | |
PREFIX dbp: <http://dbpedia.org/property/> | |
PREFIX dbo: <http://dbpedia.org/ontology/> | |
# select the facet key, the facet value, and the facet count | |
SELECT distinct ?key ?facet_label ?facet_count | |
WHERE | |
{ | |
{ # facets | |
{ # position facet | |
SELECT distinct ('position') as ?key ?position as ?facet_label count(distinct ?s) as ?facet_count | |
WHERE{ | |
{?s dbo:position ?position} . | |
} | |
} # end position facet | |
UNION | |
{ # country facet | |
SELECT distinct ('country of birth') as ?key ?country as ?facet_label count(distinct ?s) as ?facet_count | |
WHERE{ | |
{?s dbp:countryofbirth ?country} . | |
} | |
} # end country facet | |
# ... other facets ... | |
} # end facets | |
. | |
# subquery for base set for which facet counts will be calculated | |
{ | |
SELECT distinct ?s | |
WHERE | |
{ | |
{<http://dbpedia.org/resource/Arsenal_F.C.> dbp:name ?s} . | |
{?s rdf:type dbo:Person}. | |
} | |
} # End base set selection | |
} # End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment