UNPKG

@jahed/sparql-engine

Version:

SPARQL query engine for servers and web browsers.

26 lines 985 B
// SPDX-License-Identifier: MIT import { termToString } from "rdf-string"; import { Pipeline } from "../engine/pipeline/pipeline.js"; import { Bindings } from "../rdf/bindings.js"; /** * Hash an set of mappings and produce an unique value * @private * @param item - The item to hash * @return An unique hash which identify the item */ function _hash(bindings) { const items = []; bindings.forEach((k, v) => items.push(`${k}=${encodeURIComponent(termToString(v))}`)); items.sort(); return items.join("&"); } /** * Applies a DISTINCT modifier on the output of another operator. * @see {@link https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#modDuplicates} * @param source - Input {@link PipelineStage} * @return A {@link PipelineStage} which evaluate the DISTINCT operation */ export default function sparqlDistinct(source) { return Pipeline.getInstance().distinct(source, (bindings) => _hash(bindings)); } //# sourceMappingURL=sparql-distinct.js.map