2.0.8 • Published 6 years ago

sparql-iterator v2.0.8

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

Sparql Iterator

Build Status Coverage Status

A fast and simple SPARQL query interface for Linked Data Fragments and hyper-graph-db.

Note: This is a fork of Linked Data Fragments Client which includes only the code for the sparql interator. It has been modified to accept hyper-graph-db as a client.

Installation

npm install sparql-iterator

Simple Use

First, create or connect to a HyperGraph representation of a dataset. Then create a SparqlIterator to evaluate SPARQL queries on that dataset.

var SparqlIterator = require('sparql-iterator');
var hypergraph = require('hyper-graph-db');

var graph = new hypergraph(storage, key);
var query = 'SELECT * { ?s ?p <http://dbpedia.org/resource/Belgium>. ?s ?p ?o } LIMIT 100',
    results = new SparqlIterator(query, { hypergraph: graph });
results.on('data', function (result) { console.log(result); });

API

var stream = new SparqlIterator(query, options);

Returns a new stream of results. Expects query to be a valid SPARQL query as a string or an object representing a parsed query (refer to SPARQL.js).

Expects options argument to be an object passing in the client to use. Either:

{
  hypergraph: instance of HyperGraph,
}

or:

{
  fragmentsClient: an instance of LinkedDataFragementsClient,
}

stream.on('data', cb)

A data event is fired for each new result that matches the SPARQL query.

stream.on('end', cb)

A end event is fired when the query has completed.

stream.on('error', cb)

A error event is fired when an error has occurred.