UNPKG

rdf-dataset-fragmenter

Version:
38 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuadTransformerDistinct = void 0; const rdf_string_1 = require("rdf-string"); /** * A quad transformer that wraps over another quad transformer and removes duplicates produced by the transformer. * Only quads that are produced by the quad transformer (and are unequal to the incoming quad) will be filtered away. */ class QuadTransformerDistinct { transformer; passedQuads; constructor(transformer) { this.transformer = transformer; this.passedQuads = new Set(); } transform(quad, allowedComponent) { return this.transformer.transform(quad) .filter((quadOut) => { // Always let through quads that equal the incoming quad if (quadOut.equals(quad)) { return true; } const hash = JSON.stringify({ ...(0, rdf_string_1.quadToStringQuad)(quadOut), allowedComponent }); if (this.passedQuads.has(hash)) { return false; } this.passedQuads.add(hash); return true; }); } end() { if (this.transformer.end) { this.transformer.end(); } } } exports.QuadTransformerDistinct = QuadTransformerDistinct; //# sourceMappingURL=QuadTransformerDistinct.js.map