Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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);
}
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);
}
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);
}