diff --git a/docs/N3DataFactory.html b/docs/N3DataFactory.html index 545dd574..a0064b17 100644 --- a/docs/N3DataFactory.html +++ b/docs/N3DataFactory.html @@ -97,7 +97,7 @@

N3DataFactory.js

 import namespaces from './IRIs';
-import { isDefaultGraph } from './N3Util';
+
 const { rdf, xsd } = namespaces;
@@ -116,8 +116,7 @@

N3DataFactory.js

let DEFAULTGRAPH;
 let _blankNodeCounter = 0;
 
-const escapedLiteral = /^"(.*".*)(?="[^"]*$)/;
-const quadId = /^<<("(?:""|[^"])*"[^ ]*|[^ ]+) ("(?:""|[^"])*"[^ ]*|[^ ]+) ("(?:""|[^"])*"[^ ]*|[^ ]+) ?("(?:""|[^"])*"[^ ]*|[^ ]+)?>>$/;
+const escapedLiteral = /^"(.*".*)(?="[^"]*$)/; @@ -724,10 +723,14 @@

DefaultGraph singleton

§

Constructs a term from the given internal string ID

+

The third ‘nested’ parameter of this function is to aid +with recursion over nested terms. It should not be used +by consumers of this library. +See https://github.com/rdfjs/N3.js/pull/311#discussion_r1061042725

-
export function termFromId(id, factory) {
+            
export function termFromId(id, factory, nested) {
   factory = factory || DataFactory;
@@ -815,17 +818,20 @@

Constructs a term f return factory.literal(id.substr(1, endPos - 1), id[endPos + 1] === '@' ? id.substr(endPos + 2) : factory.namedNode(id.substr(endPos + 3))); - case '<': - const components = quadId.exec(id); - return factory.quad( - termFromId(unescapeQuotes(components[1]), factory), - termFromId(unescapeQuotes(components[2]), factory), - termFromId(unescapeQuotes(components[3]), factory), - components[4] && termFromId(unescapeQuotes(components[4]), factory) - ); + case '[': + id = JSON.parse(id); + break; default: - return factory.namedNode(id); + if (!nested || !Array.isArray(id)) { + return factory.namedNode(id); + } } + return factory.quad( + termFromId(id[0], factory, true), + termFromId(id[1], factory, true), + termFromId(id[2], factory, true), + id[3] && termFromId(id[3], factory, true) + ); }

@@ -838,10 +844,14 @@

Constructs a term f §

Constructs an internal string ID from the given term or ID string

+

The third ‘nested’ parameter of this function is to aid +with recursion over nested terms. It should not be used +by consumers of this library. +See https://github.com/rdfjs/N3.js/pull/311#discussion_r1061042725

