Skip to content

Instantly share code, notes, and snippets.

View rvesse's full-sized avatar

Rob Vesse rvesse

View GitHub Profile
@rvesse
rvesse / StardogInitializer.java
Last active August 29, 2015 14:16
SO 28812206
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@rvesse
rvesse / CustomOperatorTransformPassing.java
Last active August 29, 2015 14:02
Demonstrates a question about how to safely pass transforms through custom algebra operators in ARQ when the transformations are top down rather than bottom up
package org.apache.jena.playground;
import org.apache.jena.atlas.io.IndentedWriter;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.sparql.algebra.AlgebraQuad;
import com.hp.hpl.jena.sparql.algebra.Op;
import com.hp.hpl.jena.sparql.algebra.Transform;
@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 / 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 / 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 / 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 / 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 / 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"));