How to use the @comunica/bus-query-operation.ActorQueryOperation.validateQueryOutput function in @comunica/bus-query-operation

To help you get started, we’ve selected a few @comunica/bus-query-operation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github comunica / comunica / packages / actor-query-operation-filter-direct / lib / ActorQueryOperationFilterDirect.ts View on Github external
public async runOperation(pattern: Algebra.Filter, context: ActionContext)
    : Promise {
    const output: IActorQueryOperationOutputBindings = ActorQueryOperation.getSafeBindings(
      await this.mediatorQueryOperation.mediate({ operation: pattern.input, context }));
    ActorQueryOperation.validateQueryOutput(output, 'bindings');

    const exprFunc = SparqlExpressionEvaluator.createEvaluator(pattern.expression);
    const filter = (bindings: Bindings) => {
      try {
        const term = exprFunc(bindings);
        return term && term.value !== 'false' && term.value !== '0';
      } catch (e) {
        bindingsStream.emit('error', e);
        return false;
      }
    };
    const bindingsStream = output.bindingsStream.filter(filter);

    return { type: 'bindings', bindingsStream, metadata: output.metadata, variables: output.variables };
  }
github comunica / comunica / packages / actor-query-operation-filter-sparqlee / lib / ActorQueryOperationFilterSparqlee.ts View on Github external
public async runOperation(pattern: Algebra.Filter, context: ActionContext)
    : Promise {

    const outputRaw = await this.mediatorQueryOperation.mediate({ operation: pattern.input, context });
    const output = ActorQueryOperation.getSafeBindings(outputRaw);
    ActorQueryOperation.validateQueryOutput(output, 'bindings');
    const { variables, metadata } = output;

    const expressionContext = ActorQueryOperation.getExpressionContext(context);
    const config = {
      ...expressionContext,
      exists: this.createExistenceResolver(context),
    };
    const evaluator = new AsyncEvaluator(pattern.expression, config);

    const transform = async (item: Bindings, next: any) => {
      try {
        const result = await evaluator.evaluateAsEBV(item);
        if (result) {
          bindingsStream._push(item);
        }
      } catch (err) {