How to use @rdfjs/data-model - 10 common examples

To help you get started, we’ve selected a few @rdfjs/data-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github solid / query-ldflex / src / ActivityHandler.js View on Github external
user = await root.user;
      }
      catch (error) {
        if (self.requireUser)
          throw error;
        return;
      }

      // Determine the storage location
      const storage = await root.user.pim$storage;
      const document = new URL(self.activitiesPath, storage || user).href;

      // Obtain results for every activity on the path
      const results = [];
      const actor = namedNode(user);
      type = namedNode(type);
      for await (const object of path) {
        if (object.termType === 'NamedNode') {
          const activity = { actor, type, object };
          for await (const result of self.createResults(activity, document, queryEngine))
            results.push(result);
        }
      }

      // Process all results and return paths starting from the returned terms
      for (const term of await self.processResults(results, document, queryEngine))
        yield root[term.value];
    });
  }
github comunica / comunica / packages / actor-rdf-parse-jsonld / lib / ActorRdfParseJsonLd.ts View on Github external
public static mapTerm(term: any): RDF.Term {
    switch (term.termType) {
    case 'NamedNode':
      return namedNode(term.value);
    case 'BlankNode':
      return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
    case 'Literal':
      return literal(term.value, term.language || term.datatype);
    /*case 'Variable':
      return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
    case 'DefaultGraph':
      return defaultGraph();
    }
  }
github comunica / comunica / packages / actor-rdf-resolve-quad-pattern-sparql-json / lib / ActorRdfResolveQuadPatternSparqlJson.ts View on Github external
if (blankMap[name]) {
          name = blankMap[name];
        } else {
          if (variableNames.indexOf(name) >= 0) {
            // increase index added to name until we find one that is available (2 loops at most)
            let idx = 0;
            while (variableNames.indexOf(name + idx) >= 0) {
              ++idx;
            }
            name = name + idx;
          }
          blankMap[term.value] = name;
          variableNames.push(name);
        }
        changed = true;
        return variable(name);
      } else {
        return term;
      }
    });
github comunica / comunica / packages / actor-rdf-parse-jsonld / lib / ActorRdfParseJsonLd.ts View on Github external
public static mapTerm(term: any): RDF.Term {
    switch (term.termType) {
    case 'NamedNode':
      return namedNode(term.value);
    case 'BlankNode':
      return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
    case 'Literal':
      return literal(term.value, term.language || term.datatype);
    /*case 'Variable':
      return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
    case 'DefaultGraph':
      return defaultGraph();
    }
  }
github comunica / comunica / packages / actor-rdf-parse-jsonld / lib / ActorRdfParseJsonLd.ts View on Github external
public static mapTerm(term: any): RDF.Term {
    switch (term.termType) {
    case 'NamedNode':
      return namedNode(term.value);
    case 'BlankNode':
      return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
    case 'Literal':
      return literal(term.value, term.language || term.datatype);
    /*case 'Variable':
      return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
    case 'DefaultGraph':
      return defaultGraph();
    }
  }
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.match.js View on Github external
factory.quad(
          factory.namedNode('http://ex.com/s'),
          factory.namedNode('http://ex.com/p'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s'),
          factory.namedNode('http://ex.com/p2'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        )
      ];
      const source = utils.createArrayStream(quads);
      await utils.waitForEvent(store.import(source), 'end', true);
      const predicate = factory.namedNode('http://ex.com/p2');
      const matchedQuads = await utils.streamToArray(rs.match(null, predicate));
      stripTermSerializedValue(matchedQuads);
      should(matchedQuads).have.length(1);
      should(matchedQuads[0]).deepEqual(quads[1]);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.match.js View on Github external
it('should match quads by the default graph (implicit)',  async function () {
      const store = this.store;
      const rs = store;
      const quads = [
        factory.quad(
          factory.namedNode('http://ex.com/s0'),
          factory.namedNode('http://ex.com/p0'),
          factory.literal('o0', 'en-gb')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s1'),
          factory.namedNode('http://ex.com/p1'),
          factory.literal('o1', 'en-gb'),
          factory.namedNode('http://ex.com/g1')
        )
      ];
      const source = utils.createArrayStream(quads);
      await utils.waitForEvent(store.import(source), 'end', true);
      const readStream = rs.match(null, null, null, factory.defaultGraph());
      const matchedQuads = await utils.streamToArray(readStream);
      stripTermSerializedValue(matchedQuads);
      should(matchedQuads).have.length(1);
      should(matchedQuads[0].graph).deepEqual(quads[0].graph);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.match.js View on Github external
factory.quad(
          factory.namedNode('http://ex.com/s'),
          factory.namedNode('http://ex.com/p'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s2'),
          factory.namedNode('http://ex.com/p'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        )
      ];
      const source = utils.createArrayStream(quads);
      await utils.waitForEvent(store.import(source), 'end', true);
      const subject = factory.namedNode('http://ex.com/s2');
      const matchedQuads = await utils.streamToArray(rs.match(subject));
      stripTermSerializedValue(matchedQuads);
      should(matchedQuads).have.length(1);
      should(matchedQuads[0]).deepEqual(quads[1]);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.match.js View on Github external
it('should match quads by predicate',  async function () {
      const store = this.store;
      const rs = store;
      const quads = [
        factory.quad(
          factory.namedNode('http://ex.com/s'),
          factory.namedNode('http://ex.com/p'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s'),
          factory.namedNode('http://ex.com/p2'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        )
      ];
      const source = utils.createArrayStream(quads);
      await utils.waitForEvent(store.import(source), 'end', true);
      const predicate = factory.namedNode('http://ex.com/p2');
      const matchedQuads = await utils.streamToArray(rs.match(null, predicate));
      stripTermSerializedValue(matchedQuads);
      should(matchedQuads).have.length(1);
      should(matchedQuads[0]).deepEqual(quads[1]);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.match.js View on Github external
it('should match quads by subject', async function () {
      const store = this.store;
      const rs = store;
      const quads = [
        factory.quad(
          factory.namedNode('http://ex.com/s'),
          factory.namedNode('http://ex.com/p'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s2'),
          factory.namedNode('http://ex.com/p'),
          factory.literal('o', 'en-gb'),
          factory.namedNode('http://ex.com/g')
        )
      ];
      const source = utils.createArrayStream(quads);
      await utils.waitForEvent(store.import(source), 'end', true);
      const subject = factory.namedNode('http://ex.com/s2');
      const matchedQuads = await utils.streamToArray(rs.match(subject));
      stripTermSerializedValue(matchedQuads);
      should(matchedQuads).have.length(1);
      should(matchedQuads[0]).deepEqual(quads[1]);
    });

@rdfjs/data-model

A basic implementation of the RDF/JS Data Model

MIT
Latest version published 11 months ago

Package Health Score

65 / 100
Full package analysis