How to use jsonld-context-parser - 6 common examples

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);
  }
github rubensworks / jsonld-streaming-serializer.js / lib / Util.ts View on Github external
public static termToValue(term: RDF.Term, context: IJsonLdContextNormalized, options: ITermToValueOptions = {
    compactIds: false,
    useNativeTypes: false,
  }): any {
    switch (term.termType) {
    case 'NamedNode':
      const compacted = ContextParser.compactIri(term.value, context, options.vocab);
      return options.compactIds ? compacted : { '@id': compacted };
    case 'DefaultGraph':
      return options.compactIds ? term.value : { '@id': term.value };
    case 'BlankNode':
      const id = `_:${term.value}`;
      return options.compactIds ? id : { '@id': id };
    case 'Literal':
      const stringType = term.datatype.value === Util.XSD_STRING;
      const rawValue = {
        '@value': !stringType && options.useNativeTypes
          ? Util.stringToNativeType(term.value, term.datatype.value) : term.value,
      };
      if (term.language) {
        return { ...rawValue, '@language': term.language };
      } else if (!stringType && typeof rawValue['@value'] === 'string') {
        return { ...rawValue, '@type': term.datatype.value };
github rubensworks / jsonld-streaming-parser.js / lib / Util.ts View on Github external
public static isValidIri(iri: string): boolean {
    return ContextParser.isValidIri(iri);
  }

jsonld-context-parser

Parses JSON-LD contexts

MIT
Latest version published 5 months ago

Package Health Score

64 / 100
Full package analysis