SPARQL:删除实例及其具有链接子属性的所有属性 [英] SPARQL: Delete instance and all of its properties with linked subproperties

查看:264
本文介绍了SPARQL:删除实例及其具有链接子属性的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用SPARQL从三元存储(在我的情况下为Virtuoso)中删除元素有疑问.我已经在图形中存储了以下元素:

I have a question about the deletion of elements from a triplestore (in my case a Virtuoso) using SPARQL. I have stored the following elements in a graph:

@prefix xy: <http://purl.oclc.org/xy/xy#> .
@prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#> .

<point> a xy:Point ;
    xy:value "10" ;
    ssn:observationResultTime <Rs_b8d4ae44-6083-4140-b4e3-11fcf38a53c8> ;
    ssn:observationSamplingTime <St_b8d4ae44-6083-4140-b4e3-11fcf38a53c8> ;
    ssn:observedBy <SensorID-b8d4ae44-6083-4140-b4e3-11fcf38a53c8> .

如您所见,我有一个xy:Point,它具有一些属性.在我的数据库中,我已经存储了许多这些点.现在我的问题是:如何删除一个点及其所有属性(甚至是observationSamplingTime,observationResultTime可能链接的子属性)?有没有简单的解决方案?现在,我通过提供所有精确的关系来删除该点及其属性:

As you can see I have one xy:Point, which has some properties. In my database I have stored dozens of these points. Now my question: How to delete one point and all of its properties (even the possibly linked subproperties of observationSamplingTime, observationResultTime)? Is there any simple solution? By now I am deleting the point and its properties by giving all exact relations like:

@prefix xy: <http://purl.oclc.org/xy/xy#> .
@prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#> 

delete {
   ?observation a xy:Point .
   ?observation xy:value ?value .
   ?observation ssn:observationResultTime ?resultTime .
   ?observation ssn:observationSamplingTime ?samplingTime .
   ?observation ssn:observedBy ?sensor .
}
WHERE {
   ?observation xy:value ?value .
   ?observation ssn:observationResultTime ?resultTime .
   ?observation ssn:observationSamplingTime ?samplingTime .
   ?observation ssn:observedBy ?sensor .
}

我想做的是删除一个xy:Point并观察其子属性的所有内容".有可能这样做吗?

What I would like to do is "Delete ?observation a xy:Point and all ob its subproperties". Is there any possibility to do that?

感谢和亲切问候

tanktoo

推荐答案

(甚至是observationsSamplingTime,observationResultTime的可能链接的子属性)?

请注意,类似这样的操作非常危险,因为您可能会从不期望的上下文中删除三元组.例如,假设您有类似的东西

Note that something like this pretty dangerous, since you might delete from triples from a context that you're not expecting to. E.g., suppose you had something like

:pointX :hasTime :time1 ;
        :hasValue :valueX .

:pointY :hasTime :time1 ;
        :hasValue :valueY .

:time1 :hasLabel "time1" .

如果您删除" :pointX ,并递归删除:time1 ,那么您也会丢失对:pointY 重要的信息.请记住,三元组商店存储三元组的 sets .事物仅通过作为主语,谓语或宾语而存在.

If you "delete" :pointX, and recursively delete :time1, then you lose information that was important for :pointY as well. Remember that a triple store stores sets of triples. Things only exist by virtue of being a subject, predicate, or object.

无论如何,您要做的事情并不难.您可以这样做:

At any rate, what you're trying to do isn't too hard. You can just do:

delete { ?s ?p ?o }
where {
  :thing (<>|!<>)* ?s . 
  ?s ?p ?o .
}

(<> |!<>)* 是通配符路径,因此?s 绑定到:thing ,其中包括:事物本身. ?p ?o 只是?s 的属性和对象.有关通配符的更多信息,请参见 SPARQL:两个节点之间是否有任何路径?.

(<>|!<>)* is a wildcard path, so ?s gets bound to anything reachable from :thing, including :thing itself. ?p and ?o are just the property and object of ?s. For more information about the wildcard, see SPARQL: is there any path between two nodes?.

这篇关于SPARQL:删除实例及其具有链接子属性的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