Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
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)
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')
}
}
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;
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) {
},{}],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) {
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);
}
static buildIri (iri) {
if (typeof iri === 'string') {
return rdf.createNamedNode(iri)
} else {
return iri || rdf.createBlankNode()
}
}
}
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()