1

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?

dilvan
  • 2,109
  • 2
  • 20
  • 32
  • I found a way to delete a JSON-LD tree with blank nodes using 2 queries. The first query deletes the named instance: `DELETE { ?p ?o} WHERE { ?p ?o}` The second deletes all blank nodes not attached to anything and will delete blank nodes that were directly attached to the named instance. Blank nodes, attached to this blank nodes, will be eventually deleted in future delete calls: `DELETE {?bnode ?p ?o} WHERE {FILTER(isBlank(?bnode)) FILTER NOT EXISTS {?parent ?p2 ?bnode.} ?bnode ?p ?o.}` – dilvan Aug 01 '19 at 17:26

0 Answers0