I like to delete a RDF tuple from a RDF file using dotNetRDF. Here is the code I\'m using
public void deleteDest(s
The problem is that your update operates over the default graph but that your dataset only contains a named graph.
FileLoader.Load(rdf, rdfFilePath, new RdfXmlParser());
store.Add(rdf);
When you do the above this loads data into your graph and assigns that graph a name based on the source of the data - in your case it gets a file://
URI. Then when you add it to the store the store uses the current name of the graph (from the BaseUri
property of the graph) and adds it as a named graph.
However your DELETE
only references the default graph which is empty in your example and your named graph is not modified in any way. There are several different ways to fix this problem.
You can specify that your named graph be treated as the default graph like so:
// Create a dataset and use the named graph as the default graph
InMemoryDataset ds = new InMemoryDataset(store, rdf.BaseUri);
// Use the dataset to create the processor
LeviathanUpdateProcessor processor = new LeviathanUpdateProcessor(ds);
You can make your named graph be treated as the default graph by removing its name before you add it to the store:
FileLoader.Load(rdf, rdfFilePath, new RdfXmlParser());
rdf.BaseUri = null; // Remove the name from the graph
// If the graph has no name it is added as the default graph
store.Add(rdf);
You can rewrite your DELETE
to reference the named graph explicitly:
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
{
GRAPH @graph { ?dest j.0:ID @destID }
}";
cmdString.SetUri("graph", rdf.BaseUri);
cmdString.SetLiteral("destID", destID);
Note that I've used verbatim string literals for readability and injected the parameters via SetUri()
and SetLiteral()
rather than string concatenation.
There is an extra space \"" + destID + "\" "
(marked with an X --> \"" + destID + "\"X")