How to use the rdf-ext.createNamedNode function in rdf-ext

To help you get started, we’ve selected a few rdf-ext 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 rdf2h / rdf2h / dist / rdf2h.js View on Github external
function matchPattern(cfTriplePattern) {
        function isThis(node) {
            return (node && (node.interfaceName === "NamedNode") &&
                    (node.toString() === "http://rdf2h.github.io/2015/rdf2h#this"));
        }
        var s = cfTriplePattern.out("http://rdf2h.github.io/2015/rdf2h#subject").nodes()[0];
        var p = cfTriplePattern.out("http://rdf2h.github.io/2015/rdf2h#predicate").nodes()[0];
        var o = cfTriplePattern.out("http://rdf2h.github.io/2015/rdf2h#object").nodes()[0];
        if (isThis(s)) {
            if (renderee.node.interfaceName === "Literal") {
                if (rdf.createNamedNode(RDF2h.resolveCurie("rdf:type")).equals(p)) {
                    return renderee.node.datatype.equals(o);
                }
            }
            return renderee.graphNode.out(p).nodes().some(function (e) {
                return (!o || o.equals(e));
            });
        } else if (isThis(o)) {
            return renderee.graphNode.in(p).nodes().some(function (e) {
                return (!s || s.equals(e));
            });
        } else {
            console.error("Triple pattern must have r2h:this as subject or object");
        }
    }
    function matchesContext(cfTemplate) {
github simplerdf / simplerdf / examples / get-save.js View on Github external
headline: 'http://schema.org/headline',
  content: 'http://schema.org/content'
}

var blogIri = 'http://example.org/blog'

var blogPostNode = rdf.createBlankNode()

var blogGraph = rdf.createGraph([
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/name'),
    rdf.createLiteral('simple blog')),
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/post'),
    blogPostNode),
  rdf.createTriple(
    blogPostNode,
    rdf.createNamedNode('http://schema.org/headline'),
    rdf.createLiteral('first blog post'))
])

var blogStore = rdf.createStore()

