How to use the n3.StreamWriter 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 beautifulinteractions / node-quadstore / lib / http / controllers / ldf.js View on Github external
const terms = {
        subject: subject ? rdfStore._exportTerm(subject) : null,
        predicate: predicate ? rdfStore._exportTerm(predicate) : null,
        object: object ? rdfStore._exportTerm(object) : null,
        graph: graph ? rdfStore._exportTerm(graph) : null,
      };
      debug('terms: %j', terms);
      const approximateCount = await rdfStore.getApproximateCount(terms);
      let responseContentType;
      try {
        responseContentType = await ldfController._negotiate(res);
      } catch (negotiationErr) {
        res.status(400).end(negotiationErr.message);
        return;
      }
      const writerStream = new n3.StreamWriter({
        format: responseContentType
      });
      const quadStream = rdfStore.getStream(terms, { limit, offset });
      const counterStream = createCounterStream();
      quadStream.pipe(counterStream)
        .pipe(writerStream, { end: false })
        // .pipe(createDumperStream())
        //   .on('dump', (dump) => { console.log('DUMP', dump);})
        .pipe(res);
      await utils.resolveOnEvent(counterStream, 'finish', false);
      const quadCount = counterStream.count;
      const estimatedTotalCount = (quadCount && approximateCount < offset + quadCount)
        ? offset + (quadCount < limit ? quadCount : 2 * quadCount)
        : approximateCount;
      debug(`quadCount: ${quadCount}, approximateTotalCount: ${approximateCount}, estimatedTotalCount: ${estimatedTotalCount}`);
      const thisUrl = new YURL(routeUrl).query(false).query(new YURL(`http://example.com/${req.originalUrl}`).parts.query).format();
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_doc_from_triple_stream_to_rdf_stream() {
    const streamParser: N3.N3StreamParser = new N3.StreamParser();
    const inputStream = fs.createReadStream('cartoons.ttl');
    const streamWriter: N3.N3StreamWriter = new N3.StreamWriter({ prefixes: { c: N3.DataFactory.namedNode('http://example.org/cartoons#') } });
    inputStream.pipe(streamParser);
    streamParser.pipe(streamWriter);
    streamWriter.pipe(process.stdout);
}
github comunica / comunica / packages / actor-rdf-serialize-n3 / lib / ActorRdfSerializeN3.ts View on Github external
public async runHandle(action: IActionRdfSerialize, mediaType: string, context: ActionContext)
    : Promise {
    const n3Triples = new Readable({ objectMode: true });
    n3Triples._read = () => {
      return;
    };

    action.quads.on('error', (e) => data.emit('error', e));
    action.quads.on('data', (quad: RDF.Quad) => n3Triples.push(quad));
    action.quads.on('end', () => n3Triples.emit('end'));
    const data = n3Triples.pipe(new StreamWriter({ format: mediaType }));

    return { data,
      triples: mediaType === 'text/turtle'
      || mediaType === 'application/n-triples'
      || mediaType === 'text/n3' };
  }
github levelgraph / levelgraph-n3 / index.js View on Github external
graphdb.searchStream = function(conditions, options) {
    var stream;

    if (options && options.n3) {
      options.materialized = options.n3;
    }

    stream = db.searchStream(conditions, options);

    if (options && options.n3) {
      stream = stream.pipe(new n3.StreamWriter());
    }

    return stream;
  };
github beautifulinteractions / node-quadstore / lib / http / controllers / match.js View on Github external
return;
      }
      const terms = {
        subject: subject ? rdfStore._exportTerm(subject) : null,
        predicate: predicate ? rdfStore._exportTerm(predicate) : null,
        object: object ? rdfStore._exportTerm(object) : null,
        graph: graph ? rdfStore._exportTerm(graph) : null,
      };
      let responseContentType;
      try {
        responseContentType = await matchController._negotiate(res);
      } catch (negotiationErr) {
        res.status(400).end(negotiationErr.message);
        return;
      }
      const writerStream = new n3.StreamWriter({
        format: responseContentType,
        prefixes: _.extend({}, prefixes)
      });
      const quadStream = rdfStore.getStream(terms, {limit, offset});
      quadStream.pipe(writerStream).pipe(res);
    });
  }