graphy.js

A collection of RDF libraries for JavaScript

View the Project on GitHub

« API / Fast Dataset

@graphy/memory.dataset.fast

Primer

Contents


Memory and Performance

This data structure is best suited for storing quads in memory when the objective is to perform set operations quickly (e.g., union, difference, intersection, etc.) on relatively small datasets (still much better storage density than the alternatives – see memory usage comparison in the performance document).

Future releases of graphy plan to include other data structures, such as DenseDataset, FastDatacache, and DenseDatacache, for meeting the various trade-offs between storage density and insertion/deletion time. In this implementation, certain set operations may reuse pointers to existing object trees in order to save the time it takes to copy subtrees and in order to reduce the overall memory footprint. This has no effect on user functionality since object reuse is handled internally and all methods ensure that stale objects are released to GC.


Construction

The require’d return value is a wrapper function that constructs an instance of Dataset. The new keyword is optional.

dataset([config: DatasetConfig])

Usage examples

The following example is shown for usage in Node.js, however the same async/await mechanisms can be used in the browser with polyfills for piping fetch and awaiting stream events.

Read from a Turtle file in Node.js:

const fs = require('fs');
const { once } = require('events');
const ttl_read = require('@graphy/content.ttl.read');
const dataset = require('@graphy/memory.dataset.fast');

// load 'input-a.ttl' into a new Dataset
let y_input_a = dataset();

fs.createReadStream('input-a.ttl')
    .pipe(ttl_read())
    .pipe(y_input_a);


// load 'input-b.ttl' into a new Dataset
let y_input_b = dataset();

fs.createReadStream('input-b.ttl')
    .pipe(ttl_read())
    .pipe(y_input_b);


// wait for both datasets to finish loading using async/await
(async() => {
    // Dataset extends Node.js' Duplex, so simply listen for the 'finish' event
    // to be notified once the dataset has finished loading
    await Promise.all([
        once(y_input_a, 'finish'),
        once(y_input_b, 'finish'),
    ]);

    // compute the union of the two datasets
    let y_union = y_input_a.union(y_input_b);

    // do something with union...
})();

Properties

.size


Methods

* [Symbol.iterator]() per @RDFJS/DatasetCore

.canonicalize()

.add(quad: AnyQuad) implements @RDFJS/DatasetCore.add

.addAll(quads: @RDFJS/Dataset | sequence<AnyQuad>) implements @RDFJS/Dataset.addAll

.addQuads(quads: Iterable<Quad>)

.delete(quad: AnyQuad) implements @RDFJS/DatasetCore.delete

.deleteQuads(quads: list<Quad>)

.clear()

.has(quad: AnyQuad) implements @RDFJS/DatasetCore.has

.equals(other: FastDataset) implements @RDFJS/Dataset.equals

.contains(other: FastDataset)

.disjoint(other: FastDataset)

.union(other: FastDataset) implements @RDFJS/Dataset.union

.intersection(other: FastDataset) implements @RDFJS/Dataset.intersection

.minus(other: FastDataset)

.difference(other: FastDataset) implements @RDFJS/Dataset.difference

.match([subject: null | AnyTerm[, predicate: null | AnyTerm[, object: null | AnyTerm[, graph: null | AnyTerm]]]]) implements @RDFJS/DatasetCore.match