我喜欢使用 dotNetRDF 从 RDF 文件中删除 RDF 元组。这是我正在使用的代码
public void deleteDest(string destID)
{
TripleStore store = new TripleStore();
Graph rdf = new Graph();
FileLoader.Load(rdf, rdfFilePath, new RdfXmlParser());
store.Add(rdf);
SparqlUpdateParser parser = new SparqlUpdateParser();
SparqlParameterizedString cmdString = new SparqlParameterizedString();
cmdString.CommandText = "PREFIX j.0: <http://www.example.org/destDetails#>"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "DELETE "
+ "WHERE { "
+ " ?dest j.0:ID \"" + destID + "\" "
+ "}";
SparqlUpdateCommandSet cmds = parser.ParseFromString(cmdString);
LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(store);
processor.ProcessCommandSet(cmds);
rdf.SaveToFile(rdfFilePath);
}
这是我的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>
但是,不会对 RDF 文件应用任何更改。