Client Libraries

From Blazegraph
Revision as of 12:03, 29 October 2015 by Maria Krokhaleva (Talk | contribs) (Created page with "=dotNetRDF Client Support= ==Usage== Blazegraph dotNetRDF client code is [ here].</br> Download [Blazegraph client dll] and [http://www.dotnetrdf.org/content.asp?pageID=Down...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

dotNetRDF Client Support

Usage

Blazegraph dotNetRDF client code is [ here].</br>

Download [Blazegraph client dll] and dotNetRDF dll then add them to the project or include by the NuGet.</br> 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']