Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseEntity(entity, prefixes) {
// falsy, variable, or blank indicates an unknown
if (!entity || /^\?|^_:/.test(entity))
return null;
// angular brackets indicate a URI
var match = /^<(.*)>$/.exec(entity);
if (match)
return match[1];
// remove possible angular brackets from literal types
if (N3Util.isLiteral(entity))
entity = entity.replace(/<([^<>]*)>$/, '$1');
// try to expand a prefixed name (or type)
try { return N3Util.expandPrefixedName(entity, prefixes); }
// return the entity as-is if expansion fails (prefix not found)
catch (error) { return entity; }
}
meta: function (s, p, o) {
if (s && p && o && !N3Util.isLiteral(s))
metadata.push(createTriple(s, p, o));
},
// Ends the output and flushes the stream
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) }
};
})};
}},
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) },
};
}
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
}
export function parseTerm (term: string): terms.RDFTerm {
let parsed = null
if (Util.isIRI(term)) {
parsed = terms.createIRI(term)
} else if (Util.isLiteral(term)) {
const value = Util.getLiteralValue(term)
const lang = Util.getLiteralLanguage(term)
const type = cleanIRI(Util.getLiteralType(term))
if (lang !== null && lang !== undefined && lang !== '') {
parsed = terms.createLangLiteral(value, lang)
} else if (term.indexOf('^^') > -1) {
parsed = terms.createTypedLiteral(value, type)
} else {
parsed = terms.createLiteral(value)
}
} else {
throw new SyntaxError(`Unknown RDF Term encoutered during parsing: ${term}`)
}
return parsed
}