Skip to content

Client_Libraries

Brad Bebee edited this page Feb 13, 2020 · 1 revision

dotNetRDF Client Support

Usage

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.

Examples of using Blazegraph connector

Create new graph

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);

Load graph

Graph loadGraph = new Graph();
connector.LoadGraph(loadGraph, UriFactory.Create("http://example/bookStore"));

Update graph

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 }
);

Delete graph

connector.DeleteGraph(UriFactory.Create("http://example/bookStore"));

Query

SparqlResultSet resultSet = (SparqlResultSet)connector.Query("SELECT * { ?s ?p ?o }");
foreach (SparqlResult result in resultSet.Results) {
    Console.WriteLine(result.ToString());
}

Python Client Support

Blazegraph supports [Pymantic ] - Semantic Web and RDF library for Python.

Requirements

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.

Download

Install

$ python setup.py install

This will install Pymantic and all its dependencies.

Quick Start

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']
Clone this wiki locally