Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zazuko/query-rdf-data-cube

Package Overview
Dependencies
Maintainers
4
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zazuko/query-rdf-data-cube

Query (or introspect) [RDF Data Cubes](https://www.w3.org/TR/vocab-data-cube/) with a JavaScript API, without writing SPARQL.

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

@zazuko/query-rdf-data-cube

npm version Build Status Coverage Status

Query and explore RDF Data Cubes with a JavaScript API, without writing SPARQL.

Installation

npm install @zazuko/query-rdf-data-cube

Documentation

See https://zazuko.github.io/query-rdf-data-cube/

Changelog: https://github.com/zazuko/query-rdf-data-cube/blob/master/CHANGELOG.md

Examples

See the examples/ folder at the root of this repository.

Working Locally

  1. git clone
  2. npm ci
  3. npm run build
Running the Tests
  • npm run test
Building and Publishing Documentation
  1. npm run docs:compile
  2. npm run docs:publish
Running the Examples
  • node examples/introspect-and-query.js

Features and Usage

This library has two main use cases: exploring an RDF Data Cube and querying an RDF Data Cube. Both usually go hand in hand.

Instantiating a Data Cube lets you access its DataSets:

const { DataCube } = require("query-rdf-data-cube");

// instantiate an RDF Data Cube with a SPARQL endpoint
const datacube = new DataCube("https://ld.stadt-zuerich.ch/query");

// fetch all its datasets
const datasets = await datacube.datasets();

// assign the 4th dataset
const dataset = datasets[3];

You could also directly instantiate a DataSet.

A DataSet can retrieve its Components, ie. its Dimensions, Measures and Attributes:

const dimensions = await dataset.dimensions();
const measures = await dataset.measures();
const attributes = await dataset.attributes();

const zeitDimension = dimensions[0];
// const raumDimension = dimensions[1];
// Again, dimensions, measures and attributes can also be constructed from scratch:
const raumDimension = new Dimension({
  label: "Raum",
  iri: "https://ld.stadt-zuerich.ch/statistics/property/RAUM"
});
const betriebsartDimension = dimensions[2];
const geschlechtDimension = dimensions[3];

const beschaeftigteMeasure = measures[0];

const quelleAttribute = attributes[0];
const glossarAttribute = attributes[1];
const erwarteteAktualisierungAttribute = attributes[4];
const korrekturAttribute = attributes[5];

This setup is quite exhaustive, in many situations you won't want to create all of these or get all of these and rely on this lib to properly guess what to query.

const query = dataset
  .query()
  // .select({}) takes binding names as keys and Component (Dimension/Attribute/Measure) as values
  .select({
    betriebsart: betriebsartDimension,
    geschlecht: geschlechtDimension,
    raum: raumDimension,
    zeit: zeitDimension,

    bep: beschaeftigteMeasure.avg(),

    // include some extra attributes, not all of them
    quelle: quelleAttribute,
    glossar: glossarAttribute,
    erwarteteAktualisierung: erwarteteAktualisierungAttribute,
    korrektur: korrekturAttribute,
  })
  .filter(raumDimension.equals("https://ld.stadt-zuerich.ch/statistics/code/R30000"))
  .groupBy("zeit")
  .having(({ bep }) => bep.gte(10000))
  .limit(3);

Now that we built a query, we can generate SPARQL out of it:

const sparql = await query.toSparql();

Or execute the SPARQL query against the SPARQL endpoint:

const results = await query.execute();

Keywords

FAQs

Package last updated on 09 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc