SPARQL插入/删除 [英] SPARQL INSERT/DELETE
问题描述
我需要一些帮助来编写更新查询.
DELETE {
?contactInfo vivo:freeTextValue5 ?o .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
能否让我知道此更新"查询出了什么问题?
我正在猜测,您的问题是此更新添加了一个新的三元组,但没有删除旧的三元组. >
原因是您的DELETE
子句包含一个未绑定变量:?o
.这是不允许的-或至少发生的事情是SPARQL引擎会简单地忽略具有未绑定变量的模式.因此,您的DELETE
实际上不会删除任何三元组.变量?o
需要绑定到WHERE
子句中的值.
解决此问题的一种方法是将?o
替换为特定值:
DELETE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
通常,您可以使用VALUES
子句将?o
绑定到一个值,如下所示:
DELETE {
?contactInfo vivo:freeTextValue5 ?o.
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
VALUES ?o { "old_url"^^<http://www.w3.org/2001/XMLSchema#string> }
?contactInfo vivo:freeTextValue5 ?o.
}
这可能是更好的方法,因为它可以更轻松地将更新扩展为?o
的不同值.
I need some help to write my update query.
DELETE {
?contactInfo vivo:freeTextValue5 ?o .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
Can you please let me know what is wrong with this "update" query?
I'm guessing that your problem is that this update adds a new triple, but does not remove the old one.
The reason is that your DELETE
clause contains an unbound variable: ?o
. This is not allowed - or at least what happens is that patterns with unbound variables are simply ignored by the SPARQL engine. So your DELETE
won't actually remove any triples. The variable ?o
needs to be bound to a value in your WHERE
clause.
One way to fix this is to just replace ?o
with the specific value:
DELETE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
More generally, you can use a VALUES
clause to bind ?o
to a value, like this:
DELETE {
?contactInfo vivo:freeTextValue5 ?o.
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
VALUES ?o { "old_url"^^<http://www.w3.org/2001/XMLSchema#string> }
?contactInfo vivo:freeTextValue5 ?o.
}
This is perhaps the better approach as it makes it easier to extend your update to different values for ?o
.
这篇关于SPARQL插入/删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!