Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The DELETE/INSERT operation can be used to remove triples containing blank nodes: how?

I would like to use a SPARQL DELETE/INSERT to ensure that after repeated updates ?performance and certain connected blank nodes do not have multiple property values but only zero (for optional cases) or one (for mandatory cases).

If I send the DELETE/INSERT (see below) to a Jena Fuseki 1.1.1 server I receive this error message: "Blank nodes not allowed in DELETE templates".

However, the specification contains this sentence: "The DELETE/INSERT operation can be used to remove triples containing blank nodes."

So what's a valid form of a DELETE/INSERT that does the job in this case? To ease maintenance it would be good if the DELETE and INSERT parts can remain structurally similar. (This is a follow-up question.)

DELETE {
    ?performance
        mo:performer ?_ ;
        mo:singer    ?_ ;
        mo:performance_of [  ### error marked here ###
            dc:title ?_ ;
            mo:composed_in [ a mo:Composition ;
                mo:composer ?_
            ]
        ]
}
INSERT {
    ?performance
        mo:performer ?performer ;     # optional
        mo:singer    ?singer ;        # optional
        mo:performance_of [
            dc:title ?title ;         # mandatory
            mo:composed_in [ a mo:Composition ;
                mo:composer ?composer # optional
            ]
        ]
 }
 WHERE {}
like image 205
Drux Avatar asked Mar 17 '23 11:03

Drux


1 Answers

You need something in the WHERE part. This will find the bnodes, put them in variables, and use the DELETE to remove them. The DELETE{} is not itself a pattern to match - the graph pattern is the WHERE {} part.

Something like:

DELETE{
     ?performance
         mo:performance_of ?X .
     ?X dc:title ?title ;
         mo:composed_in ?Y .
     ?Y a mo:Composition .
     ?Y mo:composer ?composer .
     ?performance  mo:performer ?performer ;
                   mo:singer   ?singer
}
WHERE {
    ?performance
         mo:performance_of ?X .
     ?X dc:title ?title ;
         mo:composed_in ?Y .
     ?Y a mo:Composition .
     OPTIONAL { ?Y mo:composer ?composer }
     OPTIONAL { 
           ?performance  mo:performer ?performer ;
                         mo:singer    ?singer 
     }
}

There is no point making DELETE{} and INSERT{} the same - it's effectively a no-op.

If a variable in bout bound in a particular row from the WHERE{} part, the deletion simply skips that triple, not the rest of the instantiated template.

It may be clearer, to humans, to write the SPARQL Update in several parts. One HTTP request can have several operations, separated by ";":

DELETE{} WHERE {} ;
DELETE{} WHERE {} ;
INSERT DATA{}
like image 188
AndyS Avatar answered May 01 '23 21:05

AndyS