Skip to content

Instantly share code, notes, and snippets.

@niclashoyer
Created May 5, 2013 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niclashoyer/5520492 to your computer and use it in GitHub Desktop.
Save niclashoyer/5520492 to your computer and use it in GitHub Desktop.
SPARQL query to get the "height" or distance to a common parent class.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
PREFIX : <http://example.com#>
SELECT ?r (MIN(?h) AS ?height) WHERE {
VALUES ?r { :h0 :h1 :h2 :h3 :h4 :h5 :h6 }
VALUES ?p { ldp:Resource }
{
?r rdf:type ?p
BIND (0 AS ?h)
} UNION {
?r rdf:type/rdfs:subClassOf{1,1} ?p
BIND (1 AS ?h)
} UNION {
?r rdf:type/rdfs:subClassOf{2,2} ?p
BIND (2 AS ?h)
} UNION {
?r rdf:type/rdfs:subClassOf{3,3} ?p
BIND (3 AS ?h)
} UNION {
?r rdf:type/rdfs:subClassOf{4,4} ?p
BIND (4 AS ?h)
} UNION {
?r rdf:type/rdfs:subClassOf{5,5} ?p
BIND (5 AS ?h)
}
} GROUP BY ?r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment