Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case 'numeric':
args[i] = parseFloat(arg)
break
case 'boolean':
args[i] = arg !== XSD_FALSE &&
(!isLiteral(arg) || arg !== '0')
break
}
}
// Call the operator on the evaluated arguments
var result = operator.apply(null, args)
// Convert result if necessary
switch (operator.resultType) {
case 'numeric':
// TODO: determine type instead of taking the type of the first argument
var type = N3Util.getLiteralType(origArgs[0]) || XSD_INTEGER
return '"' + result + '"^^' + type
case 'boolean':
return result ? XSD_TRUE : XSD_FALSE
default:
return result
}
}
})(operator, argumentExpressions)
export function parseTerm (term: string): Term {
if (term.startsWith('?')) {
return Variable.allocate(term)
} else if (term.startsWith('\"')) {
const value = Util.getLiteralValue(term)
const lang = Util.getLiteralLanguage(term)
const type = cleanIRI(Util.getLiteralType(term))
return parseLiteral(value, type, lang)
} else if (term.startsWith('<') || term.startsWith('http') || Util.isIRI(term)) {
return new IRI(term)
}
throw new SyntaxError(`Unkown RDF Term found during parsing: ${term}`)
}
function parseTerm (term) {
let parsed = null
if (n3utils.isIRI(term)) {
parsed = terms.IRIDescriptor(term)
} else if (n3utils.isLiteral(term)) {
const value = n3utils.getLiteralValue(term)
const lang = n3utils.getLiteralLanguage(term)
const type = stripDatatype(n3utils.getLiteralType(term))
if (lang !== null && lang !== undefined && lang !== '') {
parsed = terms.LangLiteralDescriptor(value, lang)
} else if (term.indexOf('^^') > -1) {
parsed = terms.TypedLiteralDescriptor(value, type)
} else {
parsed = terms.RawLiteralDescriptor(value)
}
} else {
throw new Error(`Unknown RDF Term encoutered during parsing: ${term}`)
}
return parsed
}
function createTriple(subject, predicate, object) {
return {
subject: { value: subject, type: subject[0] !== '_' ? 'IRI' : 'blank node' },
predicate: { value: predicate, type: predicate[0] !== '_' ? 'IRI' : 'blank node' },
object: !N3Util.isLiteral(object) ?
{ value: object, type: object[0] !== '_' ? 'IRI' : 'blank node' } :
{ value: N3Util.getLiteralValue(object),
datatype: N3Util.getLiteralType(object),
language: N3Util.getLiteralLanguage(object) },
};
}
return { '@default': triples.map(function (triple) {
var subject = triple.subject, predicate = triple.predicate, object = triple.object;
return {
subject: { value: subject, type: getTypeName(object) },
predicate: { value: predicate, type: getTypeName(object) },
object: !N3Util.isLiteral(object) ? { value: object, type: getTypeName(object) }
: { value: N3Util.getLiteralValue(object),
datatype: N3Util.getLiteralType(object),
language: N3Util.getLiteralLanguage(object) }
};
})};
}},