rdf-utils-dataset
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/rdf-utils-dataset package

2.0.0 • Public • Published

rdf-utils-dataset

build status npm version

Utils for RDFJS Datasets.

Functions

resource(dataset, subject)

Returns a subgraph of dataset. It's created by traversing dataset starting at subject. Traversing stops at quads with a NamedNode subject.

Example

Say you have the following triples in a dataset:

@prefix ex:<http://example.org/>.

ex:Alice
    ex:address [ ex:street "Wonderland Street" ;
                 ex:number "22" ] ;
    ex:name "Alice" .

ex:Bob
    ex:name "Bob" .

Then, the resource function

import { resource } from 'rdf-utils-dataset'

const dataset = // Load the dataset somehow
const result = resource(dataset, rdf.namedNode('http://example.org/Alice'))
console.log(result.toCanonical())

yields:

<http://example.org/Alice> <http://example.org/address> _:c14n0 .
<http://example.org/Alice> <http://example.org/name> "Alice" .
_:c14n0 <http://example.org/number> "22" .
_:c14n0 <http://example.org/street> "WonderLand Street" .

(Note that the description follows blank nodes)

resourcesToGraph (dataset, options)

Searches for all NamedNode subjects in dataset and creates subgraphs using resource(). The graph of the quads are set to the start subject.

Example

Say you have the following triples in a dataset:

@prefix ex:<http://example.org/>.

ex:Alice
    ex:address [ ex:street "Wonderland Street" ;
                 ex:number "22" ] ;
    ex:name "Alice" .

ex:Bob
    ex:name "Bob" .

Then, the resourcesToGraph function

import { resourcesToGraph } from 'rdf-utils-dataset'

const dataset = // Load the dataset somehow
const result = resourcesToGraph(dataset)
console.log(result.toCanonical())

yields:

<http://example.org/Alice> <http://example.org/address> _:c14n0 <http://example.org/Alice> .
<http://example.org/Alice> <http://example.org/name> "Alice" <http://example.org/Alice> .
<http://example.org/Bob> <http://example.org/name> "Bob" <http://example.org/Bob> .
_:c14n0 <http://example.org/number> "22" <http://example.org/Alice> .
_:c14n0 <http://example.org/street> "WonderLand Street" <http://example.org/Alice> .

Loading the functions

Each util function can be loaded as property from the main module or by loading only the file with the same name. Loading the individual files can decrease the file size after packaging the JavaScript code for the browser.

Usage

Loading the function from the main module:

import { resource } from 'rdf-utils-dataset'

Loading the function from the file with the function name:

import resource from 'rdf-utils-dataset/resource.js'

Package Sidebar

Install

npm i rdf-utils-dataset

Weekly Downloads

921

Version

2.0.0

License

MIT

Unpacked Size

5.65 kB

Total Files

5

Last publish

Collaborators

  • bergos