Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static mapTerm(term: any): RDF.Term {
switch (term.termType) {
case 'NamedNode':
return namedNode(term.value);
case 'BlankNode':
return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
case 'Literal':
return literal(term.value, term.language || term.datatype);
/*case 'Variable':
return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
case 'DefaultGraph':
return defaultGraph();
}
}
const fromPlainTerm = plainTerm => {
switch (plainTerm.termType) {
case "NamedNode":
return rdf.namedNode(plainTerm.value);
case "BlankNode":
return rdf.blankNode(plainTerm.value.substr(2));
case "Literal":
return rdf.literal(
plainTerm.value,
plainTerm.language || rdf.namedNode(plainTerm.datatype.value)
);
case "DefaultGraph":
return rdf.defaultGraph();
default:
throw Error("unknown termType: " + plainTerm.termType);
}
};
term (plainTerm) {
switch (plainTerm.termType) {
case 'NamedNode':
return DataFactory.namedNode(plainTerm.value)
case 'BlankNode':
return DataFactory.blankNode(plainTerm.value.substr(2))
case 'Literal':
return DataFactory.literal(plainTerm.value, plainTerm.language || DataFactory.namedNode(plainTerm.datatype.value))
case 'DefaultGraph':
return DataFactory.defaultGraph()
default:
throw Error('unknown termType: ' + plainTerm.termType)
}
}
public static localizeBlankNode(blankNodeCounter: number,
term: RDF.Term): RDF.Term {
if (term.termType === 'BlankNode') {
return blankNode(term.value + blankNodeCounter);
}
return term;
}