Home

Awesome

@rdfjs/traverser

build status

npm version

This package provides a generic traverser for RDF/JS Datasets.

Usage

The main export of the package is the Traverser class. It can be imported like this:

import Traverser from '@rdfjs/traverser'

The package also provides a factory that can be used with @rdfjs/environment:

import Environment from '@rdfjs/environment'
import TraverserFactory from '@rdfjs/traverser/Factory.js'

const env = new Environment([DataFactory, DatasetFactory, TraverserFactory])

Traverser(filter, { backward, factory, forward })

Creates a new Traverser instance. A Traverser contains only the rules for traversing. The dataset and the starting point must be given to the methods.

forEach ({ term, dataset }, callback)

Calls the given callback function for each quad matching the rules of the Traverser, starting from the given term and dataset. The callback function is called like this: callback({ dataset, level, quad }).

match ({ term, dataset })

Returns a RDF/JS Dataset that contains all quads matching the rules of the Traverser, starting from the given term and dataset.

reduce ({ term, dataset }, callback, initialValue)

Calls the given callback function for each quad matching the rules of the Traverser, starting from the given term and dataset. The callback function is called like this: callback({ dataset, level, quad }, result).

Factory

The constructor is called by the @rdfjs/environment. The environment must support the RDF/JS DatasetFactory interface.

traverser(filter, { backward = false, forward = true } = {})

Creates a new Traverser instance and returns it.

For more details, see the Traverser constructor section.