Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Created February 24, 2018 18:20
Show Gist options
  • Save jindrichmynarz/c2e332d5ab35b47d95f17bb78dfccc07 to your computer and use it in GitHub Desktop.
Save jindrichmynarz/c2e332d5ab35b47d95f17bb78dfccc07 to your computer and use it in GitHub Desktop.
Recursive concise bounded description
# SPARQL 1.1 implementation of concise bounded description (<https://www.w3.org/Submission/CBD>).
PREFIX : <http://example.com/>
PREFIX non: <http://non/>
CONSTRUCT {
:resource ?p1 ?r1 .
?r2 ?p2 ?r3 .
}
WHERE {
# :resource is the IRI of the resource we want to describe.
:resource ?p1 ?r1 .
OPTIONAL {
# Since variables cannot be used in SPARQL 1.1 property paths
# we can ask for any but a (presumably) non-existent property.
# We use zero or more quantifier (i.e. "*") to recursively
# expand to blank node neighbourhood.
?r1 (!non:existent)* ?r2 .
FILTER (isBlank(?r1) && isBlank(?r2))
?r2 ?p2 ?r3 .
}
}
@prefix : <http://example.com/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:resource a :C ;
:p1 [
a :D ;
:p2 [
a :E
]
] .
:C a rdfs:Class .
:D a rdfs:Class .
:E a rdfs:Class .
@jindrichmynarz
Copy link
Author

I don't see the correspondence between recursive CBD and Stardog path queries. Is it possible to implement the recursive CBD in Stardog-flavoured SPARQL?

@ktk
Copy link

ktk commented Feb 26, 2018

We plan to use PATH for that but from what I know we cannot use it in sub-selects right now

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