wurtle
Version:
Utilities to parse grouped quads from the N3-family of serializations based on parser directives
40 lines • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var n3_1 = require("n3");
/**
* Due to some historic decisions in N3.js it seems impossible to extend the Writer class.
*/
var GroupedWriter = /** @class */ (function () {
function GroupedWriter(outputStream, options) {
this.writer = new n3_1.Writer(outputStream, options);
this._groupCount = 0;
}
/**
* Add a group of quads and group them using wurtle
* @param groupedQuads
*/
GroupedWriter.prototype.addGroupedQuads = function (groupedQuads) {
var _this = this;
this.writer._outputStream.write('# @group begin ' + this._groupCount + '\n');
var _loop_1 = function (i) {
var quad = groupedQuads[i];
this_1.writer.addQuad(quad.subject, quad.predicate, quad.object, quad.graph, function () {
//If this was the last element, close the group now.
if (groupedQuads.length === i + 1) {
_this.writer._outputStream.write('\n# @group end ' + _this._groupCount + '\n');
_this._groupCount++;
}
});
};
var this_1 = this;
for (var i = 0; i < groupedQuads.length; i++) {
_loop_1(i);
}
};
GroupedWriter.prototype.end = function (cb) {
this.writer.end(cb);
};
return GroupedWriter;
}());
exports.default = GroupedWriter;
//# sourceMappingURL=N3GroupedWriter.js.map