Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SummaryController.prototype._handleRequest = function (request, response, next) {
var summaryMatch = this._matcher && this._matcher.exec(request.url), datasource;
if (datasource = summaryMatch && summaryMatch[1]) {
var summaryFile = path.join(this._summariesFolder, datasource + '.ttl');
// Read summary triples from file
var streamParser = new StreamParser({ blankNodePrefix: '' }),
inputStream = fs.createReadStream(summaryFile);
// If the summary cannot be read, invoke the next controller without error
inputStream.on('error', function (error) { next(); });
inputStream.pipe(streamParser);
// Set caching
response.setHeader('Cache-Control', 'public,max-age=604800'); // 14 days
// Render the summary
var view = this._negotiateView('Summary', request, response);
view.render({ prefixes: this._prefixes, results: streamParser }, request, response);
}
else
next();
};
const parseClassesAndProperties = url => _(request(url).pipe(N3.StreamParser()))
// ignore blank nodes
.reject(triple => isBlank(triple.subject))
// group into JSON-LD nodes with specified predicates
.reduce(Map(), rollup(PREDICATES))
// stream over values
.flatMap(map => _(map.valueSeq()))
// ignore resources without labels
.reject(node => node.preferredLabel() === undefined)
// infer datatype properties
.map(inferDatatypeProperties)
// split into classes and properties
.reduce({}, ({classes = Map(), properties = Map()}, node) => (
isClass(node)
? ({classes: classes.set(node.id, node), properties})
: isProperty(node)
? ({classes, properties: properties.set(node.id, node)})
fs.exists(filename, function (exists) {
if (!exists) return triples.close();
triples.source = fs.createReadStream(filename).pipe(N3.StreamParser());
});
triples.on('error', console.error);
function test_doc_rdf_stream_to_triples_1() {
interface QuadBnode extends N3.BaseQuad {
subject: N3.BlankNode;
predicate: N3.BlankNode;
object: N3.BlankNode;
graph: N3.BlankNode;
}
const parser: N3.N3Parser = new N3.Parser({factory: N3.DataFactory});
parser.parse('abc', console.log);
const streamParser: N3.N3StreamParser = N3.StreamParser();
const quad: RDF.Quad = streamParser.read();
const rdfStream = fs.createReadStream('cartoons.ttl');
const pipedStreamParser: N3.N3StreamParser = rdfStream.pipe(streamParser);
streamParser.pipe(new class SlowConsumer extends stream.Writable {
constructor() {
super({ objectMode: true });
this._write = (quad: RDF.Quad, encoding, done) => {
console.log(quad);
setTimeout(done, 1000);
};
}
}());
}
function importTurtleFile (graph, file, callback) {
var parser = N3.StreamParser()
var writer = graph.putStream()
N3.Parser._resetBlankNodeIds()
fs.createReadStream(file).pipe(parser).pipe(writer)
writer.on('end', callback)
writer.on('error', callback)
}
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);
}
public async runHandle(action: IActionRdfParse, mediaType: string, context: ActionContext)
: Promise {
action.input.on('error', (e) => quads.emit('error', e));
const quads = action.input.pipe(new StreamParser({ baseIRI: action.baseIRI }));
return {
quads,
triples: mediaType === 'text/turtle'
|| mediaType === 'application/n-triples'
|| mediaType === 'text/n3',
};
}
return httpUtils.asyncMiddleware(async (req, res) => {
const parserStream = new n3.StreamParser({format: req.get('content-type')});
await rdfStore.putStream(req.pipe(parserStream));
res.status(200).end();
});
}
(resolve, reject) => {
const streamParser = N3.StreamParser()
, learner = new ShapeLearner()
learner.on('finish', () => resolve())
streamParser.on('error', err => reject(`${filename}: ${err}`))
streamParser.pipe(learner)
fs.createReadStream(filename).pipe(streamParser)
}
))