-
Notifications
You must be signed in to change notification settings - Fork 12
Dataset spec
During a discussion of the Stream .match()
method being asynchronous, the question came up about what to do with synchronous querying use cases (such as filter/matching using an in-memory store). @bergos suggested that this is what Datasets were intended for, and that we should create a Wiki page to document a potential spec and gauge community interest.
As currently implemented in rdf-ext's SimpleDataset, which is itself based on on the v0.3.x Graph API.
Important: Unlike Arrays, RDF Datasets have the following properties:
- they are un-ordered (and quads within them cannot be accessed using
[]
notation) - like Sets, they are unique (duplicate identical quads are not allowed)
-
number .length
Number of quads in the dataset. (Similar toArray.length
)
-
static Promise<Dataset> import (Function factory, Stream stream)
creates a new Dataset and returns the result of callingdataset.import(stream)
(see below)
These methods have the same semantics as corresponding methods on an Array
instance.
-
Boolean every (Function callback)
tests whether all quads in the dataset pass the test implemented by the provided function -
Dataset filter (Function callback)
returns a new Dataset with all quads that pass the test implemented by the provided function -
undefined forEach (Function callback)
executes a provided function once per each quad in the dataset -
Boolean includes (Quad quad)
determines whether a dataset includes a certain quad, returningtrue
orfalse
as appropriate -
Dataset map (Function callback)
returns a new dataset with the results of calling a provided function on every quad in this dataset -
Boolean some (Function callback)
tests whether some quad in the dataset passes the test implemented by the provided function
These methods deal with (un-ordered) set operations such as set union, intersection, etc.
-
Dataset add (Quad quad)
adds a given quad to the dataset, returns itself (this dataset) -
Dataset addAll (Array<Quad>|Dataset quads)
adds all given quads to the dataset, returns itself (this dataset) -
Dataset difference (Dataset other)
returns a set difference of this dataset and the given one -
Dataset intersection (Dataset other)
returns a set intersection of this dataset and the given one -
Dataset merge (Array<Quad>|Dataset other)
returns a set union operation, a new dataset comprised of this dataset merged with all of the quads in the given dataset. (Similar semantics toArray.concat()
, except that Dataset is of course un-ordered.)
-
Dataset clone ()
returns a copy of this dataset (and all its quads) -
Boolean equals (Dataset other)
returnstrue
if this dataset contains the same quads as the given one -
Promise<Dataset> import (Stream stream)
-
Dataset match (Term subject, Term predicate, Term object, Term graph)
synchronous method, returns a Dataset containing all the quads that match the given pattern. See also the RDFJS spec'sStream.match()
method. -
Dataset remove(Quad quad)
removes the given quad from this dataset, returns itself (this dataset) -
Dataset removeMatches (Term subject, Term predicate, Term object, Term graph)
removes all quads that match the given pattern from this dataset, returns itself (this dataset) -
Array toArray ()
returns an array containing all the quads in this dataset -
String toCanonical ()
returns the results of anormalize()
operation on the quads of this dataset as canonical N-Triples string -
Stream toStream ()
returns the stream containing all of the quads in this dataset -
string toString ()
- Is it worth doing a
.delete(quad)
method, a Set-compatible alias to.remove()
? - Is it worth doing a
.has(quad)
method, a Set-compatible alias to.inclues()
?