Multiple SPARQL "INSERT WHERE" Queries in One Query

My question is similar to what was asked in this thread. Can I combine these 2 SPARQL INSERT into one?

I want to have multiple INSERT WHERE queries in the query, but for different items. I would like to test a specific value ("testValueN"), and if he would like to insert a new triple for this object.

An example of this might be

PREFIX Sensor: <http://example.com/Equipment.owl#> { INSERT { ?subject1 Sensor:test2 'newValue1' . } WHERE { ?subject1 Sensor:test1 'testValue1' . } }; { INSERT { ?subject2 Sensor:test2 'newValue2' . } WHERE { ?subject2 Sensor:test1 'testValue2' . } }; 

I know that the above request is incorrect. I would like to know if something like this is possible in SPARQL.

+7
source share
2 answers

Yes it is possible. In fact, your example is almost completely perfect, just lose the brackets around each insert:

 PREFIX Sensor: <http://example.com/Equipment.owl#> INSERT { ?subject1 Sensor:test2 'newValue1' . } WHERE { ?subject1 Sensor:test1 'testValue1' . }; INSERT { ?subject2 Sensor:test2 'newValue2' . } WHERE { ?subject2 Sensor:test1 'testValue2' . } 

- valid update sequence for SPARQL.

+8
source

I want to have multiple INSERT WHERE queries in the query, but for different items. I would like to test a specific value ("testValueN"), and if he would like to insert a new triple for this object.

You can do this using values to specify the oldValue / newValue pairs that you need, and this requires only one insert . It also scales better for new pairs, since you only need to add one line to the query.

 PREFIX Sensor: <http://example.com/Equipment.owl#> INSERT { ?subject Sensor:test2 ?newValue } WHERE { values (?oldValue ?newValue) { ('testValue1' 'newValue1') ('testValue2' 'newValue2') } ?subject Sensor:test1 ?oldValue } 
0
source

All Articles