Delete RDF tuple using dotNetRDF [duplicate]

点点圈 提交于 2020-01-16 09:08:10

问题


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>

Here is the code I am using:

        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);

However nothing is happening to the RDF file.


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);

where destID is a subject of all triples.


回答1:


Your query does not actually match your data which is why your DELETE has no effect.

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.



来源:https://stackoverflow.com/questions/18257942/delete-rdf-tuple-using-dotnetrdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!