How to use the rdf-string.termToString function in rdf-string

To help you get started, we’ve selected a few rdf-string 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-group / lib / GroupsState.ts View on Github external
// Update all the aggregators with the input binding
      const group = this.groups.get(groupHash);
      for (const i in this.pattern.aggregates) {
        const aggregate = this.pattern.aggregates[i];

        // If distinct, check first wether we have inserted these values already
        if (aggregate.distinct) {
          const hash = this.hashBindings(bindings);
          if (this.distinctHashes!.get(groupHash).has(hash)) {
            continue;
          } else {
            this.distinctHashes!.get(groupHash).add(hash);
          }
        }

        const variable = termToString(aggregate.variable);
        group.aggregators[variable].put(bindings);
      }
    }
  }
github comunica / comunica / packages / actor-query-operation-group / lib / GroupsState.ts View on Github external
aggBindings[variable] = value;
        }
      }

      // Merge grouping bindings and aggregator bindings
      return groupBindings.merge(aggBindings);
    });

    // Case: No Input
    // Some aggregators still define an output on the empty input
    // Result is a single Bindings
    if (rows.length === 0) {
      const single: { [key: string]: Term } = {};
      for (const i in this.pattern.aggregates) {
        const aggregate = this.pattern.aggregates[i];
        const key = termToString(aggregate.variable);
        const value = AggregateEvaluator.emptyValue(aggregate);
        if (value !== undefined) {
          single[key] = value;
        }
      }
      rows = [Bindings(single)];
    }

    return rows;
  }
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
github comunica / comunica / packages / actor-rdf-resolve-quad-pattern-ostrich / lib / OstrichIterator.ts View on Github external
constructor(ostrichDocument: any, versionContext: VersionContext,
              subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, options?: any) {
    super(options || { autoStart: false });
    this.ostrichDocument = ostrichDocument;
    this.versionContext = versionContext;
    this.subject = RdfString.termToString(subject);
    this.predicate = RdfString.termToString(predicate);
    this.object = RdfString.termToString(object);
    this.position = options && options.offset || 0;

    this.on('newListener', (eventName) => {
      if (eventName === 'totalItems') {
        setImmediate(() => this._fillBuffer());
      }
    });
  }
github comunica / comunica / packages / actor-query-operation-quadpattern / lib / ActorQueryOperationQuadpattern.ts View on Github external
(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) => {
github comunica / comunica / packages / actor-rdf-resolve-quad-pattern-hdt / lib / HdtIterator.ts View on Github external
constructor(hdtDocument: any, subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, options?: any) {
    super(options || { autoStart: false });
    this.hdtDocument = hdtDocument;
    this.subject = RdfString.termToString(subject);
    this.predicate = RdfString.termToString(predicate);
    this.object = RdfString.termToString(object);
    this.position = options && options.offset || 0;

    this.on('newListener', (eventName) => {
      if (eventName === 'totalItems') {
        setImmediate(() => this._fillBuffer());
      }
    });
  }
github comunica / comunica / packages / actor-rdf-resolve-quad-pattern-ostrich / lib / OstrichIterator.ts View on Github external
constructor(ostrichDocument: any, versionContext: VersionContext,
              subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, options?: any) {
    super(options || { autoStart: false });
    this.ostrichDocument = ostrichDocument;
    this.versionContext = versionContext;
    this.subject = RdfString.termToString(subject);
    this.predicate = RdfString.termToString(predicate);
    this.object = RdfString.termToString(object);
    this.position = options && options.offset || 0;

    this.on('newListener', (eventName) => {
      if (eventName === 'totalItems') {
        setImmediate(() => this._fillBuffer());
      }
    });
  }
github comunica / comunica / packages / actor-rdf-resolve-quad-pattern-ostrich / lib / OstrichQuadSource.ts View on Github external
return new Promise((resolve, reject) => {
      const s = RdfString.termToString(subject);
      const p = RdfString.termToString(predicate);
      const o = RdfString.termToString(object);
      const done = (error: Error, totalItems: number) => {
        if (error) {
          reject(error);
        }
        resolve(totalItems);
      };
      if (this.versionContext.type === 'version-materialization') {
        this.ostrichDocument.countTriplesVersionMaterialized(s, p, o, this.versionContext.version, done);
      } else if (this.versionContext.type === 'delta-materialization') {
        this.ostrichDocument.countTriplesDeltaMaterialized(s, p, o,
          this.versionContext.versionEnd, this.versionContext.versionStart, done);
      } else {
        this.ostrichDocument.countTriplesVersion(s, p, o, done);
      }
    });
github comunica / comunica / packages / actor-query-operation-filter-sparqlee / lib / ActorQueryOperationFilterSparqlee.ts View on Github external
private substituteSingle(term: RDF.Term, bindings: Bindings): RDF.Term {
    if (term.termType === 'Variable') {
      return bindings.get(termToString(term), term);
    }
    return term;
  }
}

rdf-string

Convenience functions for creating and serializing RDF terms and quads

MIT
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis