0

我想使用 dotNetRDF 删除一个 RDF 元组。这是我的 RDF 文件:

<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 文件没有发生任何事情。


这段代码对我来说很好,因为没有要求我使用 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);

wheredestID是所有三元组的主题。

4

1 回答 1

2

您的查询实际上与您的数据不匹配,这就是您DELETE无效的原因。

在您拥有的数据中,ns0:ID但在您DELETE尝试匹配的数据中ns0:nodeID- 因此不会匹配任何数据,也不会删除任何内容。

于 2013-08-15T18:10:26.487 回答