How to use the n3.Util.isIRI 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 / controllers / TriplePatternFragmentsController.js View on Github external
var requestUrl = request.parsedUrl,
      // maintain the originally requested query string to avoid encoding differences
      origQuery = request.url.replace(/[^?]+/, ''),
      pageUrl = url.format(requestUrl).replace(/\?.*/, origQuery),
      paramsNoPage = _.omit(requestUrl.query, 'page'),
      currentPage = parseInt(requestUrl.query.page, 10) || 1,
      datasourceUrl = url.format(_.omit(requestUrl, 'query')),
      fragmentUrl = url.format(_.defaults({ query: paramsNoPage }, requestUrl)),
      fragmentPageUrlBase = fragmentUrl + (/\?/.test(fragmentUrl) ? '&' : '?') + 'page=',
      indexUrl = url.format(_.omit(requestUrl, 'search', 'query', 'pathname')) + '/';

  // Generate a textual representation of the pattern
  query.patternString = '{ ' +
    (query.subject              ? '<' + query.subject   + '> ' : '?s ') +
    (query.predicate            ? '<' + query.predicate + '> ' : '?p ') +
    (N3Util.isIRI(query.object) ? '<' + query.object    + '> ' : (query.object || '?o')) + ' }';

  return {
    datasource: _.assign(_.omit(datasourceSettings, 'datasource'), {
      index: indexUrl + '#dataset',
      url: datasourceUrl + '#dataset',
      templateUrl: datasourceUrl + '{?subject,predicate,object}',
    }),
    fragment: {
      url: fragmentUrl,
      pageUrl: pageUrl,
      firstPageUrl: fragmentPageUrlBase + '1',
      nextPageUrl: fragmentPageUrlBase + (currentPage + 1),
      previousPageUrl: currentPage > 1 ? fragmentPageUrlBase + (currentPage - 1) : null,
    },
    query: query,
    prefixes: this._prefixes,
github Callidon / sparql-engine / src / rdf / rdf-model.ts View on Github external
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}`)
}
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
github LinkedDataFragments / Server.js / lib / controllers / QuadPatternFragmentsController.js View on Github external
QuadPatternFragmentsController.prototype._createPatternString = function(query) {
    return '{ ' +
        (query.subject              ? '<' + query.subject   + '> ' : '?s ') +
        (query.predicate            ? '<' + query.predicate + '> ' : '?p ') +
        (N3Util.isIRI(query.object) ? '<' + query.object    + '> ' : (query.object || '?o ')) +
        (query.graph                ? '<' + query.graph     + '> ' : '?g' ) + ' }';
};