How to use the n3.DataFactory.quad function in n3

To help you get started, we’ve selected a few n3 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 inrupt / wac-ldp / test-comunica.ts View on Github external
async function test () {
  // This can be any RDFJS source
  // In this example, we wrap an N3Store
  const store = new Store()
  store.addQuad(DataFactory.quad(
    DataFactory.namedNode('a'), DataFactory.namedNode('b'), DataFactory.namedNode('http://dbpedia.org/resource/Belgium')))
  store.addQuad(DataFactory.quad(
    DataFactory.namedNode('a'), DataFactory.namedNode('b'), DataFactory.namedNode('http://dbpedia.org/resource/Ghent')))

  // Create our engine, and query it.
  // If you intend to query multiple times, be sure to cache your engine for optimal performance.
  const myEngine = newEngine()
  const result: any = await myEngine.query('SELECT * { ?s ?p . ?s ?p ?o } LIMIT 100',
    { sources: [ { type: 'rdfjsSource', value: store } ] })
  result.bindingsStream.on('data', (data: any) => {
    console.log(data)
  })
}
void test()
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.import.js View on Github external
it('should import a single quad correctly', async function () {
      const store = this.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')
        )
      ];
      const source = utils.createArrayStream(quads);
      await utils.waitForEvent(store.import(source), 'end', true);
      const matchedQuads = await utils.streamToArray(store.match());
      should(matchedQuads).have.length(1);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.sparql.js View on Github external
dataFactory.literal('8', `${XSD}integer`),
          dataFactory.namedNode('http://ex.com/g0')
        ),
        dataFactory.quad(
          dataFactory.namedNode('http://ex.com/s0'),
          dataFactory.namedNode('http://ex.com/p0'),
          dataFactory.literal('1', `${XSD}integer`),
          dataFactory.namedNode('http://ex.com/g0')
        ),
        dataFactory.quad(
          dataFactory.namedNode('http://ex.com/s0'),
          dataFactory.namedNode('http://ex.com/p1'),
          dataFactory.literal('3', `${XSD}integer`),
          dataFactory.namedNode('http://ex.com/g0')
        ),
        dataFactory.quad(
          dataFactory.namedNode('http://ex.com/s0'),
          dataFactory.namedNode('http://ex.com/p2'),
          dataFactory.literal('5', `${XSD}integer`),
          dataFactory.namedNode('http://ex.com/g0')
        )
      ];
      await store.put(quads);
      const query = 'SELECT * WHERE { GRAPH ?g { ?s ?p ?o. FILTER (?o >= 4) } }';
      const bindings = await utils.streamToArray(await store.sparql(query));
      should(bindings).have.length(2);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.removematches.js View on Github external
it('should remove matching quads correctly', async function () {
      const store = this.store;
      const importQuads = [
        factory.quad(
          factory.namedNode('http://ex.com/s0'),
          factory.namedNode('http://ex.com/p0'),
          factory.literal('o0', 'en-gb'),
          factory.namedNode('http://ex.com/g0')
        ),
        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')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s2'),
          factory.namedNode('http://ex.com/p2'),
          factory.literal('o2', 'en-gb'),
          factory.namedNode('http://ex.com/g1')
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.sparql.js View on Github external
it('Shoud return the correct number of entries (LIMIT)', async function () {
      const ctx = this;
      const store = ctx.store;
      const quads = [];
      for (let i = 0; i < 200; i++) {
        quads.push(dataFactory.quad(
          dataFactory.namedNode('http://ex.com/s' + i),
          dataFactory.namedNode('http://ex.com/p' + i),
          dataFactory.namedNode('http://ex.com/o' + i),
          dataFactory.namedNode('http://ex.com/g' + i)
        ));
      }
      await store.put(quads);
      const query = 'SELECT *  WHERE { GRAPH ?g { ?s ?p ?o } } LIMIT 132';
      const bindings = await utils.streamToArray(await ctx.store.sparql(query));
      should(bindings).have.length(132);
    });
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.del.js View on Github external
it('Should delete matching quads correctly (callback).', async function () {
      const store = this.store;
      const quads = [
        factory.quad(
          factory.namedNode('http://ex.com/s0'),
          factory.namedNode('http://ex.com/p0'),
          factory.literal('o0', 'en-gb'),
          factory.namedNode('http://ex.com/g0')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s0'),
          factory.namedNode('http://ex.com/p1'),
          factory.literal('o1', 'en-gb'),
          factory.namedNode('http://ex.com/g1')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s2'),
          factory.namedNode('http://ex.com/p1'),
          factory.literal('o2', 'en-gb'),
          factory.namedNode('http://ex.com/g1')
github beautifulinteractions / node-quadstore / test / rdfstore.prototype.remove.js View on Github external
),
        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')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s2'),
          factory.namedNode('http://ex.com/p2'),
          factory.literal('o2', 'en-gb'),
          factory.namedNode('http://ex.com/g3')
        )
      ];
      const removeQuads = [
        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')
        ),
        factory.quad(
          factory.namedNode('http://ex.com/s2'),
          factory.namedNode('http://ex.com/p2'),
          factory.literal('o2', 'en-gb'),
          factory.namedNode('http://ex.com/g3')
        )
      ];
      const importStream = utils.createArrayStream(importQuads);
      const removeStream = utils.createArrayStream(removeQuads);
      await utils.waitForEvent(store.import(importStream), 'end', true);
      await utils.waitForEvent(store.remove(removeStream), 'end', true);