How to use the jsonld-context-parser.ContextParser.expandTerm function in jsonld-context-parser

To help you get started, we’ve selected a few jsonld-context-parser 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 rubensworks / jsonld-streaming-parser.js / lib / Util.ts View on Github external
public predicateToTerm(context: IJsonLdContextNormalized, key: string): RDF.Term {
    const expanded: string = ContextParser.expandTerm(key, context, true);

    // Immediately return if the predicate was disabled in the context
    if (!expanded) {
      return null;
    }

    // Check if the predicate is a blank node
    if (expanded[0] === '_' && expanded[1] === ':') {
      if (this.parsingContext.produceGeneralizedRdf) {
        return this.dataFactory.blankNode(expanded.substr(2));
      } else {
        return null;
      }
    }

    // Check if the predicate is a valid IRI
github rubensworks / jsonld-streaming-parser.js / lib / Util.ts View on Github external
public resourceToTerm(context: IJsonLdContextNormalized, key: string): RDF.Term {
    if (key.startsWith('_:')) {
      return this.dataFactory.blankNode(key.substr(2));
    }
    const iri = ContextParser.expandTerm(key, context, false);
    if (!Util.isValidIri(iri)) {
      if (iri && this.parsingContext.errorOnInvalidProperties) {
        this.parsingContext.emitError(new Error(`Invalid resource IRI: ${iri}`));
      } else {
        return null;
      }
    }
    return this.dataFactory.namedNode(iri);
  }
github rubensworks / jsonld-streaming-parser.js / lib / Util.ts View on Github external
public createVocabOrBaseTerm(context: IJsonLdContextNormalized, key: string): RDF.Term {
    if (key.startsWith('_:')) {
      return this.dataFactory.blankNode(key.substr(2));
    }
    let expanded = ContextParser.expandTerm(key, context, true);
    if (expanded === key) {
      expanded = ContextParser.expandTerm(key, context, false);
    }
    if (!Util.isValidIri(expanded)) {
      if (expanded && this.parsingContext.errorOnInvalidProperties) {
        this.parsingContext.emitError(new Error(`Invalid term IRI: ${expanded}`));
      } else {
        return null;
      }
    }
    return this.dataFactory.namedNode(expanded);
  }
github rubensworks / jsonld-streaming-parser.js / lib / Util.ts View on Github external
public createVocabOrBaseTerm(context: IJsonLdContextNormalized, key: string): RDF.Term {
    if (key.startsWith('_:')) {
      return this.dataFactory.blankNode(key.substr(2));
    }
    let expanded = ContextParser.expandTerm(key, context, true);
    if (expanded === key) {
      expanded = ContextParser.expandTerm(key, context, false);
    }
    if (!Util.isValidIri(expanded)) {
      if (expanded && this.parsingContext.errorOnInvalidProperties) {
        this.parsingContext.emitError(new Error(`Invalid term IRI: ${expanded}`));
      } else {
        return null;
      }
    }
    return this.dataFactory.namedNode(expanded);
  }

jsonld-context-parser

Parses JSON-LD contexts

MIT
Latest version published 5 months ago

Package Health Score

64 / 100
Full package analysis