Skip to content

Latest commit

History

History
144 lines (103 loc) 路 5.21 KB

README.md

File metadata and controls

144 lines (103 loc) 路 5.21 KB

Comunica SPARQL

npm version Docker Pulls

Linked Data on the Web is being published in different ways, such as data dumps, subject pages, results of SPARQL queries, and Triple Pattern Fragments. This client is able to solve queries over such heterogeneous interfaces.

Concretely, Comunica SPARQL is a module that is preconfigured with a configuration file to initialize the Comunica engine with actors to evaluate SPARQL queries over heterogeneous interfaces.

It's main distinguishing features are the following:

  • High modularity enabling easy extensions and customization.
  • Federated querying over heterogeneous interfaces.
  • Can run using Node.JS, in the browser, and via the command-line.

Comunica can either be invoked dynamically using a configuration file, or statically using a pre-compiled configuration file. The latter will be faster to start because the dependency-injection phase can be avoided.

Execute SPARQL queries

This actor can be used to execute SPARQL queries from the command line, HTTP (SPARQL protocol), within a Node.JS application, or from a browser.

Usage from the command line

Show 100 triples from http://fragments.dbpedia.org/2015-10/en:

$ comunica-sparql http://fragments.dbpedia.org/2015-10/en "CONSTRUCT WHERE { ?s ?p ?o } LIMIT 100"

Show the help with all options:

$ comunica-sparql --help

The dynamic variant of this executable is comunica-dynamic-sparql. An alternative config file can be passed via the COMUNICA_CONFIG environment variable.

When you are working with this module in the Comunica monorepo development environment, this command can be invoked directly as follows:

node bin/query.js http://fragments.dbpedia.org/2015-10/en "CONSTRUCT WHERE { ?s ?p ?o } LIMIT 100"

Usage from HTTP

Start a webservice exposing http://fragments.dbpedia.org/2015-10/en via the SPARQL protocol.

$ comunica-sparql-http "{ \"sources\": [{ \"type\": \"entrypoint\", \"value\" : \"http://fragments.dbpedia.org/2015/en\" }]}""

Show the help with all options:

$ comunica-sparql-http --help

The HTTP service can only be started dynamically. An alternative config file can be passed via the COMUNICA_CONFIG environment variable.

Usage within application

Static:

const newEngine = require('@comunica/actor-init-sparql').newEngine;

const myEngine = newEngine();
myEngine.query('SELECT * { ?s ?p <http://dbpedia.org/resource/Belgium>. ?s ?p ?o } LIMIT 100',
  { sources: [ { type: 'hypermedia', value: 'http://fragments.dbpedia.org/2015/en' } ] })
  .then(function (result) {
    result.bindingsStream.on('data', function (data) {
      console.log(data.toObject());
    });
  });

Dynamic:

const newEngineDynamic = require('@comunica/actor-init-sparql').newEngineDynamic;

newEngineDynamic().then(function (myEngine) {
  myEngine.query('SELECT * { ?s ?p <http://dbpedia.org/resource/Belgium>. ?s ?p ?o } LIMIT 100',
    { sources: [ { type: 'hypermedia', value: 'http://fragments.dbpedia.org/2015/en' } ] })
    .then(function (result) {
      result.bindingsStream.on('data', function (data) {
        console.log(data.toObject());
      });
    });
});

Usage within browser

This engine can run in the browser using Webpack. To created a web-packed version of the engine, run yarn run browser to create comunica-browser.js.

Include this file in your webpage as follows:

<script src="path/to/comunica-browser.js"></script>

After that, Comunica.newEngine can be called via JavaScript.

const myEngine = Comunica.newEngine();
myEngine.query('SELECT * { ?s ?p <http://dbpedia.org/resource/Belgium>. ?s ?p ?o } LIMIT 100',
  { sources: [ { type: 'hypermedia', value: 'http://fragments.dbpedia.org/2015/en' } ] })
  .then(function (result) {
    result.bindingsStream.on('data', function (data) {
      console.log(data.toObject());
    });
  });

The browser script is pre-compiled using a config file and can therefore only be invoked dynamically. See the prepare and browser scripts in package.json to compile using a custom config file.

Installation

Comunica requires Node.JS 8.0 or higher and is tested on OSX and Linux.

The easiest way to install the client is by installing it from NPM as follows:

$ [sudo] npm install -g @comunica/actor-init-sparql

Alternatively, you can install from the latest GitHub sources. For this, please refer to the README of the Comunica monorepo.