How to use the rdf-terms.getVariables 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-rdf-resolve-quad-pattern-sparql-json / lib / ActorRdfResolveQuadPatternSparqlJson.ts View on Github external
public static replaceBlankNodes(pattern: RDF.Quad): RDF.Quad {
    const variableNames: string[] = getVariables(getTerms(pattern)).map((v) => v.value);
    // track the names the blank nodes get mapped to (required if the name has to change)
    const blankMap: { [id: string]: string } = {};
    let changed = false;

    // for every position, convert to a variable if there is a blank node
    const result = mapTerms(pattern, (term) => {
      if (term.termType === 'BlankNode') {
        let name = term.value;
        if (blankMap[name]) {
          name = blankMap[name];
        } else {
          if (variableNames.indexOf(name) >= 0) {
            // increase index added to name until we find one that is available (2 loops at most)
            let idx = 0;
            while (variableNames.indexOf(name + idx) >= 0) {
              ++idx;
github comunica / comunica / packages / actor-rdf-resolve-quad-pattern-sparql-json / lib / ActorRdfResolveQuadPatternSparqlJson.ts View on Github external
public static patternToSelectQuery(pattern: RDF.Quad): string {
    const variables: RDF.Variable[] = getVariables(getTerms(pattern));
    return toSparql(ActorRdfResolveQuadPatternSparqlJson.FACTORY.createProject(
      ActorRdfResolveQuadPatternSparqlJson.patternToBgp(pattern),
      variables,
    ));
  }

rdf-terms

Convenience functions for handling RDFJS terms

MIT
Latest version published 1 year ago

Package Health Score

45 / 100
Full package analysis