I need to save and delete JSON-LD trees in a triple store. These trees often have subtrees that are represented as blank nodes. It is easy to transform them into RDF and use SPARQL to save them. But, when I need to retrieve/delete them, it is impossible to get all blank nodes. I am using the following query to get all blank nodes (but only up to 3 levels deep):
CONSTRUCT {
<instanceURI> ?p ?o.
?o ?p1 ?o1.
?o1 ?p2 ?o2.
}
WHERE {
<instanceURI> ?p ?o.
OPTIONAL {
FILTER (isBlank(?o))
?o ?p1 ?o1.
OPTIONAL {
FILTER (isBlank(?o1))
?o1 ?p2 ?o2.
}
}
}
In another question (How to recursively expand blank nodes in SPARQL construct query?) they suggest the use of DESCRIBE. But DESCRIBE returns more things than I want. Can I make a subquery to the graph DESCRIBE returns? If so, how?
This use case (retrieve/delete JSON-LD instances with arbitrary blank nodes) seems to be very common for people working with JSON-LD. A solution for it shouldn't be hard to implement. Am I doing something wrong? Is there a standard way of doing this?