4

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 {}
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Drux
  • 11,992
  • 13
  • 66
  • 116
  • I guess by now that the problem is caused by this sentence also from the specification: "Blank nodes in graph patterns act as variables, not as references to specific blank nodes in the data being queried." Referring to them as `_:b1`, `_:b2`, `_:b3` also triggers the error ... – Drux Jan 03 '15 at 05:19

1 Answers1

7

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{}
Drux
  • 11,992
  • 13
  • 66
  • 116
AndyS
  • 16,345
  • 17
  • 21
  • Thx! I see how this can handle the deletion step. A desire for using the abbreviated `[ ... ]` syntax sent me down a wrong blind alley with blank nodes. I can now also see how SPARQL DELETE/INSERT does not apply here. What I don't see yet is how I can avoid repeating the "almost" verbatim same statements in both the (now separate) `DELETE{} WHERE{}` and `INSERT{}` steps. They are the same except that `DELETE{} WHERE{}` uses variables (e.g. `?X`) whereas `INSERT{}` uses blank nodes (e.g. `_:X`) (at least in the new SPARQL Update I am now using and that seems to work.) – Drux Jan 03 '15 at 14:30
  • INSERT inserts new blank nodes. Verbatim delete can be handled with DELETE WHERE except for the use of OPTIONAL. "Almost the same" isn't "the same". – AndyS Jan 04 '15 at 17:45