@comunica/actor-init-sparql-file

A SPARQL query engine for querying over local and remote RDF files

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
21090Jun 23, 2021Oct 18, 2017Minified + gzip package size for @comunica/actor-init-sparql-file in KB

Readme

Comunica SPARQL File Init Actor

npm version

Comunica SPARQL is a SPARQL query engine for JavaScript for querying local and remote RDF files.

This module is part of the Comunica framework.

Install

$ yarn global add @comunica/actor-init-sparql-file

or

$ npm install -g @comunica/actor-init-sparql-file

Usage from the command line

Show 100 triples from a remote FOAF profile:

$ comunica-sparql-file https://ruben.verborgh.org/profile/#me "CONSTRUCT WHERE { ?s ?p ?o } LIMIT 100"

Show 100 triples from a local RDF file:

$ comunica-sparql-file path/to/my/file.ttl "CONSTRUCT WHERE { ?s ?p ?o } LIMIT 100"

Show all triples from a local and remote file:

$ comunica-sparql-file path/to/my/file.ttl https://ruben.verborgh.org/profile/#me "CONSTRUCT WHERE { ?s ?p ?o } LIMIT 100"

Show the help with all options:

$ comunica-sparql-file --help

Just like Comunica SPARQL, a dynamic variant (comunica-dynamic-sparql-file) also exists.

Read more about querying from the command line.

Usage within application

This engine can be used in JavaScript/TypeScript applications as follows:

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

const result = await myEngine.query(`
  SELECT ?s ?p ?o WHERE {
    ?s ?p <http://dbpedia.org/resource/Belgium>.
    ?s ?p ?o
  } LIMIT 100`, {
  sources: ['http://fragments.dbpedia.org/2015/en'],
});

// Consume results as a stream (best performance)
result.bindingsStream.on('data', (binding) => {
    console.log(binding.get('?s').value);
    console.log(binding.get('?s').termType);

    console.log(binding.get('?p').value);

    console.log(binding.get('?o').value);
});

// Consume results as an array (easier)
const bindings = await result.bindings();
console.log(bindings[0].get('?s').value);
console.log(bindings[0].get('?s').termType);

Read more about querying an application.

Usage as a SPARQL endpoint

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

$ comunica-sparql-file-http "{ \"sources\": [\"/path/to/my/file.ttl\"]}"

Show the help with all options:

$ comunica-sparql-file-http --help

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

Use bin/http.js when running in the Comunica monorepo development environment.

Read more about setting up a SPARQL endpoint.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.