Created
May 5, 2013 10:59
-
-
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.
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
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