@jahed/sparql-engine
Version:
SPARQL query engine for servers and web browsers.
37 lines • 1.71 kB
JavaScript
// SPDX-License-Identifier: MIT
import ExecutionContext from "../engine/context/execution-context.js";
import { Pipeline } from "../engine/pipeline/pipeline.js";
import { PlanBuilder } from "../engine/plan-builder.js";
import { BindingBase, Bindings } from "../rdf/bindings.js";
/**
* Evaluates a SPARQL FILTER (NOT) EXISTS clause
* TODO this function could be simplified using a filterMap like operator, we should check if Rxjs offers that filterMap
* @param source - Source {@link PipelineStage}
* @param groups - Content of the FILTER clause
* @param builder - Plan builder used to evaluate subqueries
* @param notexists - True if the filter is NOT EXISTS, False otherwise
* @param context - Execution context
* @return A {@link PipelineStage} which evaluate the FILTER (NOT) EXISTS operation
*/
export default function exists(source, groups, builder, notexists, context) {
const defaultValue = new BindingBase();
defaultValue.setProperty("exists", false);
const engine = Pipeline.getInstance();
let evaluator = engine.mergeMapAsync(source, async (bindings) => {
let op = await builder._buildWhere(engine.of(bindings), groups, context);
op = engine.defaultValues(op, defaultValue);
op = engine.first(op);
return engine.map(op, (b) => {
const exists = !b.hasProperty("exists") || b.getProperty("exists");
return {
bindings,
output: (exists && !notexists) || (!exists && notexists),
};
});
});
evaluator = engine.filter(evaluator, (b) => {
return b.output;
});
return engine.map(evaluator, (b) => b.bindings);
}
//# sourceMappingURL=exists.js.map