-
export function termToId(term) {
+            
export function termToId(term, nested) {
   if (typeof term === 'string')
     return term;
   if (term instanceof Term && term.termType !== 'Quad')
@@ -870,31 +880,16 @@ 

Const case 'Literal': return `"${term.value}"${ term.language ? `@${term.language}` : (term.datatype && term.datatype.value !== xsd.string ? `^^${term.datatype.value}` : '')}`; - case 'Quad':

- - - - -
  • -
    - -
    - § -
    -

    To identify RDF* quad components, we escape quotes by doubling them. -This avoids the overhead of backslash parsing of Turtle-like syntaxes.

    - -
    - -
        return `<<${
    -        escapeQuotes(termToId(term.subject))
    -      } ${
    -        escapeQuotes(termToId(term.predicate))
    -      } ${
    -        escapeQuotes(termToId(term.object))
    -      }${
    -        (isDefaultGraph(term.graph)) ? '' : ` ${termToId(term.graph)}`
    -      }>>`;
    +  case 'Quad':
    +    const res = [
    +      termToId(term.subject, true),
    +      termToId(term.predicate, true),
    +      termToId(term.object, true),
    +    ];
    +    if (term.graph && term.graph.termType !== 'DefaultGraph') {
    +      res.push(termToId(term.graph, true));
    +    }
    +    return nested ? res : JSON.stringify(res);
       default: throw new Error(`Unexpected termType: ${term.termType}`);
       }
     }
    @@ -902,11 +897,11 @@

    Const

  • -
  • +
  • - § + §

    Quad constructor

    @@ -924,11 +919,11 @@

    Quad constructor

  • -
  • +
  • - § + §

    The term type of this term

    @@ -957,11 +952,11 @@

    The term type of this term

  • -
  • +
  • - § + §

    Returns a plain object representation of this quad

    @@ -980,11 +975,11 @@

    Returns a plain obje

  • -
  • +
  • - § + §

    Returns whether this object represents the same quad as the other

    @@ -1002,45 +997,47 @@

    Retur

  • -
  • +
  • - § + §

    Escapes the quotes within the given literal

    export function escapeQuotes(id) {
    -  return id.replace(escapedLiteral, (_, quoted) => `"${quoted.replace(/"/g, '""')}`);
    -}
    + return id.replace(escapedLiteral, (_, quoted) => `"${quoted.replace(/"/g, '""')}`); +} + +
  • -
  • +
  • - § + §

    Unescapes the quotes within the given literal

    export function unescapeQuotes(id) {
    -  return id.replace(escapedLiteral, (_, quoted) => `"${quoted.replace(/""/g, '"')}`);
    +  return id.replace(escapedLiteral, (_, quoted) => `"${quoted.replace(/""/g, '"')}`);
     }
  • -
  • +
  • - § + §

    Creates an IRI

    @@ -1053,11 +1050,11 @@

    Creates an IRI

  • -
  • +
  • - § + §

    Creates a blank node

    @@ -1070,11 +1067,11 @@

    Creates a blank node

  • -
  • +
  • - § + §

    Creates a literal

    @@ -1085,11 +1082,11 @@

    Creates a literal

  • -
  • +
  • - § + §

    Create a language-tagged string

    @@ -1101,11 +1098,11 @@

    Creates a literal

  • -
  • +
  • - § + §

    Automatically determine datatype for booleans and numbers

    @@ -1117,11 +1114,11 @@

    Creates a literal

  • -
  • +
  • - § + §

    Convert a boolean

    @@ -1133,11 +1130,11 @@

    Creates a literal

  • -
  • +
  • - § + §

    Convert an integer or double

    @@ -1157,11 +1154,11 @@

    Creates a literal

  • -
  • +
  • - § + §

    Create a datatyped literal

    @@ -1175,11 +1172,11 @@

    Creates a literal

  • -
  • +
  • - § + §

    Creates a variable

    @@ -1192,11 +1189,11 @@

    Creates a variable

  • -
  • +
  • - § + §

    Returns the default graph

    @@ -1209,11 +1206,11 @@

    Returns the default graph

  • -
  • +
  • - § + §

    Creates a quad

    diff --git a/docs/N3Lexer.html b/docs/N3Lexer.html index b8c395a4..fd7f1ca8 100644 --- a/docs/N3Lexer.html +++ b/docs/N3Lexer.html @@ -94,8 +94,8 @@

    N3Lexer.js

    -
    import namespaces from './IRIs';
    -import queueMicrotask from 'queue-microtask';
    +            
    import queueMicrotask from 'queue-microtask';
    +import namespaces from './IRIs';
     
     const { xsd } = namespaces;
    diff --git a/docs/N3Store.html b/docs/N3Store.html index cebfcf44..d1815d25 100644 --- a/docs/N3Store.html +++ b/docs/N3Store.html @@ -94,9 +94,10 @@

    N3Store.js

    -
    import { default as N3DataFactory, termToId, termFromId } from './N3DataFactory';
    -import { Readable } from 'readable-stream';
    -import namespaces from './IRIs';
    +
    import { Readable } from 'readable-stream';
    +import { default as N3DataFactory, termToId, termFromId } from './N3DataFactory';
    +import namespaces from './IRIs';
    +import { isDefaultGraph } from './N3Util';
  • @@ -160,7 +161,6 @@

    Constructor

        this._id = 0;
         this._ids = Object.create(null);
    -    this._ids['><'] = 0; // dummy entry, so the first actual key is non-zero
         this._entities = Object.create(null); // inverse of `_ids`
    @@ -211,7 +211,37 @@

    Constructor

        if (quads)
           this.addQuads(quads);
    -  }
    + } + + _termFromId(id, factory) { + if (id[0] === '.') { + const entities = this._entities; + const terms = id.split('.'); + const q = this._factory.quad( + this._termFromId(entities[terms[1]]), + this._termFromId(entities[terms[2]]), + this._termFromId(entities[terms[3]]), + terms[4] && this._termFromId(entities[terms[4]]) + ); + return q; + } + return termFromId(id, factory); + } + + _termToNumericId(term) { + if (term.termType === 'Quad') { + const s = this._termToNumericId(term.subject), + p = this._termToNumericId(term.predicate), + o = this._termToNumericId(term.object); + let g; + + return s && p && o && (isDefaultGraph(term.graph) || (g = this._termToNumericId(term.graph))) && + this._ids[g ? `.${s}.${p}.${o}.${g}` : `.${s}.${p}.${o}`]; + } + return this._ids[termToId(term)]; + } + + _termToNewNumericId(term) { @@ -222,10 +252,19 @@

    Constructor

    §
    -

    Public properties

    +

    This assumes that no graph term is present - we may wish to error if there is one

    +
        const str = term && term.termType === 'Quad' ?
    +      `.${this._termToNewNumericId(term.subject)}.${this._termToNewNumericId(term.predicate)}.${this._termToNewNumericId(term.object)}${
    +        isDefaultGraph(term.graph) ? '' : `.${this._termToNewNumericId(term.graph)}`
    +      }`
    +      : termToId(term);
    +
    +    return this._ids[str] || (this._ids[this._entities[++this._id] = str] = this._id);
    +  }
    + @@ -235,6 +274,19 @@

    Public properties

    §
    +

    Public properties

    + + + + + + +
  • +
    + +
    + § +

    size returns the number of quads in the store

    @@ -244,11 +296,11 @@

    size returns

  • -
  • +
  • - § + §

    Return the quad count if if was cached

    @@ -261,11 +313,11 @@

    size returns

  • -
  • +
  • - § + §

    Calculate the number of quads by counting to the deepest level

    @@ -284,11 +336,11 @@

    size returns

  • -
  • +
  • - § + §

    Private methods

    @@ -297,11 +349,11 @@

    Private methods

  • -
  • +
  • - § + §

    _addToIndex adds a quad to a three-layered index.

    Returns if the index has changed, if the entry did not already exist.

    @@ -313,11 +365,11 @@

    _addToIndex -
  • +
  • - § + §

    Create layers as necessary

    @@ -329,11 +381,11 @@

    _addToIndex -
  • +
  • - § + §

    Setting the key to any value signals the presence of the quad

    @@ -348,11 +400,11 @@

    _addToIndex -
  • +
  • - § + §

    _removeFromIndex removes a quad from a three-layered index

    @@ -363,11 +415,11 @@

    _remov

  • -
  • +
  • - § + §

    Remove the quad from the index

    @@ -379,11 +431,11 @@

    _remov

  • -
  • +
  • - § + §

    Remove intermediary index layers if they are empty

    @@ -398,11 +450,11 @@

    _remov

  • -
  • +
  • - § + §

    _findInIndex finds a set of quads in a three-layered index.

    The index base is index0 and the keys at each level are key0, key1, and key2. @@ -417,17 +469,17 @@

    _findI
      *_findInIndex(index0, key0, key1, key2, name0, name1, name2, graphId) {
         let tmp, index1, index2;
         const entityKeys = this._entities;
    -    const graph = termFromId(graphId, this._factory);
    +    const graph = this._termFromId(graphId, this._factory);
         const parts = { subject: null, predicate: null, object: null };

  • -
  • +
  • - § + §

    If a key is specified, use only that part of index 0.

    @@ -436,16 +488,16 @@

    _findI
        if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
         for (const value0 in index0) {
           if (index1 = index0[value0]) {
    -        parts[name0] = termFromId(entityKeys[value0], this._factory);
    + parts[name0] = this._termFromId(entityKeys[value0], this._factory);

  • -
  • +
  • - § + §

    If a key is specified, use only that part of index 1.

    @@ -454,16 +506,16 @@

    _findI
            if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
             for (const value1 in index1) {
               if (index2 = index1[value1]) {
    -            parts[name1] = termFromId(entityKeys[value1], this._factory);
    + parts[name1] = this._termFromId(entityKeys[value1], this._factory);

  • -
  • +
  • - § + §

    If a key is specified, use only that part of index 2, if it exists.

    @@ -474,18 +526,18 @@

    _findI

  • -
  • +
  • - § + §

    Create quads for all items found in index 2.

                for (let l = 0; l < values.length; l++) {
    -              parts[name2] = termFromId(entityKeys[values[l]], this._factory);
    +              parts[name2] = this._termFromId(entityKeys[values[l]], this._factory);
                   yield this._factory.quad(parts.subject, parts.predicate, parts.object, graph);
                 }
               }
    @@ -497,11 +549,11 @@ 

    _findI

  • -
  • +
  • - § + §

    _loop executes the callback on all keys of index 0

    @@ -515,11 +567,11 @@

    _loop e

  • -
  • +
  • - § + §

    _loopByKey0 executes the callback on all keys of a certain entry in index 0

    @@ -536,11 +588,11 @@

    +
  • - § + §

    _loopByKey1 executes the callback on given keys of all entries in index 0

    @@ -558,11 +610,11 @@

    +
  • - § + §

    _loopBy2Keys executes the callback on given keys of certain entries in index 2

    @@ -579,11 +631,11 @@

    +
  • - § + §

    _countInIndex counts matching quads in a three-layered index.

    The index base is index0 and the keys at each level are key0, key1, and key2. @@ -597,11 +649,11 @@

    _cou

  • -
  • +
  • - § + §

    If a key is specified, count only that part of index 0

    @@ -614,11 +666,11 @@

    _cou

  • -
  • +
  • - § + §

    If a key is specified, count only that part of index 1

    @@ -631,11 +683,11 @@

    _cou

  • -
  • +
  • - § + §

    If a key is specified, count the quad if it exists

    @@ -646,11 +698,11 @@

    _cou

  • -
  • +
  • - § + §

    Otherwise, count all quads

    @@ -667,11 +719,11 @@

    _cou

  • -
  • +
  • - § + §

    _getGraphs returns an array with the given graph,

    or all graphs if the argument is null or undefined.

    @@ -689,11 +741,11 @@

    _getGraphs -
  • +
  • - § + §

    _uniqueEntities returns a function that accepts an entity ID

    and passes the corresponding entity to callback if it hasn’t occurred before.

    @@ -705,7 +757,7 @@

    _uni return id => { if (!(id in uniqueIds)) { uniqueIds[id] = true; - callback(termFromId(this._entities[id], this._factory)); + callback(this._termFromId(this._entities[id], this._factory)); } }; }

  • @@ -713,11 +765,11 @@

    _uni

  • -
  • +
  • - § + §

    Public methods

    @@ -726,11 +778,11 @@

    Public methods

  • -
  • +
  • - § + §

    add adds the specified quad to the dataset.

    Returns the dataset instance it was called on. @@ -746,11 +798,11 @@

    add adds the sp

  • -
  • +
  • - § + §

    addQuad adds a new quad to the store.

    Returns if the quad index has changed, if the quad did not already exist.

    @@ -762,11 +814,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Shift arguments if a quad object is given instead of components

    @@ -779,29 +831,26 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    -
        subject = termToId(subject);
    -    predicate = termToId(predicate);
    -    object = termToId(object);
    -    graph = termToId(graph);
    +
        graph = termToId(graph);
  • -
  • +
  • - § + §

    Find the graph that will contain the triple

    @@ -812,11 +861,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Create the graph if it doesn’t exist yet

    @@ -828,11 +877,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Freezing a graph helps subsequent add performance, and properties will never be modified anyway

    @@ -845,11 +894,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Since entities can often be long IRIs, we avoid storing them in every index. Instead, we have a separate index that maps entities to numbers, @@ -857,11 +906,9 @@

    addQuad adds a new qu

    -
        const ids = this._ids;
    -    const entities = this._entities;
    -    subject   = ids[subject]   || (ids[entities[++this._id] = subject]   = this._id);
    -    predicate = ids[predicate] || (ids[entities[++this._id] = predicate] = this._id);
    -    object    = ids[object]    || (ids[entities[++this._id] = object]    = this._id);
    +            
        subject   = this._termToNewNumericId(subject);
    +    predicate = this._termToNewNumericId(predicate);
    +    object    = this._termToNewNumericId(object);
     
         const changed = this._addToIndex(graphItem.subjects,   subject,   predicate, object);
         this._addToIndex(graphItem.predicates, predicate, object,    subject);
    @@ -870,11 +917,11 @@ 

    addQuad adds a new qu

  • -
  • +
  • - § + §

    The cached quad count is now invalid

    @@ -887,11 +934,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    addQuads adds multiple quads to the store

    @@ -905,11 +952,11 @@

    addQuads adds mu

  • -
  • +
  • - § + §

    delete removes the specified quad from the dataset.

    Returns the dataset instance it was called on.

    @@ -924,11 +971,11 @@

    delete

  • -
  • +
  • - § + §

    has determines whether a dataset includes a certain quad or quad pattern.

    @@ -943,11 +990,11 @@

    +
  • - § + §

    import adds a stream of quads to the store

    @@ -961,11 +1008,11 @@

    import adds a s

  • -
  • +
  • - § + §

    removeQuad removes a quad from the store if it exists

    @@ -976,11 +1023,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Shift arguments if a quad object is given instead of components

    @@ -993,39 +1040,36 @@

    removeQuad<

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    -
        subject = termToId(subject);
    -    predicate = termToId(predicate);
    -    object = termToId(object);
    -    graph = termToId(graph);
    +
        graph = termToId(graph);
  • -
  • +
  • - § + §

    Find internal identifiers for all components and verify the quad exists.

    -
        const ids = this._ids, graphs = this._graphs;
    +            
        const graphs = this._graphs;
         let graphItem, subjects, predicates;
    -    if (!(subject    = ids[subject]) || !(predicate = ids[predicate]) ||
    -        !(object     = ids[object])  || !(graphItem = graphs[graph])  ||
    +    if (!(subject    = subject && this._termToNumericId(subject)) || !(predicate = predicate && this._termToNumericId(predicate)) ||
    +        !(object     = object && this._termToNumericId(object))  || !(graphItem = graphs[graph])  ||
             !(subjects   = graphItem.subjects[subject]) ||
             !(predicates = subjects[predicate]) ||
             !(object in predicates))
    @@ -1034,11 +1078,11 @@ 

    removeQuad<

  • -
  • +
  • - § + §

    Remove it from all indexes

    @@ -1052,11 +1096,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Remove the graph if it is empty

    @@ -1070,11 +1114,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    removeQuads removes multiple quads from the store

    @@ -1088,11 +1132,11 @@

    removeQuads -
  • +
  • - § + §

    remove removes a stream of quads from the store

    @@ -1106,11 +1150,11 @@

    remove rem

  • -
  • +
  • - § + §

    removeMatches removes all matching quads from the store

    Setting any field to undefined or null indicates a wildcard.

    @@ -1132,11 +1176,11 @@

    removeMat

  • -
  • +
  • - § + §

    deleteGraph removes all triples with the given graph from the store

    @@ -1149,11 +1193,11 @@

    -
  • +
  • - § + §

    getQuads returns an array of quads matching a pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1167,11 +1211,11 @@

    getQuads -
  • +
  • - § + §

    readQuads returns an generator of quads matching a pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1183,40 +1227,37 @@

    readQu

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    -
        subject = subject && termToId(subject);
    -    predicate = predicate && termToId(predicate);
    -    object = object && termToId(object);
    -    graph = graph && termToId(graph);
    +            
        graph = graph && termToId(graph);
     
    -    const graphs = this._getGraphs(graph), ids = this._ids;
    +    const graphs = this._getGraphs(graph);
         let content, subjectId, predicateId, objectId;
  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    -
        if (isString(subject)   && !(subjectId   = ids[subject])   ||
    -        isString(predicate) && !(predicateId = ids[predicate]) ||
    -        isString(object)    && !(objectId    = ids[object]))
    +            
        if (subject   && !(subjectId   = this._termToNumericId(subject))   ||
    +        predicate && !(predicateId = this._termToNumericId(predicate)) ||
    +        object    && !(objectId    = this._termToNumericId(object)))
           return;
     
         for (const graphId in graphs) {
    @@ -1224,11 +1265,11 @@

    readQu

  • -
  • +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1239,11 +1280,11 @@

    readQu

  • -
  • +
  • - § + §

    Choose the optimal index, based on what fields are present

    @@ -1255,11 +1296,11 @@

    readQu

  • -
  • +
  • - § + §

    If subject and object are given, the object index will be the fastest

    @@ -1272,11 +1313,11 @@

    readQu

  • -
  • +
  • - § + §

    If only subject and possibly predicate are given, the subject index will be the fastest

    @@ -1290,11 +1331,11 @@

    readQu

  • -
  • +
  • - § + §

    If only predicate and possibly object are given, the predicate index will be the fastest

    @@ -1307,11 +1348,11 @@

    readQu

  • -
  • +
  • - § + §

    If only object is given, the object index will be the fastest

    @@ -1324,11 +1365,11 @@

    readQu

  • -
  • +
  • - § + §

    If nothing is given, iterate subjects and predicates first

    @@ -1343,11 +1384,11 @@

    readQu

  • -
  • +
  • - § + §

    match returns a new dataset that is comprised of all quads in the current instance matching the given arguments.

    The logic described in Quad Matching is applied for each quad in this dataset to check if it should be included in the output dataset. @@ -1365,11 +1406,11 @@

    +
  • - § + §

    countQuads returns the number of quads matching a pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1381,40 +1422,37 @@

    countQu

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    -
        subject = subject && termToId(subject);
    -    predicate = predicate && termToId(predicate);
    -    object = object && termToId(object);
    -    graph = graph && termToId(graph);
    +            
        graph = graph && termToId(graph);
     
    -    const graphs = this._getGraphs(graph), ids = this._ids;
    +    const graphs = this._getGraphs(graph);
         let count = 0, content, subjectId, predicateId, objectId;
  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    -
        if (isString(subject)   && !(subjectId   = ids[subject])   ||
    -        isString(predicate) && !(predicateId = ids[predicate]) ||
    -        isString(object)    && !(objectId    = ids[object]))
    +            
        if (subject   && !(subjectId   = this._termToNumericId(subject))   ||
    +        predicate && !(predicateId = this._termToNumericId(predicate)) ||
    +        object    && !(objectId    = this._termToNumericId(object)))
           return 0;
     
         for (const graphId in graphs) {
    @@ -1422,11 +1460,11 @@

    countQu

  • -
  • +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1437,11 +1475,11 @@

    countQu

  • -
  • +
  • - § + §

    Choose the optimal index, based on what fields are present

    @@ -1453,11 +1491,11 @@

    countQu

  • -
  • +
  • - § + §

    If subject and object are given, the object index will be the fastest

    @@ -1469,11 +1507,11 @@

    countQu

  • -
  • +
  • - § + §

    If only subject and possibly predicate are given, the subject index will be the fastest

    @@ -1486,11 +1524,11 @@

    countQu

  • -
  • +
  • - § + §

    If only predicate and possibly object are given, the predicate index will be the fastest

    @@ -1503,11 +1541,11 @@

    countQu

  • -
  • +
  • - § + §

    If only object is possibly given, the object index will be the fastest

    @@ -1523,11 +1561,11 @@

    countQu

  • -
  • +
  • - § + §

    forEach executes the callback on all quads.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1544,11 +1582,11 @@

    forEach execute

  • -
  • +
  • - § + §

    every executes the callback on all quads,

    and returns true if it returns truthy for all them. @@ -1568,11 +1606,11 @@

    every executes th

  • -
  • +
  • - § + §

    some executes the callback on all quads,

    and returns true if it returns truthy for any of them. @@ -1590,11 +1628,11 @@

    some executes the

  • -
  • +
  • - § + §

    getSubjects returns all subjects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1610,11 +1648,11 @@

    getSubjec

  • -
  • +
  • - § + §

    forSubjects executes the callback on all subjects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1626,39 +1664,37 @@

    +
  • - § + §

    Convert terms to internal string representation

    -
        predicate = predicate && termToId(predicate);
    -    object = object && termToId(object);
    -    graph = graph && termToId(graph);
    +            
        graph = graph && termToId(graph);
     
    -    const ids = this._ids, graphs = this._getGraphs(graph);
    +    const graphs = this._getGraphs(graph);
         let content, predicateId, objectId;
         callback = this._uniqueEntities(callback);
  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    -
        if (isString(predicate) && !(predicateId = ids[predicate]) ||
    -        isString(object)    && !(objectId    = ids[object]))
    +            
        if (predicate && !(predicateId = this._termToNumericId(predicate)) ||
    +        object    && !(objectId    = this._termToNumericId(object)))
           return;
     
         for (graph in graphs) {
    @@ -1666,11 +1702,11 @@

    +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1681,11 +1717,11 @@

    +
  • - § + §

    Choose optimal index based on which fields are wildcards

    @@ -1697,11 +1733,11 @@

    +
  • - § + §

    If predicate and object are given, the POS index is best.

    @@ -1713,11 +1749,11 @@

    +
  • - § + §

    If only predicate is given, the SPO index is best.

    @@ -1730,11 +1766,11 @@

    +
  • - § + §

    If only object is given, the OSP index is best.

    @@ -1746,11 +1782,11 @@

    +
  • - § + §

    If no params given, iterate all the subjects

    @@ -1764,11 +1800,11 @@

    +
  • - § + §

    getPredicates returns all predicates that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1784,11 +1820,11 @@

    getPr

  • -
  • +
  • - § + §

    forPredicates executes the callback on all predicates that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1800,39 +1836,37 @@

    +
  • - § + §

    Convert terms to internal string representation

    -
        subject = subject && termToId(subject);
    -    object = object && termToId(object);
    -    graph = graph && termToId(graph);
    +            
        graph = graph && termToId(graph);
     
    -    const ids = this._ids, graphs = this._getGraphs(graph);
    +    const graphs = this._getGraphs(graph);
         let content, subjectId, objectId;
         callback = this._uniqueEntities(callback);
  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    -
        if (isString(subject) && !(subjectId = ids[subject]) ||
    -        isString(object)  && !(objectId  = ids[object]))
    +            
        if (subject   && !(subjectId   = this._termToNumericId(subject))   ||
    +        object    && !(objectId    = this._termToNumericId(object)))
           return;
     
         for (graph in graphs) {
    @@ -1840,11 +1874,11 @@

    +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1855,11 +1889,11 @@

    +
  • - § + §

    Choose optimal index based on which fields are wildcards

    @@ -1871,11 +1905,11 @@

    +
  • - § + §

    If subject and object are given, the OSP index is best.

    @@ -1887,11 +1921,11 @@

    +
  • - § + §

    If only subject is given, the SPO index is best.

    @@ -1904,11 +1938,11 @@

    +
  • - § + §

    If only object is given, the POS index is best.

    @@ -1920,11 +1954,11 @@

    +
  • - § + §

    If no params given, iterate all the predicates.

    @@ -1938,11 +1972,11 @@

    +
  • - § + §

    getObjects returns all objects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1958,11 +1992,11 @@

    getObjects<

  • -
  • +
  • - § + §

    forObjects executes the callback on all objects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1974,39 +2008,37 @@

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    -
        subject = subject && termToId(subject);
    -    predicate = predicate && termToId(predicate);
    -    graph = graph && termToId(graph);
    +            
        graph = graph && termToId(graph);
     
    -    const ids = this._ids, graphs = this._getGraphs(graph);
    +    const graphs = this._getGraphs(graph);
         let content, subjectId, predicateId;
         callback = this._uniqueEntities(callback);
  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    -
        if (isString(subject)   && !(subjectId   = ids[subject]) ||
    -        isString(predicate) && !(predicateId = ids[predicate]))
    +            
        if (subject   && !(subjectId   = this._termToNumericId(subject))   ||
    +        predicate && !(predicateId = this._termToNumericId(predicate)))
           return;
     
         for (graph in graphs) {
    @@ -2014,11 +2046,11 @@

  • -
  • +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -2029,11 +2061,11 @@

  • -
  • +
  • - § + §

    Choose optimal index based on which fields are wildcards

    @@ -2045,11 +2077,11 @@

  • -
  • +
  • - § + §

    If subject and predicate are given, the SPO index is best.

    @@ -2061,11 +2093,11 @@

  • -
  • +
  • - § + §

    If only subject is given, the OSP index is best.

    @@ -2078,11 +2110,11 @@

  • -
  • +
  • - § + §

    If only predicate is given, the POS index is best.

    @@ -2094,11 +2126,11 @@

  • -
  • +
  • - § + §

    If no params given, iterate all the objects.

    @@ -2112,11 +2144,11 @@

  • -
  • +
  • - § + §

    getGraphs returns all graphs that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -2132,11 +2164,11 @@

    getGraphs -
  • +
  • - § + §

    forGraphs executes the callback on all graphs that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -2155,11 +2187,11 @@

    -
  • +
  • - § + §

    createBlankNode creates a new blank node, returning its name

    @@ -2171,11 +2203,11 @@

    creat

  • -
  • +
  • - § + §

    Generate a name based on the suggested name

    @@ -2190,11 +2222,11 @@

    creat

  • -
  • +
  • - § + §

    Generate a generic blank node name

    @@ -2208,11 +2240,11 @@

    creat

  • -
  • +
  • - § + §

    Add the blank node to the entities, avoiding the generation of duplicates

    @@ -2226,11 +2258,11 @@

    creat

  • -
  • +
  • - § + §

    extractLists finds and removes all list triples

    and returns the items per list.

    @@ -2245,11 +2277,11 @@

    extractLists -
  • +
  • - § + §

    Traverse each list from its tail

    @@ -2267,11 +2299,11 @@

    extractLists -
  • +
  • - § + §

    Traverse the list from tail to end

    @@ -2286,11 +2318,11 @@

    extractLists -
  • +
  • - § + §

    Find the first and rest of this list node

    @@ -2306,11 +2338,11 @@

    extractLists -
  • +
  • - § + §

    one rdf:first

    @@ -2326,11 +2358,11 @@

    extractLists -
  • +
  • - § + §

    one rdf:rest

    @@ -2346,11 +2378,11 @@

    extractLists -
  • +
  • - § + §

    alien triple

    @@ -2367,11 +2399,11 @@

    extractLists -
  • +
  • - § + §

    { :s :p (1 2) } arrives here with no head { (1 2) :p :o } arrives here with head set to the list.

    @@ -2386,11 +2418,11 @@

    extractLists -
  • +
  • - § + §

    one rdf:rest

    @@ -2411,11 +2443,11 @@

    extractLists -
  • +
  • - § + §

    Store the list item and continue with parent

    @@ -2431,11 +2463,11 @@

    extractLists -
  • +
  • - § + §

    Don’t remove any quads if the list is malformed

    @@ -2447,11 +2479,11 @@

    extractLists -
  • +
  • - § + §

    Store the list under the value of its head

    @@ -2464,11 +2496,11 @@

    extractLists -
  • +
  • - § + §

    Remove list quads if requested

    @@ -2482,11 +2514,11 @@

    extractLists -
  • +
  • - § + §

    Store is an iterable.

    Can be used where iterables are expected: for…of loops, array spread operator, @@ -2502,11 +2534,11 @@

    Store is an iterable.

  • -
  • +
  • - § + §

    Determines whether the argument is a string

    diff --git a/docs/N3StreamParser.html b/docs/N3StreamParser.html index 7adbd3b0..4ec8c54a 100644 --- a/docs/N3StreamParser.html +++ b/docs/N3StreamParser.html @@ -94,8 +94,8 @@

    N3StreamParser.js

    -
    import N3Parser from './N3Parser';
    -import { Transform } from 'readable-stream';
    +
    import { Transform } from 'readable-stream';
    +import N3Parser from './N3Parser';
  • diff --git a/docs/N3Writer.html b/docs/N3Writer.html index cada86c5..5b410701 100644 --- a/docs/N3Writer.html +++ b/docs/N3Writer.html @@ -151,8 +151,8 @@

    Placeholder

    -
      equals() {
    -    return false;
    +            
      equals(other) {
    +    return other === this;
       }
     }
    @@ -1031,12 +1031,12 @@

    addPrefixes
        if (hasPrefixes) {
    -      let IRIlist = '', prefixList = '';
    +      let IRIlist = '', prefixList = '';
           for (const prefixIRI in this._prefixIRIs) {
    -        IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI;
    +        IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI;
             prefixList += (prefixList ? '|' : '') + this._prefixIRIs[prefixIRI];
           }
    -      IRIlist = escapeRegex(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
    +      IRIlist = escapeRegex(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
           this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` +
                                          `^(${IRIlist})([_a-zA-Z][\\-_a-zA-Z0-9]*)$`);
         }