Skip to content

Instantly share code, notes, and snippets.

View rvesse's full-sized avatar

Rob Vesse rvesse

View GitHub Profile
@rvesse
rvesse / StardogApproximatedUpdate.cs
Created December 18, 2013 09:38
Shows how to use a GenericUpdateProcessor to get approximated SPARQL Updates even if using a version of dotNetRDF/Stardog that does not provide native SPARQL Update support for Stardog. There is no downside to this method since when used with versions of dotNetRDF/Stardog that do provide native SPARQL Update it delegates to that implementation o…
// Assume we already have a StardogConnector in the variable Stardog
// Firstly need to parse our updates
SparqlUpdateCommandSet updates = new SparqlUpdateParser().ParseFromString(@"
INSERT DATA { GRAPH <http://example.org/graph> { <http://s> <http://p> <http://o } }
");
// Then we can create an update processor and execute the updates
GenericUpdateProcessor processor = new GenericUpdateProcessor(stardog);
processor.ProcessCommandSet(updates);
@rvesse
rvesse / StardogSparqlUpdate.cs
Created December 18, 2013 09:23
Issuing a SPARQL Update against Stardog
// Assume we already have a StardogConnector in the variable Stardog
stardog.Update(@"
INSERT DATA { GRAPH <http://example.org/graph> { <http://s> <http://p> <http://o } }
");
@rvesse
rvesse / StardogParameterizedUpdate.cs
Created December 18, 2013 09:25
Issuing a parameterised update against Stardog
// Assume we have a StardogConnector in the variable stardog
// Create the update
SparqlParameterizedString updateString = new SparqlParameterizedString();
updateString.CommandText = @"DELETE WHERE
{
?s a @type .
}";
// Set the parameter
updateString.SetUri("type", new Uri("http://example.org/myType"));
@rvesse
rvesse / StardogDeleteGraph.cs
Created October 30, 2013 10:22
Deleting a graph from Stardog
// Assume we already have a StardogConnector in the variable stardog
// Deleting a graph simply requires the URI of the graph to delete
stardog.DeleteGraph(new Uri("http://example.org/name"));
@rvesse
rvesse / StardogParameterizedQuery.cs
Last active December 26, 2015 23:28
Issuing a parameterised SPARQL query to Stardog
// Assume we have a StardogConnector in the variable stardog
// Create the query
SparqlParameterizedString queryString = new SparqlParameterizedString();
queryString.CommandText = @"SELECT * WHERE
{
?s a @type .
}";
// Set the parameter
queryString.SetUri("type", new Uri("http://example.org/myType"));
@rvesse
rvesse / StardogSparqlQuery.cs
Created October 30, 2013 10:19
Issuing a SPARQL Query to Stardog with dotNetRDF
// Assume we already have a StardogConnector in the variable Stardog
SparqlResultSet results = stardog.Query(@"
SELECT DISTINCT ?type WHERE { [] a ?type } LIMIT 10
") as SparqlResultSet;
// Now work with the SPARQL Results as desired...
// Assumes we already have a StardogConnector in the variable stardog
// Create the Triples we want to remove
NodeFactory factory = new NodeFactory();
List<Triple> toRemove = new List<Triple>();
toRemove.Add(new Triple(factory.CreateUriNode(new Uri("http://subject")),
factory.createUriNode(new Uri("http://predicate")),
factory.CreateUriNode(new Uri("http://object"))
);
// And so forth...
// Assuming we already have a StardogConnector in the variable Stardog
// Define a Graph that will receive our data
IGraph g = new Graph();
// Load from Stardog
stardog.LoadGraph(g, new Uri("http://example.org/name"));
// Assuming we already have a StardogConnector in the variable stardog
IGraph g = new Graph();
// The graph gets populated with data somehow...
// Set the name for the graph
g.BaseUri = new Uri("http://example.org/name");
// Save to Stardog
stardog.SaveGraph(g);
StardogConnector stardog = new StardogConnector("http://localhost:5820", "db", "admin", "admin");