How to use the sparqlee.AsyncEvaluator function in sparqlee

To help you get started, we’ve selected a few sparqlee 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-orderby-sparqlee / lib / ActorQueryOperationOrderBySparqlee.ts View on Github external
public async runOperation(pattern: Algebra.OrderBy, context: ActionContext)
    : Promise {

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

    const options = { window: this.window };
    const sparqleeConfig = { ...ActorQueryOperation.getExpressionContext(context) };
    let bindingsStream = output.bindingsStream;

    for (let expr of pattern.expressions) {
      const isAscending = this.isAscending(expr);
      expr = this.extractSortExpression(expr);

      // Transform the stream by annotating it with the expr result
      const evaluator = new AsyncEvaluator(expr, sparqleeConfig);
      interface IAnnotatedBinding { bindings: Bindings; result: Term; }
      const transform = async (bindings: Bindings, next: any) => {
        try {
          const result = await evaluator.evaluate(bindings);
          transformedStream._push({ bindings, result });
        } catch (err) {
          if (!isExpressionError(err)) {
            bindingsStream.emit('error', err);
          }
          transformedStream._push({ bindings, result: undefined });
        }
        next();
      };
      const transformedStream = bindingsStream.transform({ transform });

      // Sort the annoted stream
github comunica / comunica / packages / actor-query-operation-filter-sparqlee / lib / ActorQueryOperationFilterSparqlee.ts View on Github external
public async testOperation(pattern: Algebra.Filter, context: ActionContext): Promise {
    // Will throw error for unsupported operators
    const config = { exists: this.createExistenceResolver(context) };
    const _ = new AsyncEvaluator(pattern.expression, config);
    return true;
  }
github comunica / comunica / packages / actor-query-operation-extend / lib / ActorQueryOperationExtend.ts View on Github external
public async runOperation(pattern: Algebra.Extend, context: ActionContext)
    : Promise {

    const { expression, input, variable } = pattern;

    const output: IActorQueryOperationOutputBindings = ActorQueryOperation.getSafeBindings(
      await this.mediatorQueryOperation.mediate({ operation: input, context }));

    const extendKey = termToString(variable);
    const config = { ...ActorQueryOperation.getExpressionContext(context) };
    const evaluator = new AsyncEvaluator(expression, config);

    // Transform the stream by extending each Bindings with the expression result
    const transform = async (bindings: Bindings, next: any) => {
      try {
        const result = await evaluator.evaluate(bindings);
        // Extend operation is undefined when the key already exists
        // We just override it here.
        const extended = bindings.set(extendKey, result);
        bindingsStream._push(extended);
      } catch (err) {
        if (isExpressionError(err)) {
          // Errors silently don't actually extend according to the spec
          bindingsStream._push(bindings);
          // But let's warn anyway
          this.logWarn(context, `Expression error for extend operation with bindings '${JSON.stringify(bindings)}'`);
        } else {
github comunica / comunica / packages / actor-query-operation-extend / lib / ActorQueryOperationExtend.ts View on Github external
public async testOperation(pattern: Algebra.Extend, context: ActionContext): Promise {
    // Will throw error for unsupported opperations
    const _ = !!new AsyncEvaluator(pattern.expression);
    return true;
  }
github comunica / comunica / packages / actor-query-operation-orderby-sparqlee / lib / ActorQueryOperationOrderBySparqlee.ts View on Github external
public async testOperation(pattern: Algebra.OrderBy, context: ActionContext): Promise {
    // Will throw error for unsupported operators
    for (let expr of pattern.expressions) {
      expr = this.extractSortExpression(expr);
      const _ = new AsyncEvaluator(expr);
    }
    return true;
  }
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) {
        if (!isExpressionError(err)) {
          bindingsStream.emit('error', err);
        }
      }
      next();
    };

    const bindingsStream = output.bindingsStream.transform({ transform });
github comunica / comunica / packages / actor-query-operation-leftjoin-nestedloop / lib / ActorQueryOperationLeftJoinNestedLoop.ts View on Github external
public async runOperation(pattern: Algebra.LeftJoin, context: ActionContext)
    : Promise {

    const leftRaw = await this.mediatorQueryOperation.mediate({ operation: pattern.left, context });
    const left = ActorQueryOperation.getSafeBindings(leftRaw);
    const rightRaw = await this.mediatorQueryOperation.mediate({ operation: pattern.right, context });
    const right = ActorQueryOperation.getSafeBindings(rightRaw);

    const config = { ...ActorQueryOperation.getExpressionContext(context) };
    const evaluator = (pattern.expression)
      ? new AsyncEvaluator(pattern.expression, config)
      : null;

    const leftJoinInner = (outerItem: Bindings, innerStream: ClonedIterator) => {
      const joinedStream = innerStream
        .transform({
          transform: async (innerItem: Bindings, nextInner: any) => {
            const joinedBindings = ActorRdfJoin.join(outerItem, innerItem);
            if (!joinedBindings) { nextInner(); return; }
            if (!pattern.expression) {
              joinedStream._push({ joinedBindings, result: true });
              nextInner();
              return;
            }
            try {
              const result = await evaluator.evaluateAsEBV(joinedBindings);
              joinedStream._push({ joinedBindings, result });

sparqlee

A simple SPARQL expression evaluator library

MIT
Latest version published 1 year ago

Package Health Score

45 / 100
Full package analysis