Deleting complex statements (involving blank nodes)

In the tutorial available here, there is following statement added to the database:
:cowriter owl:propertyChainAxiom (:writerOf :writer) .
This statement will translate to some triplets involving two blank nodes:

Now, how can I delete such (this) statement from the database? Using the "Remove data" widget does not affect the construct. I have tried to explicitly specify the triplets in DELETE statements, but I have trouble understanding when blank nodes can be directly addressed and when not.

Thank you

Something like this?

:cowriter owl:propertyChainAxiom ?blank001 .
?blank001 rdf:first :writerOf .
?blank001 rdf:rest ?blank002 .
<<< of pattern here>>>
:cowriter owl:propertyChainAxiom ?blank001 .
?blank001 rdf:first :writerOf .
?blank001 rdf:rest ?blank002 .
<<< of pattern here>>>

Seems repetitive but it should work… Blanks bind to variables same way as others, but you can’t use them as constants (rigid designators) which is why DELETE DATA would not work. I’m sure there is a more elegant solution, or a better explanation (and sorry, I can’t try it out right now).

Hi Zoltán,

you are correct that the bnodes cause issues there. One can figure out a generic SPARQL query to correctly delete the RDF serialisation of such axioms (also rules, SHACL shapes, etc.) similarly to what Pierluigi describes. But it's a bit error-prone.

What usually works best in practice is maintaining your schema in a separate named graph so you can drop it altogether and then re-load the updated schema.



Thank you all for your answers.

I am coming from the relational world, thus not being able to grab something by its identifier only makes me dizzy :).

I got the idea of having separated graphs for this, and Pierluigi's suggestion is also clear. I succeeded with it. While being error-prone doing it by hand, looks quite an automatic task. Practically, the graph I have visualized can be simply translated in such a selector. Stardog Studio could really be of help in this situation with a quite simple widget: adding the ability to manually select nodes and edges on the visualized graph (ctrl, shift, lasso, etc... or simply switching to a "select mode") and then being able to get the selector statement matching the selected subgraph with the push of a button. This might be helpful in other scenarios too, like saving the result of visual exploration for further use.
On the other hand, the "Remove data" widget is really misleading right now. There is absolutely no feedback on what was or wasn't deleted while getting confirmation.

Hello @pavel ,

Now I am familiarizing myself with the named graphs and I can't find the correct syntax for adding rules in named graph as you suggested. Actually, the rule is from the same tutorial:

RULE :CowriterRule
IF {
    ?s :writer ?w1.
    ?s :writer ?w2.
    FILTER(?w1 != ?w2)
} THEN {
    ?w1 :cowriter ?w2 

Could you give me a hint on how to change this statement to be enclosed in a named graph?

Here's one way: I added your rule to a file and then

pavel$ stardog data add -g "urn:g1" test {path}/test.trig 
Adding data from file: {path}/test.trig
Transaction committed successfully in 00:00:00.132
pavel$ stardog query test "select * from <urn:g1> { ?s ?p ?o }"
|        s         |              p               |                                        o                                         |
| urn:CowriterRule | rdf:type                     | tag:stardog:api:rule:SPARQLRule                                                  |
| urn:CowriterRule | tag:stardog:api:rule:content | """IF {                                                                          |
|                  |                              |    ?s <urn:writer> ?w1 .                                                         |
|                  |                              |    ?s <urn:writer> ?w2 .                                                         |
|                  |                              |    FILTER (?w1!=?w2)                                                             |
|                  |                              | }                                                                                |
|                  |                              | THEN {                                                                           |
|                  |                              |    ?w1 <urn:cowriter> ?w2 .                                                      |
|                  |                              | }                                                                                |
|                  |                              | """                                                                              |
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.