Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function test_doc_utility() {
const N3Util = N3.Util;
N3Util.isNamedNode(N3.DataFactory.namedNode('http://example.org/cartoons#Mickey')); // true
N3Util.isLiteral(N3.DataFactory.literal('Mickey Mouse')); // true
N3Util.isLiteral(N3.DataFactory.literal('Mickey Mouse', 'en')); // true
N3Util.isLiteral(N3.DataFactory.literal('3', N3.DataFactory.namedNode('http://www.w3.org/2001/XMLSchema#integer'))); // true
N3Util.isLiteral(N3.DataFactory.literal('http://example.org/')); // true
N3Util.isLiteral(N3.DataFactory.literal('This word is "quoted"!')); // true
N3Util.isLiteral(N3.DataFactory.literal('3', N3.DataFactory.namedNode('http://www.w3.org/2001/XMLSchema#integer'))); // true
new N3.Parser().parse('<a> <b> "This word is \\"quoted\\"!".', console.log);
// { subject: 'a', predicate: 'b', object: '"This word is "quoted"!"' }
N3Util.isBlankNode(N3.DataFactory.blankNode('b1')); // true
N3Util.isNamedNode(N3.DataFactory.blankNode('b1')); // false
N3Util.isLiteral(N3.DataFactory.blankNode('b1')); // false
const prefixes: N3.Prefixes = { rdfs: N3.DataFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#') };
const namedNode1: RDF.NamedNode = N3Util.prefix('http://www.w3.org/2000/01/rdf-schema#')('label');
const namedNode2: RDF.NamedNode = N3Util.prefixes(prefixes)('rdfs')('label');
}
</b></a>
function test_doc_rdf_to_triples_2() {
const parser1: N3.N3Parser = new N3.Parser({ format: 'N-Triples' });
const parser2: N3.N3Parser = new N3.Parser({ format: 'application/trig' });
// Notation3 (N3) is supported only through the format argument:
const parser3: N3.N3Parser = N3.Parser({ format: 'N3' });
const parser4: N3.N3Parser = N3.Parser({ format: 'Notation3' });
const parser5: N3.N3Parser = N3.Parser({ format: 'text/n3' });
}
Trellis.renderHTML = function(turtle, containerElement) {
// var parser = new n3.Parser();
var divNode = $("#nid-template");
// .clone(true)
var store = new require('n3').Store();
var parser = new require('n3').Parser();
parser.parse(turtle,
function(error, triple) {
if (error) {
console.log("Parser error : " + error);
}
if (triple) {
store.add(triple.subject, triple.predicate, triple.object);
if (triple.predicate == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') {
// console.log("O = " + triple.object);
}
} else {
buildTree(store, containerElement, divNode);
console.log("Parsed.")
Trellis.initDragDrop();
}
});
exports.parse = function(req, resourceURI, callback) {
var parser = N3.Parser({ documentURI: resourceURI }), triples = [];
parser.parse(req.rawBody, function(err, triple) {
if (err) {
callback(err);
} else if (triple) {
triple.subject = normalize(triple.subject);
if (N3.Util.isIRI(triple.object)) {
triple.object = normalize(triple.object);
}
triples.push(triple);
} else {
// when last triple is null, we're done parsing
callback(null, triples);
}
});
}
function resolveRelativeIRI (baseIri, relativeIri) {
if (!N3.Util.isIRI(relativeIri))
return relativeIri; // not really an IRI
var p = N3.Parser({ documentIRI: baseIri });
p._readSubject({type: "IRI", value: relativeIri});
return p._subject;
}
function ttlToJsonld (turtle, base, callback) {
var triples = [];
var parser = n3.Parser({
documentIRI: base
});
parser.parse(turtle, function (error, triple, prefixes) {
if (error) {
return callback(error);
}
if (triple) {
triples.push(triple);
} else {
callback(null, rdfToJsonld(n3Totriples(triples, prefixes), {
useRdfType: true
}));
}
});
}
promise.resolve();
}
if (newPrefixes) {
prefixes = Object.assign(prefixes, newPrefixes);
}
});
var promises2 = [promise].concat(promises).map(promise => {return promise.promise});
return q.all(promises2).then(() => {
return { triples,
prefixes,
statusCode: response.statusCode,
url : response.url};
});
} else if (["application/trig","application/n-quads","text/turtle","application/n-triples","text/n3"].indexOf(response.type.toLowerCase()) > -1) {
//Parse N3, text/turtle, N-Quads, n-triples or trig
var parser = new N3.Parser({documentIRI: response.url, factory: DataFactory});
parser.parse(response.body, (error, triple, newPrefixes) => {
this.emit("parsed", response.url);
if (error) {
promise.reject(error);
} else if (triple) {
triples.push(triple);
} else {
prefixes = Object.assign(prefixes, this.prefixes);
promise.resolve({ triples: triples,
prefixes: prefixes,
statusCode: response.statusCode,
url : response.url});
}
if (newPrefixes) {
prefixes = Object.assign(prefixes, newPrefixes);
}
function(stream, callback) {
var self = this;
var parser = N3.Parser();
parser.parse(stream, function(err, triple) {
if (err) {
callback(err);
return;
}
if (triple) {
self.add(triple);
} else {
callback();
}
});
};
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) {
async _parse (string, url) {
const quadsArray = []
const parser = new N3.Parser({ baseIRI: url })
return new Promise((resolve, reject) => {
parser.parse(string, (err, quad, prefixes) => {
if (quad) {
quadsArray.push(quad)
}
if (err) return reject(err)
if (!quad) {
const store = new N3.Store()
store.addQuads(quadsArray)
resolve(store)
}
})
})
}
}