How to use the n3.Util.isLiteral function in n3

To help you get started, we’ve selected a few n3 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 LinkedDataFragments / Server.js / lib / LinkedDataFragmentsServer.js View on Github external
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; }
}
github LinkedDataFragments / Server.js / lib / writers / JsonLdWriter.js View on Github external
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
github LinkedDataFragments / Server.js / lib / JsonLdFragmentWriter.js View on Github external
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) }
          };
        })};
      }},
github LinkedDataFragments / Server.js / lib / writers / JsonLdWriter.js View on Github external
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) },
  };
}
github Callidon / sparql-engine / src / utils.js View on Github external
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
}
github Callidon / sparql-engine / src / utils.ts View on Github external
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
  }