blogStore.add('http://example.org/blog', blogGraph).then(function () {
  return simple(blogContext, blogIri, null, blogStore).get()
}).then(function (blog) {
  console.log('fetched blog from: ' + blog._iri.toString())
  console.log(blog.name)
  console.log(blog.post.shift().headline)
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
return undefined
  }

  if (Array.isArray(value)) {
    return value.map(function (item) {
      return node(item)
    })
  }

  if (typeof value === 'object' && value.interfaceName) {
    return value
  }

  if (typeof value === 'string') {
    if (clownface.options.detectNamedNodes && clownface.options.namedNodeRegEx.test(value)) {
      return rdf.createNamedNode(value)
    } else {
      return rdf.createLiteral(value)
    }
  } else if (typeof value === 'number') {
    return rdf.createLiteral(value + '')
  } else {
    throw new Error('unknown type')
  }
}
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
var unorderedMatchers = new NodeSet();
    var rdfTypeProperty = rdf.createNamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
    var matcherType = rdf.createNamedNode("http://rdf2h.github.io/2015/rdf2h#Matcher");
    var matcherStatements = matcherGraph.match(null, rdfTypeProperty, matcherType);
    matcherStatements.forEach(function(t) {
        unorderedMatchers.add(t.subject);
    });
    /*Sorting:
     * 
     * Choose any matcher that is not the object of any before statement . 
     * Remove all before statements with that matcher as subject. 
     * Repeat till there are no more matchers that are not the object of a 
     * before statement. 
     * If there are matchers left the before statements are circular.
     */   
    var beforeProperty = rdf.createNamedNode("http://rdf2h.github.io/2015/rdf2h#before");
    var beforeStatements = matcherGraph.match(null,beforeProperty);
    beforeStatements.forEach(function(t) {
        unorderedMatchers.add(t.subject);
        unorderedMatchers.add(t.object);
    });
    this.sortedMatchers = [];
    var self = this;
    while (unorderedMatchers.length > 0) {
        if (!unorderedMatchers.some(function(current) {
            if (beforeStatements.match(null, beforeProperty, current).length === 0) {
                self.sortedMatchers.push(current);
                unorderedMatchers.remove(current);
                beforeStatements.removeMatches(current, beforeProperty);
                return true; //stop iteration over unorderedMatchers
            } else {
                return false;
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
function RDF2h(matcherGraph) {
    RDF2h.logger.info("To see more debug output invoke RDF2h.logger.setLevel(Logger.DEBUG) or even RDF2h.logger.setLevel(Logger.TRACE)");
    this.matcherGraph = matcherGraph;
    var unorderedMatchers = new NodeSet();
    var rdfTypeProperty = rdf.createNamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
    var matcherType = rdf.createNamedNode("http://rdf2h.github.io/2015/rdf2h#Matcher");
    var matcherStatements = matcherGraph.match(null, rdfTypeProperty, matcherType);
    matcherStatements.forEach(function(t) {
        unorderedMatchers.add(t.subject);
    });
    /*Sorting:
     * 
     * Choose any matcher that is not the object of any before statement . 
     * Remove all before statements with that matcher as subject. 
     * Repeat till there are no more matchers that are not the object of a 
     * before statement. 
     * If there are matchers left the before statements are circular.
     */   
    var beforeProperty = rdf.createNamedNode("http://rdf2h.github.io/2015/rdf2h#before");
    var beforeStatements = matcherGraph.match(null,beforeProperty);
    beforeStatements.forEach(function(t) {
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
},{}],2:[function(require,module,exports){
var rdf = require("rdf-ext");

function NodeSet() {
    this._g = new rdf.Graph();
    this.length = 0;
};

NodeSet._filler = rdf.createNamedNode("http://ignored/");

NodeSet._node2Triple = function(node) {
    return rdf.createTriple(node, NodeSet._filler, NodeSet._filler);
};

NodeSet.prototype.add = function(node) {
    this._g.add(NodeSet._node2Triple(node));
    this.length = this._g.length;
};

NodeSet.prototype.remove = function(node) {
    this._g.removeMatches(node, NodeSet._filler, NodeSet._filler);
    this.length = this._g.length;
};

NodeSet.prototype.contains = function(node) {
github rdf2h / rdf2h / dist / rdf2h.js View on Github external
RDF2h.prototype.render = function (graph, node, context, startMatcherIndex) {
    if (!node.interfaceName) {
        node = rdf.createNamedNode(node);
    }
    if (!context) {
        context = RDF2h.resolveCurie("r2h:Default");
    }
    //wrap all in one object that gets special care by lookup
    var renderee = new RDF2h.Renderee(this, graph, node, context);
    if (!startMatcherIndex) {
        this.startMatcherIndex = 0;
    } else {
        this.startMatcherIndex = startMatcherIndex;
    }
    var renderer = this.getRenderer(renderee);
    return renderer(renderee);
}
github simplerdf / simplerdf / lib / core.js View on Github external
static buildIri (iri) {
    if (typeof iri === 'string') {
      return rdf.createNamedNode(iri)
    } else {
      return iri || rdf.createBlankNode()
    }
  }
}
github simplerdf / simplerdf / examples / get-save.js View on Github external
name: 'http://schema.org/name',
  post: {
    '@id': 'http://schema.org/post',
    '@container': '@set'
  },
  headline: 'http://schema.org/headline',
  content: 'http://schema.org/content'
}

var blogIri = 'http://example.org/blog'

var blogPostNode = rdf.createBlankNode()

var blogGraph = rdf.createGraph([
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/name'),
    rdf.createLiteral('simple blog')),
  rdf.createTriple(
    rdf.createNamedNode(blogIri),
    rdf.createNamedNode('http://schema.org/post'),
    blogPostNode),
  rdf.createTriple(
    blogPostNode,
    rdf.createNamedNode('http://schema.org/headline'),
    rdf.createLiteral('first blog post'))
])

var blogStore = rdf.createStore()

blogStore.add('http://example.org/blog', blogGraph).then(function () {
  return simple(blogContext, blogIri, null, blogStore).get()