How to use the rdf-terms.reduceTerms function in rdf-terms

To help you get started, we’ve selected a few rdf-terms 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-quadpattern / lib / ActorQueryOperationQuadpattern.ts View on Github external
public async runOperation(pattern: Algebra.Pattern, context: ActionContext)
  : Promise {
    // Resolve the quad pattern
    const result = await this.mediatorResolveQuadPattern.mediate({ pattern, context });

    // Collect all variables from the pattern
    const variables: string[] = this.getVariables(pattern);

    // Convenience datastructure for mapping quad elements to variables
    const elementVariables: {[key: string]: string} = reduceTerms(pattern,
      (acc: {[key: string]: string}, term: RDF.Term, key: QuadTermName) => {
        if (ActorQueryOperationQuadpattern.isTermVariable(term)) {
          acc[key] = termToString(term);
        }
        return acc;
      }, {});
    const quadBindingsReducer = (acc: {[key: string]: RDF.Term}, term: RDF.Term, key: QuadTermName) => {
      const variable: string = elementVariables[key];
      if (variable) {
        acc[variable] = term;
      }
      return acc;
    };

    const bindingsStream: BindingsStream = new PromiseProxyIterator(async () => result.data.map((quad) => {
      return Bindings(reduceTerms(quad, quadBindingsReducer, {}));
github comunica / comunica / packages / actor-query-operation-quadpattern / lib / ActorQueryOperationQuadpattern.ts View on Github external
const bindingsStream: BindingsStream = new PromiseProxyIterator(async () => result.data.map((quad) => {
      return Bindings(reduceTerms(quad, quadBindingsReducer, {}));
    }, { autoStart: true, maxBufferSize: 128 }));

rdf-terms

Convenience functions for handling RDFJS terms

MIT
Latest version published 10 months ago

Package Health Score

55 / 100
Full package analysis