How to use the n3.Util 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 / Client.js / lib / util / RdfUtil.js View on Github external
/*! @license MIT ©2014-2016 Ruben Verborgh, Ghent University - imec */

var N3 = require('n3'),
    _ = require('lodash');

var genidMatcher = /^https?:\/\/[^\/]+\/\.well-known\/genid\/([^]+)$/;

/**
 * Utility functions for working with URIs, triples, variables, and patterns.
 * @exports RdfUtil
 * @extends N3.Util
 */
var util = module.exports = new N3.Util({});

/* Methods for URIs */

/** Checks whether two URIs are equal after decoding, to make up for encoding differences. **/
util.decodedURIEquals = function (URIa, URIb) {
  if (URIa === URIb) return true;
  try { return decodeURI(URIa) === decodeURI(URIb); }
  catch (error) { return false; }
};

/** Transforms a skolemized URI into a blank node. */
util.deskolemize = function (URI) {
  return URI && URI.replace(genidMatcher, function (URI, id) {
    return '_:' + id.replace(/\W/g, '_');
  });
};
github dan-f / twinql / src / rdf / serialize.js View on Github external
if (quad) {
        const newQuad = {}
        for (let [whichNode, n3NodeText] of iterObj(quad)) {
          let nodeVal
          if (N3.Util.isIRI(n3NodeText)) {
            nodeVal = Node({ termType: 'NamedNode', value: n3NodeText })
          } else if (N3.Util.isLiteral(n3NodeText)) {
            const language = (N3.Util.getLiteralLanguage(n3NodeText))
            const datatype = (N3.Util.getLiteralType(n3NodeText))
            const metaData = {
              language: language || null,
              datatype: datatype !== STR_TYPE
                ? datatype
                : null
            }
            nodeVal = Node({ termType: 'Literal', value: N3.Util.getLiteralValue(n3NodeText), ...metaData })
          } else if (N3.Util.isBlank(n3NodeText)) {
            nodeVal = Node({ termType: 'BlankNode', value: n3NodeText })
          }
          newQuad[whichNode] = nodeVal
        }
        if (graphName && !newQuad.graph) {
          newQuad.graph = Node({ termType: 'NamedNode', value: graphName })
        }
        quads.push(Quad(newQuad))
      } else {
        resolve(Graph.fromQuads(quads))
      }
    })
  })
github jolocom / smartwallet-app / src / js / stores / comments.js View on Github external
import Reflux from 'reflux'
import _ from 'lodash'

import N3 from 'n3'
import HTTPAgent from 'lib/agents/http.js'
import Util from 'lib/util.js'
import {Parser, Writer} from 'lib/rdf.js'
import {DC, RDF, SIOC} from 'lib/namespaces.js'

let N3Util = N3.Util
let http = new HTTPAgent()

import CommentsActions from 'actions/comments'

let {load, create, remove} = CommentsActions

let comments = []

export default Reflux.createStore({
  listenables: CommentsActions,

  getInitialState() {
    return {
      loading: true,
      items: []
    }
github dan-f / twinql / src / rdf / serialize.js View on Github external
parser.parse(text, function (error, quad) {
      if (error) { reject(error) }
      if (quad) {
        const newQuad = {}
        for (let [whichNode, n3NodeText] of iterObj(quad)) {
          let nodeVal
          if (N3.Util.isIRI(n3NodeText)) {
            nodeVal = Node({ termType: 'NamedNode', value: n3NodeText })
          } else if (N3.Util.isLiteral(n3NodeText)) {
            const language = (N3.Util.getLiteralLanguage(n3NodeText))
            const datatype = (N3.Util.getLiteralType(n3NodeText))
            const metaData = {
              language: language || null,
              datatype: datatype !== STR_TYPE
                ? datatype
                : null
            }
            nodeVal = Node({ termType: 'Literal', value: N3.Util.getLiteralValue(n3NodeText), ...metaData })
          } else if (N3.Util.isBlank(n3NodeText)) {
            nodeVal = Node({ termType: 'BlankNode', value: n3NodeText })
          }
          newQuad[whichNode] = nodeVal
        }