package
A simple reasoner for linked data
npm install reasonerGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
A simple linked data reasoner...
This module began life as part of the ActivityStrea.ms implementation (http://github.com/jasnell/activitystrea.ms).
This module requires Node.js 4.0.0 and uses ES6 language features.
npm install reasonerconst rdf = require('linkeddata-vocabs').rdf;
const Reasoner = require('reasoner');
const Graph = Reasoner.Graph;
const graph = new Graph();
graph.add({
subject: 'http://example.org/foo',
predicate: rdf.type,
object: 'http://example.org/bar'
});
graph.add({
subject: 'http://example.org/foo',
predicate: rdf.type,
object: 'http://example.org/baz'
});
graph.add({
subject: 'http://example.org/foo',
predicate: rdfs.subClassOf,
object: 'http://example.org/boo'
});
graph.add({
subject: 'http://example.org/boo',
predicate: rdfs.subClassOf,
object: 'http://example.org/aaa'
});
graph.add({
subject: 'http://example.org/aaa',
predicate: rdfs.subClassOf,
object: 'http://example.org/ccc'
});
graph.add({
subject: 'http://example.org/bar',
predicate: rdfs.subClassOf,
object: 'http://example.org/aaa'
});
graph.add({
Reasoner([graph])Creates a new Reasoner. Either a single Reasoner.Graph instance, or an array
of Reasoner.Graph instances can be provided to the constructor to be bound
automatically when the Reasoner is created.
<number> Reasoner.prototype.sizeThe total number of triples known to the Reasoner.
Reasoner.prototype.bind(graph)Binds a single Reasoner.Graph instance to the Reasoner.
<Reasoner.Node> Reasoner.prototype.node(uri)Returns a Reasoner.Node instance. A Node represents a single subject known to
the Reasoner.
<Reasoner.Literal> Reasoner.prototype.literal(value[, options])Utility method that creates new Reasoner.Literal
Reasoner.Graph()Creates a new Reasoner.Graph instance. A Graph is essentially a thin wrapper
around an N3.Store object.
<number> Reasoner.Graph.prototype.sizeReturns the total number of triples known to the Graph.
Reasoner.Graph.prototype.add(triple)Adds a single triple to the Graph. The argument is an object with three
properties: subject, predicate and object.
const Graph = require('reasoner').Graph;
const graph = new Graph();
graph.add({
subject: 'http://example.org/foo',
predicate: 'http://example.org/bar',
object: 'http://example.org/baz'
});Reasoner.Graph.prototype.merge(graph)Merge the specified Graph into this Graph.
Reasoner.Graph.prototype.find(triple)Search the Graph for triples matching the specified pattern.
const Graph = require('reasoner').Graph;
const graph = new Graph();
graph.add({
subject: 'http://example.org/foo',
predicate: 'http://example.org/bar',
object: 'http://example.org/baz'
});
const triples = graph.find({subject:'http://example.org/foo'});
for (const triple of triples) {
console.log(triple);
}Reasoner.NodeThe Reasoner.Node object provides access to explicit and inferred information
about a single subject known to the Reasoner.
const Reasoner = require('reasoner');
const Graph = Reasoner.Graph;
const graph = new Graph();
graph.add({
subject: 'http://example.org/foo',
predicate: 'http://example.org/bar',
object: 'http://example.org/baz'
});
const reasoner = new Reasoner(graph);
const node = reasoner.node('http://example.org/foo');
// ...Reasoner.Node.prototype.idThe Subject URI
Reasoner.Node.prototype.findInbound(predicate)Searches for all triples known to the Reasoner for which this node is the object.
Reasoner.Node.prototype.find(predicate)Searches for all triples known to the Reasoner for which this node is the subject.
Reasoner.Node.prototype.literal(predicate)Searches for literal values with the specified predicate.
var literals = node.literal('http://example.org/label');
for (let literal of literals) {
console.log(literal.valueOf());
console.log(literal.type);
console.log(literal.language);
};Reasoner.Node.prototype.typesThe collection of rdf:type explicitly defined for this subject.
Reasoner.Node.prototype.subPropertiesA listing of Reasoner.Node objects representing other subjects defined as
rdfs:subPropertyOf this subject.
Reasoner.Node.prototype.subClassesA listing of Reasoner.Node objects representing other
subjects defined as rdfs:subClassOf this subject.
Reasoner.Node.prototype.superPropertiesA listing of Reasoner.Node objects representing other
subjects for which this node can be considered a sub-property.
Reasoner.Node.prototype.superClassesA listing of Reasoner.Node objects representing other
subjects for which this node can be considered a sub-class.
Reasoner.Node.prototype.is(type)Returns true if this subject can be considered to be an instance of the
specified type. Specifically, this will return true if:
rdf:type typerdf:type's is typerdfs:subClassOf typetyperdfs:subPropertyOf typetypeReasoner.LiteralRepresents a literal value.
Reasoner.Literal.prototype.valueOf()Returns the value of the literal.
<Reasoner.Node> Reasoner.Literal.prototype.typeA Reasoner.Node representing the Literal type.
<LanguageTag> Reasoner.Literal.prototype.languageA LanguageTag representing the Literal language. (The LanguageTag object is
provided by the rfc5646 module in npm)
Estimated unpacked size across 16 packages.
1.4 MB
Includes dependencies.
6 direct · 1 outdated
^0.11.2
2.13.12
^3.0.0
3.0.0
^0.11.1
0.11.1
^0.11.1
0.11.1
^0.11.1
0.11.1
^0.11.1
0.11.1