首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用dotNetRDF删除RDF元组

使用dotNetRDF删除RDF元组
EN

Stack Overflow用户
提问于 2013-08-15 17:13:46
回答 1查看 441关注 0票数 0

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

代码语言:javascript
复制
<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>

下面是我使用的代码:

代码语言:javascript
复制
        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删除三元组。

代码语言:javascript
复制
        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是所有三元组的主题。

EN

回答 1

Stack Overflow用户

发布于 2013-08-15 18:10:26

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

在您的数据中,您有ns0:ID,但是在您的DELETE中,您尝试与ns0:nodeID匹配-因此,没有数据将被匹配,也不会删除任何数据。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18257942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档