Difference between revisions of " Client Libraries"

From Blazegraph
Jump to: navigation, search
(Features support matrix)
Line 1: Line 1:
=Features support matrix=
+
==Features support matrix==
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 243: Line 243:
 
|}
 
|}
  
=dotNetRDF Client Support=
+
==dotNetRDF Client Support==
==Usage==
+
===Usage===
 
Blazegraph dotNetRDF client code is [https://github.com/SYSTAP/blazegraph-dotnetrdf here].<br>
 
Blazegraph dotNetRDF client code is [https://github.com/SYSTAP/blazegraph-dotnetrdf here].<br>
  
Line 251: Line 251:
  
  
==Examples of using Blazegraph connector==
+
===Examples of using Blazegraph connector===
===Create new graph===
+
====Create new graph====
 
<pre>
 
<pre>
 
BlazegraphConnector connector = new BlazegraphConnector("http://localhost:9999/bigdata/");
 
BlazegraphConnector connector = new BlazegraphConnector("http://localhost:9999/bigdata/");
Line 270: Line 270:
 
</pre>
 
</pre>
  
===Load graph===
+
====Load graph====
 
<pre>
 
<pre>
 
Graph loadGraph = new Graph();
 
Graph loadGraph = new Graph();
 
connector.LoadGraph(loadGraph, UriFactory.Create("http://example/bookStore"));
 
connector.LoadGraph(loadGraph, UriFactory.Create("http://example/bookStore"));
 
</pre>
 
</pre>
===Update graph===
+
====Update graph====
 
<pre>
 
<pre>
 
Triple triple2remove = new Triple(
 
Triple triple2remove = new Triple(
Line 293: Line 293:
 
);
 
);
 
</pre>
 
</pre>
===Delete graph===
+
====Delete graph====
 
<pre>
 
<pre>
 
connector.DeleteGraph(UriFactory.Create("http://example/bookStore"));
 
connector.DeleteGraph(UriFactory.Create("http://example/bookStore"));
 
</pre>
 
</pre>
===Query===
+
====Query====
 
<pre>
 
<pre>
 
SparqlResultSet resultSet = (SparqlResultSet)connector.Query("SELECT * { ?s ?p ?o }");
 
SparqlResultSet resultSet = (SparqlResultSet)connector.Query("SELECT * { ?s ?p ?o }");
Line 305: Line 305:
 
</pre>
 
</pre>
  
=Python Client Support=
+
==Python Client Support==
 
[http://pymantic.readthedocs.org/en/latest/ Pymantic] (Semantic Web and RDF library for Python ) could be used as a client for Blazegraph.<br>
 
[http://pymantic.readthedocs.org/en/latest/ Pymantic] (Semantic Web and RDF library for Python ) could be used as a client for Blazegraph.<br>
 
You can download the code [https://github.com/SYSTAP/blazegraph-python here].
 
You can download the code [https://github.com/SYSTAP/blazegraph-python here].
  
==Requirements==
+
===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.
 
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.
  
==Install==
+
===Install===
 
<pre>
 
<pre>
 
$ python setup.py install
 
$ python setup.py install
Line 318: Line 318:
 
This will install Pymantic and all its dependencies.
 
This will install Pymantic and all its dependencies.
  
==Quick Start==
+
===Quick Start===
 
<pre>
 
<pre>
 
from pymantic import sparql
 
from pymantic import sparql

Revision as of 07:14, 6 November 2015

Features support matrix

REST Endpoint Call / parameters Pyton client (Pymantic) dotNetRDF
QUERY
GET Request-URI ?query=...
+ +
 POST Request-URI ?query=...
+ +
parameters timestamp - +
explain - -
analytic - -
default-graph-uri + -
named-graph-uri + -
format - -
baseURI - -
includeInferred - -
timeout - -
${var}=Value - -
headers X-BIGDATA-MAX-QUERY-MILLIS + +
INSERT
INSERT RDF (POST with Body)
POST Request-URI
... 
Content-Type:
...
BODY
- -
INSERT RDF (POST with URLs)
POST Request-URI ?uri=URI
- -
DELETE
DELETE with Query
DELETE Request-URI ?query=...
- -
DELETE with Body (using POST)
POST Request-URI ?delete
...
Content-Type
...
BODY
- -
UPDATE
UPDATE (SPARQL 1.1 UPDATE)
 POST Request-URI ?update=... 
+ -
parameters using-graph-uri + -
using-named-graph-uri + -
UPDATE (DELETE + INSERT)
PUT Request-URI ?query=...
...
Content-Type
...
BODY 
- +
UPDATE

(POST with Multi-Part Request Body)

POST Request-URI ?updatePost
...
Content-Type: multipart/form-data; boundary=...
...
form-data; name="remove"
Content-Type: ...
Content-Body
...
form-data; name="add"
Content-Type: ...
Content-Body
...
BODY 
- +
Multi-Tenancy API
DESCRIBE DATA SETS
GET /bigdata/namespace
- -
CREATE DATA SET
POST /bigdata/namespace
...
Content-Type
...
BODY
- -
DESTROY DATA SET
DELETE /bigdata/namespace/NAMESPACE
- -
Transaction Management API
POST /bigdata/tx => txId
- +
COMMIT-TX
POST /bigdata/tx/txid?COMMIT
- +
LIST-TX
GET /bigdata/tx
- -
CREATE-TX
POST /bigdata/tx(?timestamp=TIMESTAMP)
- +
STATUS-TX
POST /bigdata/tx/txId?STATUS
- -
ABORT-TX
POST /bigdata/tx/txId?ABORT
- +
PREPARE-TX
POST /bigdata/tx/txId?PREPARE
- -
Access Path Operations
FAST RANGE COUNTS
GET Request-URI ?ESTCARD&([s|p|o|c]=(uri|literal))[&exact=(true|false)+
- -
HASSTMT
GET Request-URI ?HASSTMT&([s|p|o|c]=(uri|literal))[&includeInferred=(true|false)+
- -
GETSTMTS
GET Request-URI ?GETSTMTS
...
Content-Type
...
- -
POST Request-URI ?GETSTMTS
...
Content-Type
…
- -
DELETE with Access Path
DELETE Request-URI ?([s|p|o|c]=(uri|literal))+
- only c parameter
STATUS
GET /status
- -
CANCEL
POST /bigdata/sparql/?cancelQuery&queryId=....
- -

dotNetRDF Client Support

Usage

Blazegraph dotNetRDF client code is here.

Download BlazegraphConnector.dll and dotNetRDF dll files. Then add them to your 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

Pymantic (Semantic Web and RDF library for Python ) could be used as a client for Blazegraph.
You can download the code here.

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.

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']