{"id":26190098,"url":"https://github.com/zazuko/query-rdf-data-cube","last_synced_at":"2025-04-15T02:09:34.632Z","repository":{"id":35096502,"uuid":"203984000","full_name":"zazuko/query-rdf-data-cube","owner":"zazuko","description":"Explore or query RDF Data Cubes with a JavaScript API, without writing SPARQL.","archived":false,"fork":false,"pushed_at":"2023-01-04T08:50:09.000Z","size":2916,"stargazers_count":9,"open_issues_count":26,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T02:09:29.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://zazuko.github.io/query-rdf-data-cube/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zazuko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-23T11:16:39.000Z","updated_at":"2024-03-08T14:14:26.000Z","dependencies_parsed_at":"2023-01-15T13:46:06.371Z","dependency_job_id":null,"html_url":"https://github.com/zazuko/query-rdf-data-cube","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zazuko%2Fquery-rdf-data-cube","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zazuko%2Fquery-rdf-data-cube/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zazuko%2Fquery-rdf-data-cube/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zazuko%2Fquery-rdf-data-cube/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zazuko","download_url":"https://codeload.github.com/zazuko/query-rdf-data-cube/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991544,"owners_count":21194894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-12T00:52:29.585Z","updated_at":"2025-04-15T02:09:34.614Z","avatar_url":"https://github.com/zazuko.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [@zazuko/query-rdf-data-cube](https://github.com/zazuko/query-rdf-data-cube)\n\n[![npm version](https://img.shields.io/npm/v/@zazuko/query-rdf-data-cube.svg?style=flat)](https://npmjs.org/package/@zazuko/query-rdf-data-cube \"View this project on npm\")\n[![Build Status](https://travis-ci.org/zazuko/query-rdf-data-cube.svg?branch=master)](https://travis-ci.org/zazuko/query-rdf-data-cube)\n[![Coverage Status](https://coveralls.io/repos/github/zazuko/query-rdf-data-cube/badge.svg?branch=master)](https://coveralls.io/github/zazuko/query-rdf-data-cube?branch=master)\n\nQuery and explore [RDF Data Cubes](https://www.w3.org/TR/vocab-data-cube/) with a JavaScript API,\nwithout writing SPARQL.\n\n- [Installation](#installation)\n- [Concepts](#concepts)\n- [API Documentation](#api-documentation)\n- [Examples](#examples)\n- [Working Locally](#working-locally)\n- [Features and Usage](#features-and-usage)\n\n## Installation\n\n- `npm install @zazuko/query-rdf-data-cube`\n- [CHANGELOG](https://github.com/zazuko/query-rdf-data-cube/blob/master/CHANGELOG.md)\n\n## Concepts\n\nRDF Data Cubes are an implementation of the generic [OLAP](https://en.wikipedia.org/wiki/Online_analytical_processing) concept and more specifically, [OLAP cube](https://en.wikipedia.org/wiki/OLAP_cube).\nWhat RDF Data Cube calls _data structure definition_ can be mapped to _dimension tables_ in [OLAP cubes](https://en.wikipedia.org/wiki/OLAP_cube#Terminology), the _observations_ in RDF Data Cube are called _fact tables_. \n\nThe main classes this library exposes are the following:\n\n- [`DataCubeEntryPoint`](https://zazuko.github.io/query-rdf-data-cube/classes/datacubeentrypoint.html)  \n    The *EntryPoint* has a SPARQL endpoint.\n    It lets you discover and fetch Data Cubes available at this endpoint and their corresponding Dimensions, Attributes, and Measures.\n- [`DataCube`](https://zazuko.github.io/query-rdf-data-cube/classes/datacube.html)  \n    A Data Cube represents the [*cube model*](https://www.w3.org/TR/vocab-data-cube/#cubes-model). It has Dimensions, Attributes and Measures and is initialized with an IRI and a graph IRI.  \n    Querying a DataCube starts with having a DataCube instance.\n- [`Component`](https://zazuko.github.io/query-rdf-data-cube/classes/component.html)  \n    An abstract class, parent of the following [*component properties*](https://www.w3.org/TR/vocab-data-cube/#dsd-dimensions):\n    - [`Dimension`](https://zazuko.github.io/query-rdf-data-cube/classes/dimension.html)\n    - [`Attribute`](https://zazuko.github.io/query-rdf-data-cube/classes/attribute.html)\n    - [`Measure`](https://zazuko.github.io/query-rdf-data-cube/classes/measure.html)\n    \n    [Filter operators](https://zazuko.github.io/query-rdf-data-cube/classes/baseexpr.html#bound) can be applied directly to components.\n\n\n## API Documentation\n\nSee \u003chttps://zazuko.github.io/query-rdf-data-cube/\u003e\n\n## Examples\n\nSee the [`examples/`](https://github.com/zazuko/query-rdf-data-cube/tree/master/examples) folder at the root of this repository.\n\n## Working Locally\n\n1. `git clone`\n1. `npm ci`\n1. `npm run build`\n\n#### Running the Tests\n\n* `npm run test`\n\n#### Building and Publishing Documentation\n\n1. `npm run docs:compile`\n1. `npm run docs:publish`\n\n#### Running the Examples\n\n* `node examples/introspect-and-query.js`\n\n## Features and Usage\n\nThis library has two main use cases: exploring an RDF Data Cube and querying an RDF Data Cube.\nBoth usually go hand in hand.\n\nInstantiating a DataCube EntryPoint lets you access its DataCubes:\n```js\nconst { DataCubeEntryPoint } = require(\"query-rdf-data-cube\");\n\n// instantiate an RDF Data Cube with a SPARQL endpoint\nconst entryPoint = new DataCubeEntryPoint(\"https://ld.stadt-zuerich.ch/query\");\n\n// fetch all its dataCubes\nconst dataCubes = await entryPoint.dataCubes();\n\n// assign the 4th datacube\nconst datacube = dataCubes[3];\n```\n\nYou could also [directly instantiate a DataCube](https://github.com/zazuko/query-rdf-data-cube/blob/ebb4dca18df46fc1f384ed9ee3876b2c865d5d20/src/expressions/filter.test.ts#L13-L21).\n\nA DataCube can retrieve its *Components*, ie. its *Dimensions*, *Measures* and *Attributes*:\n\n```js\nconst dimensions = await datacube.dimensions();\nconst measures = await datacube.measures();\nconst attributes = await datacube.attributes();\n\nconst zeitDimension = dimensions[0];\n// const raumDimension = dimensions[1];\n// Again, dimensions, measures and attributes can also be constructed from scratch:\nconst raumDimension = new Dimension({\n  label: \"Raum\",\n  iri: \"https://ld.stadt-zuerich.ch/statistics/property/RAUM\"\n});\nconst betriebsartDimension = dimensions[2];\nconst geschlechtDimension = dimensions[3];\n\nconst beschaeftigteMeasure = measures[0];\n\nconst quelleAttribute = attributes[0];\nconst glossarAttribute = attributes[1];\nconst erwarteteAktualisierungAttribute = attributes[4];\nconst korrekturAttribute = attributes[5];\n```\n\nThis 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.\n\n```js\nconst query = datacube\n  .query()\n  // .select({}) takes binding names as keys and Component (Dimension/Attribute/Measure) as values\n  .select({\n    betriebsart: betriebsartDimension,\n    geschlecht: geschlechtDimension,\n    raum: raumDimension,\n    zeit: zeitDimension,\n\n    bep: beschaeftigteMeasure.avg(),\n\n    // include some extra attributes, not all of them\n    quelle: quelleAttribute,\n    glossar: glossarAttribute,\n    erwarteteAktualisierung: erwarteteAktualisierungAttribute,\n    korrektur: korrekturAttribute,\n  })\n  .filter(raumDimension.equals(\"https://ld.stadt-zuerich.ch/statistics/code/R30000\"))\n  .groupBy(\"zeit\")\n  .having(({ bep }) =\u003e bep.gte(10000))\n  .limit(3);\n```\n\nNow that we built a query, we can generate SPARQL out of it:\n```js\nconst sparql = await query.toSparql();\n```\n\nOr execute the SPARQL query against the SPARQL endpoint:\n```js\nconst results = await query.execute();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzazuko%2Fquery-rdf-data-cube","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzazuko%2Fquery-rdf-data-cube","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzazuko%2Fquery-rdf-data-cube/lists"}