多个 SPARQL“INSERT WHERE"在单个请求中查询 [英] Multiple SPARQL "INSERT WHERE" queries in a single request
问题描述
我的问题类似于在此线程上提出的问题 是否可以将这 2 个 SPARQL INSERT 合二为一?
My question is similar to what was asked on this thread Is it possible to combine those 2 SPARQL INSERT into one?
我想在一个查询中有多个 INSERT WHERE 语句,但针对不同的主题.我想测试一个特定的值(testValueN"),如果存在,我想为该主题插入一个新的三元组.
I want to have multiple INSERT WHERE statements in a query, but for different subjects. I will like to test a particular value ("testValueN") and if present would like to insert a new triple for that subject.
一个例子是,
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' .
}
};
我知道上面的查询是错误的.我想知道在 SPARQL 中是否有类似的可能.
I know the above query is wrong. I would like to know if something similar is possible in SPARQL.
推荐答案
是的,这是可能的.事实上,你的例子几乎完全没问题,只是失去了每个插入周围的括号:
Yes, this is possible. In fact, your example is almost completely fine, 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' .
}
是有效的 SPARQL 更新序列.
is a valid SPARQL update sequence.
这篇关于多个 SPARQL“INSERT WHERE"在单个请求中查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!