使用 dotNetRDF 删除 RDF 元组 [英] Delete RDF tuple using dotNetRDF
问题描述
我想使用 dotNetRDF 删除 RDF 元组.这是我的 RDF 文件:
I'd like to delete a RDF tuple using dotNetRDF. Here is my RDF file:
<rdf:RDF xml:base="http://www.example.org/destDetails#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:ns0="http://www.example.org/destDetails#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="&ns0;0165a659-54ea-4e80-bee7-9d3951d47ae3">
<ns0:ID>0165a659-54ea-4e80-bee7-9d3951d47ae3</ns0:ID>
<ns0:destination rdf:resource="&ns0;VELES" />
<ns0:distrName>Test Test</ns0:distrName>
<ns0:hasTimeStart>17:00</ns0:hasTimeStart>
<ns0:hasTimeStop>17:55</ns0:hasTimeStop>
<ns0:moneyOneDir>130 den.</ns0:moneyOneDir>
<ns0:moneyTwoDir>---</ns0:moneyTwoDir>
</rdf:Description>
</rdf:RDF>
这是我使用的代码:
TripleStore magacinTorki = new TripleStore();
//kreiranje na graf
Graph rdf = new Graph();
// Create a dataset and use the named graph as the default graph
FileLoader.Load(rdf, rdfDatoteka, new RdfXmlParser());
rdf.BaseUri = new Uri("http://www.example.org/destDetails"); // Remove the name from the graph
// If the graph has no name it is added as the default graph
magacinTorki.Add(rdf);
SparqlUpdateParser parser = new SparqlUpdateParser();
SparqlParameterizedString cmdString = new SparqlParameterizedString();
cmdString.CommandText = @"PREFIX ns0: <http://www.example.org/destDetails#>"
+ " PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ " DELETE "
+ " WHERE {"
+ " GRAPH @graph { ?dest ?p ?o"
+ " ?dest ns0:nodeID @destID} }";
cmdString.SetUri("graph",rdf.BaseUri);
cmdString.SetLiteral("destID",destID);
SparqlUpdateCommandSet cmds = parser.ParseFromString(cmdString);
LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(magacinTorki);
processor.ProcessCommandSet(cmds);
rdf.SaveToFile(rdfDatoteka);
然而,RDF 文件没有发生任何变化.
However nothing is happening to the RDF file.
这段代码对我来说很好用,因为我没有被要求使用 SPARQL 删除三元组
This code works fine for me, because I was not asked to delete the triples using SPARQL
Graph rdf = new Graph();
// Create a dataset and use the named graph as the default graph
FileLoader.Load(rdf, rdfDatoteka, new RdfXmlParser());
rdf.BaseUri = new Uri("http://www.example.org/destDetails");
INode n = rdf.GetUriNode(new Uri("http://www.example.org/destDetails#" + destID));
if (n != null)
{
rdf.Retract(rdf.GetTriplesWithSubject(n));
}
rdf.SaveToFile(rdfDatoteka);
其中 destID
是所有三元组的主题.
where destID
is a subject of all triples.
推荐答案
您的查询实际上与您的数据不匹配,这就是您的 DELETE
无效的原因.
Your query does not actually match your data which is why your DELETE
has no effect.
在您的数据中,您有 ns0:ID
但在您的 DELETE
中,您尝试与 ns0:nodeID
匹配 - 因此不会有任何数据匹配,不会删除任何内容.
In your data you have ns0:ID
but in your DELETE
you try to match against ns0:nodeID
- therefore no data will be matched and nothing will be deleted.
这篇关于使用 dotNetRDF 删除 RDF 元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!