diff --git a/docs/bql.md b/docs/bql.md index bc93099b..a539bc4b 100644 --- a/docs/bql.md +++ b/docs/bql.md @@ -428,7 +428,7 @@ The where clause will bind to all available predicates. Each binding will then be used in the construct part to create the new triples. A more elaborate example would be to create a new fact `grandparent` into -the destination graphs by properly extracting graph patterns via the where +the destination graphs by properly extracting graph patterns via the `WHERE` clause. ``` @@ -517,3 +517,51 @@ number of blank nodes. The syntax is always the same, they all start with the prefix `_:` followed by a logical ID. On insertion of each new fact, BQL guarantees a new unique blank node will be generated by each of them. Example of multiple blank nodes generated at once are `_:v0`, `_:v1`, etc. + + +## Removing complex facts out of existing graphs using existing statements + +In some cases you want to create remove facts--remove existing triples---in an +existing graph or graphs based on facts existing on the same or other graphs. +Deconstructing facts requires two steps: (1) querying for the information that +is going to be used to remove facts, and (2) how the facts to be removed are +going to be assembled. An illustrative example is: + +``` + DECONSTRUCT { + ?s ?p ?o + } + IN ?dest + FROM ?src + WHERE { + ?s ?p ?o + }; +``` + +The above example would remove all immutable triples in the `?dest` graph that +were found in the `?src` graph. As the `CONSTRUCT` statement, the `DECONTRUCT` +statement supports multiple graph on the `IN` and `FROM` clauses of the +statement. + +Following the example used in the previous section, we could use the +`DECONSTRUCT` to remove `grandparent` facts in a destination graph built from +a source graphs by properly extracting graph patterns via the `WHERE` +clause. + +``` + DECONSTRUCT { + ?ancestor "grandparent"@[] ?grandchildren + } + INTO ?dest + FROM ?src + WHERE { + ?ancestor "parent"@[] ?c . + ?c "parent"@[] ?grandchildren + }; +``` + +The `DECONSTRUCT` statement does not support neither the blank node notation +nor the reification syntax. Those are used to refer to newly created nodes +introduced by the statement, which makes sends on `CONSTRUCT` statements. +However, `DECONSTRUTC` statements already have all the required information +to assemble the triples to remove.