How to use the n3.Writer 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 LinkedDataFragments / Server.js / lib / writers / TurtleWriter.js View on Github external
TurtleWriter.prototype._createWriter = function (destination, settings) {
  var writer = new N3.Writer({ format: this._format, prefixes: settings.prefixes });
  return {
    // Adds the data triple to the output
    data: function (s, p, o) {
      writer.addTriple(s, p, o);
    },
    // Adds the metadata triple to the output
    meta: function (s, p, o) {
      if (s && p && o && !N3.Util.isLiteral(s))
        writer.addTriple(s, p, o);
    },
    // Ends the output and flushes the stream
    end: function () {
      writer.end(function (error, output) { destination.end(output); });
    },
  };
};
github dice-group / dice-website / scripts / papers-to-ttl / index.js View on Github external
papers.forEach(paper => {
    // create new turtle writer for paper
    const writer = new Writer(writerConfig);

    // generate a basename for file and URL
    const baseName = _.upperFirst(_.camelCase(paper.label));
    const baseFileName = paper.id.replace(
      /https:\/\/www.bibsonomy.org\/bibtex\/(.+?)\/(.+)/,
      '$1_$2'
    );

    // generate URL for paper
    const paperUrl = `${prefixes.dicepapers}${baseName}`;

    // create writer functions
    const writeUrl = createUrlWriter(writer, paperUrl);
    const writeLiteral = createLiteralWriter(writer, paperUrl);

    // write rdf:type info
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_doc_from_triples_to_string() {
    const writer: N3.N3Writer = new N3.Writer({ prefixes: { c: 'http://example.org/cartoons#' } });
    writer.addQuad(N3.DataFactory.quad(
        N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
        N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
        N3.DataFactory.namedNode('http://example.org/cartoons#Cat')
    ));
    writer.addQuad(N3.DataFactory.quad(
      N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
      N3.DataFactory.namedNode('http://example.org/cartoons#name'),
      N3.DataFactory.literal('Tom'),
    ));
    writer.end((error, result: string) => { console.log(result); });

    const writer1: N3.N3Writer = N3.Writer({ format: 'N-Triples' });
    const writer2: N3.N3Writer = N3.Writer({ format: 'application/trig' });
}
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_serialize() {
    const writer: N3.N3Writer = new N3.Writer(
        {
            format: "ttl",
            prefixes: {
                foaf: "http://xmlns.com/foaf/0.1",
                freebase: N3.DataFactory.namedNode("http://rdf.freebase.com/ns/"),
                g: "http://base.google.com/ns/1.0"
            }
        });
    writer.addQuad(N3.DataFactory.quad(
      N3.DataFactory.namedNode("subject-name"),
      N3.DataFactory.namedNode("predicate-name"),
      N3.DataFactory.literal(12)
    ));

    writer.end((error, result) => {
        console.log(`result ${result}`);
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_doc_from_triples_to_string() {
    const writer: N3.N3Writer = new N3.Writer({ prefixes: { c: 'http://example.org/cartoons#' } });
    writer.addQuad(N3.DataFactory.quad(
        N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
        N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
        N3.DataFactory.namedNode('http://example.org/cartoons#Cat')
    ));
    writer.addQuad(N3.DataFactory.quad(
      N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
      N3.DataFactory.namedNode('http://example.org/cartoons#name'),
      N3.DataFactory.literal('Tom'),
    ));
    writer.end((error, result: string) => { console.log(result); });

    const writer1: N3.N3Writer = N3.Writer({ format: 'N-Triples' });
    const writer2: N3.N3Writer = N3.Writer({ format: 'application/trig' });
}
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_add_prefixes() {
    const writer: N3.N3Writer = new N3.Writer();

    writer.addPrefixes({
        freebase: N3.DataFactory.namedNode("http://rdf.freebase.com/ns/"),
        xsd: N3.DataFactory.namedNode("http://www.w3.org/2001/XMLSchema#"),
        rdf: 'http://test'
    });

    writer.end((error, result) => {
        console.log(result);
    });
}
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_doc_from_triples_to_string() {
    const writer: N3.N3Writer = new N3.Writer({ prefixes: { c: 'http://example.org/cartoons#' } });
    writer.addQuad(N3.DataFactory.quad(
        N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
        N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
        N3.DataFactory.namedNode('http://example.org/cartoons#Cat')
    ));
    writer.addQuad(N3.DataFactory.quad(
      N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
      N3.DataFactory.namedNode('http://example.org/cartoons#name'),
      N3.DataFactory.literal('Tom'),
    ));
    writer.end((error, result: string) => { console.log(result); });

    const writer1: N3.N3Writer = N3.Writer({ format: 'N-Triples' });
    const writer2: N3.N3Writer = N3.Writer({ format: 'application/trig' });
}
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_doc_blank_nodes_and_lists() {
    const writer: N3.N3Writer = new N3.Writer({
        prefixes: {
            c: 'http://example.org/cartoons#',
            foaf: 'http://xmlns.com/foaf/0.1/'
        }
    });
    writer.addQuad(writer.blank(N3.DataFactory.namedNode('http://xmlns.com/foaf/0.1/givenName'), N3.DataFactory.literal('Tom', 'en')),
        N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
        N3.DataFactory.namedNode('http://example.org/cartoons#Cat'));
    writer.addQuad(N3.DataFactory.namedNode('http://example.org/cartoons#Jerry'),
        N3.DataFactory.namedNode('http://xmlns.com/foaf/0.1/knows'),
        writer.blank([{
            predicate: N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
            object: N3.DataFactory.namedNode('http://example.org/cartoons#Cat')
        }, {
            predicate: N3.DataFactory.namedNode('http://xmlns.com/foaf/0.1/givenName'),
            object: N3.DataFactory.literal('Tom', 'en'),
github DefinitelyTyped / DefinitelyTyped / types / n3 / n3-tests.ts View on Github external
function test_doc_from_triples_to_rdf_stream() {
    const writer: N3.N3Writer = new N3.Writer(process.stdout, { end: false, prefixes: { c: N3.DataFactory.namedNode('http://example.org/cartoons#') } });
    writer.addQuad(N3.DataFactory.quad(
      N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
      N3.DataFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
      N3.DataFactory.namedNode('http://example.org/cartoons#Cat'),
    ));
    writer.addQuad(N3.DataFactory.quad(
      N3.DataFactory.namedNode('http://example.org/cartoons#Tom'),
      N3.DataFactory.namedNode('http://example.org/cartoons#name'),
      N3.DataFactory.literal('Tom'),
    ));
    writer.end();
}
github linkeddata / rdflib.js / src / convert.js View on Github external
export function convertToNQuads (n3String, nquadCallback) {
  var nquadString
  var n3Parser = new Parser()
  var n3Writer = new Writer({
    format: 'N-Quads'
  })
  asyncLib.waterfall([
    function (callback) {
      n3Parser.parse(n3String, callback)
    },
    function (triple, prefix, callback) {
      if (triple !== null) {
        n3Writer.addTriple(triple)
      }
      if (typeof callback === 'function') {
        n3Writer.end(callback)
      }
    },
    function (result, callback) {
      nquadString = result