A compact Notation3 (N3) reasoner in JavaScript.
eyeling.js), no external runtime dependencies=>) and backward (<=) chaining over Horn-style rulesreason() output is mode-dependent by default: it prints newly derived forward facts in normal mode, or (when top-level { ... } log:query { ... }. directives are present) the unique instantiated conclusion triples of those queries, optionally with compact proof commentsEyeling is regularly checked against the community Notation3 test suite. If you want implementation details (parser, unifier, proof search, skolemization, scoped closure, builtins), start with the handbook.
npm i eyeling
Run on a file:
npx eyeling examples/socrates.n3
Show all options:
npx eyeling --help
Useful flags include --proof-comments, --stream, --strings, and --enforce-https.
Without top-level log:query directives, Eyeling prints newly derived forward facts by default.
log:query mode (output selection)If the input contains one or more top-level directives of the form:
{ ?x a :Human. } log:query { ?x a :Mortal. }.
Eyeling still computes the saturated forward closure, but it prints only the unique instantiated conclusion triples of those log:query directives (instead of all newly derived forward facts).
reason()CommonJS:
const { reason } = require('eyeling');
const input = `
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix : <http://example.org/socrates#>.
:Socrates a :Human.
:Human rdfs:subClassOf :Mortal.
{ ?s a ?A. ?A rdfs:subClassOf ?B. } => { ?s a ?B. }.
`;
console.log(reason({ proofComments: false }, input));
ESM:
import eyeling from 'eyeling';
console.log(eyeling.reason({ proofComments: false }, input));
Notes:
reason() returns the same textual output you would get from the CLI for the same input/options.proofComments: false).eyeling.js CLI for simplicity and robustness.reasonStream()For in-process reasoning (browser, worker, or direct use of eyeling.js):
const result = eyeling.reasonStream(input, {
proof: false,
onDerived: ({ triple }) => console.log(triple),
// includeInputFactsInClosure: false,
});
console.log(result.closureN3);
reasonStream() output behaviorclosureN3 is also mode-dependent:
closureN3 is the closure (input facts + derived facts)log:query mode: closureN3 is the query-selected triplesTo exclude input facts from the normal-mode closure, pass:
includeInputFactsInClosure: false;
The returned object also includes queryMode, queryTriples, and queryDerived (and in normal mode, onDerived fires for newly derived facts; in log:query mode it fires for the query-selected derived triples).
Builtins are defined in eyeling-builtins.ttl and described in the Handbook (Chapter 11).
npm test
You can also inspect the examples/ directory for many small and large N3 programs.
MIT — see LICENSE.md.