Sparql删除节点的所有子节点

时间:2015-12-30 09:03:34

标签: sparql rdf jena fuseki turtle-rdf

我对使用SPARQL删除triplestore(fuseki)中的元素有疑问。我已将以下元素存储在图表中:

<ChargingRequest/66769> a keak-ev:ChargingRequest ;
cnr:priority 2 ; 
keak-ev:chargingNeed [
 keak-eval:temporalContext [
    keak-time:start "2015-09-15T12:00:00Z"^^xsd:dateTime ;
    keak-time:end "2015-09-15T18:00:00Z"^^xsd:dateTime
  ] ;
  keak-eval:minimalValue [ # the powerMin
    qudt:unit qudt-unit:Watt ; 
    qudt:numericValue "7000"^^xsd:double 
  ] ;
] .

我想删除节点&lt; ChargingRequest / 66769&GT;和他所有的财产。

我试过

   DELETE WHERE {
     <http://localhost:3030/keak/ChargingRequest/66769>  ?p ?o.
     keak-ev:chargingNeed ?p ?o
  }

但它不会删除

下面的节点
keak-eval:temporalContext [
    keak-time:start "2015-09-15T12:00:00Z"^^xsd:dateTime ;
    keak-time:end "2015-09-15T18:00:00Z"^^xsd:dateTime
  ] ;
  keak-eval:minimalValue [ # the powerMin
    qudt:unit qudt-unit:Watt ; 
    qudt:numericValue "7000"^^xsd:double 
  ] ;

请帮帮我,谢谢你的时间。

2 个答案:

答案 0 :(得分:2)

有多种方法可以做到这一点,但我认为单个请求中的3个操作是最清楚的:注意这是一个请求 - 请参阅“;”将操作分开。

  # Delete 3-deep
  DELETE {
    ?x ?p ?o 
  } WHERE {
     <http://localhost:3030/keak/ChargingRequest/66769>  ?q ?n1.
     ?n1 ?p1 ?x .
     ?x ?p ?o .
  } ;

  # Delete 2-deep
  DELETE {
    ?x ?p ?o 
  } WHERE {
     <http://localhost:3030/keak/ChargingRequest/66769>  ?q ?x.
     ?x ?p ?o .
  } ;
  # Delete immediate
  DELETE WHERE { <http://localhost:3030/keak/ChargingRequest/66769>  ?q ?x. }

答案 1 :(得分:0)

我设法让它发挥作用,这是最终的解决方案

WITH <http://localhost:3030/keak/>  
 DELETE { 
  ?x ?p ?o 
} WHERE { 
  <http://localhost:3030/keak/ChargingRequest/66769>  ?q ?n1.
  ?n1 ?p1 ?x .
  ?x ?p ?o .
};

WITH <http://localhost:3030/keak/>  
 DELETE {
  ?x ?p ?o 
 } WHERE  {
   <http://localhost:3030/keak/ChargingRequest/66769>  ?q ?x.
   ?x ?p ?o .
 };

WITH <http://localhost:3030/keak/>  
 DELETE {
   <http://localhost:3030/keak/ChargingRequest/66769> ?q ?x 
 } WHERE  {
    <http://localhost:3030/keak/ChargingRequest/66769>  ?q ?x.
}

非常感谢您的回答