-
Notifications
You must be signed in to change notification settings - Fork 173
Client_Libraries
Brad Bebee edited this page Feb 13, 2020
·
1 revision
Blazegraph dotNetRDF client code is here.
Download Blazegraph client dll and dotNetRDF dll then add them to the project or include by the NuGet. Look at the dotNetRDF documentation.
BlazegraphConnector connector = new BlazegraphConnector("http://localhost:9999/bigdata/");
Graph newGraph = new Graph();
newGraph.BaseUri = UriFactory.Create("http://example/bookStore");
Triple triple = new Triple(
newGraph.CreateUriNode(UriFactory.Create("http://example/book1")),
newGraph.CreateUriNode(UriFactory.Create("http://example.org/ns#price")),
newGraph.CreateLiteralNode("42", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger))
);
newGraph.Assert(triple);
connector.SaveGraph(newGraph);
Graph loadGraph = new Graph();
connector.LoadGraph(loadGraph, UriFactory.Create("http://example/bookStore"));
Triple triple2remove = new Triple(
newGraph.CreateUriNode(UriFactory.Create("http://example/book1")),
newGraph.CreateUriNode(UriFactory.Create("http://example.org/ns#price")),
newGraph.CreateLiteralNode("42", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger))
);
Triple triple2add = new Triple(
newGraph.CreateUriNode(UriFactory.Create("http://example/book1")),
newGraph.CreateUriNode(UriFactory.Create("http://purl.org/dc/elements/1.1/title")),
newGraph.CreateLiteralNode("Fundamentals of Compiler Design", new Uri(XmlSpecsHelper.XmlSchemaDataTypeString))
);
connector.UpdateGraph(
UriFactory.Create("http://example/bookStore"),
new List<Triple>() { triple2add },
new List<Triple>() { triple2remove }
);
connector.DeleteGraph(UriFactory.Create("http://example/bookStore"));
SparqlResultSet resultSet = (SparqlResultSet)connector.Query("SELECT * { ?s ?p ?o }");
foreach (SparqlResult result in resultSet.Results) {
Console.WriteLine(result.ToString());
}
Blazegraph supports [Pymantic ] - Semantic Web and RDF library for Python.
Pymantic requires Python 2.6 or higher. Lepl is used for the Turtle and NTriples parser. httplib2 is used for HTTP requests and the SPARQL client. simplejson and lxml are required by the SPARQL client as well.
$ python setup.py install
This will install Pymantic and all its dependencies.
from pymantic import sparql
server = sparql.SPARQLServer('http://127.0.0.1:9999/bigdata/sparql')
# Loading data to Blazegraph
server.update('load <file:///tmp/data.n3>')
# Executing query
result = server.query('select * where { <http://blazegraph.com/blazegraph> ?p ?o }')
for b in result['results']['bindings']:
print "%s %s" (b['p']['value'], b['o']['value']