eyeling 1.7.11 → 1.7.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eyeling.js +70 -5
- package/package.json +1 -1
package/eyeling.js
CHANGED
|
@@ -16,8 +16,20 @@
|
|
|
16
16
|
* 5) Print only newly derived forward facts with explanations.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// -----------------------------------------------------------------------------
|
|
20
|
+
// Browser/Worker-safe version + crypto wiring
|
|
21
|
+
// -----------------------------------------------------------------------------
|
|
22
|
+
let version = 'dev';
|
|
23
|
+
try {
|
|
24
|
+
// Node: keep package.json version if available
|
|
25
|
+
if (typeof require === 'function') version = require('./package.json').version || version;
|
|
26
|
+
} catch (_) {}
|
|
27
|
+
|
|
28
|
+
let nodeCrypto = null;
|
|
29
|
+
try {
|
|
30
|
+
// Node: crypto available
|
|
31
|
+
if (typeof require === 'function') nodeCrypto = require('crypto');
|
|
32
|
+
} catch (_) {}
|
|
21
33
|
|
|
22
34
|
// ===========================================================================
|
|
23
35
|
// Namespace constants
|
|
@@ -6237,7 +6249,7 @@ function proveGoals(goals, subst, facts, backRules, depth, visited, varGen) {
|
|
|
6237
6249
|
// Forward chaining to fixpoint
|
|
6238
6250
|
// ===========================================================================
|
|
6239
6251
|
|
|
6240
|
-
function forwardChain(facts, forwardRules, backRules) {
|
|
6252
|
+
function forwardChain(facts, forwardRules, backRules, onDerived /* optional */) {
|
|
6241
6253
|
ensureFactIndexes(facts);
|
|
6242
6254
|
ensureBackRuleIndexes(backRules);
|
|
6243
6255
|
|
|
@@ -6322,7 +6334,10 @@ function forwardChain(facts, forwardRules, backRules) {
|
|
|
6322
6334
|
if (!hasFactIndexed(facts, instantiated)) {
|
|
6323
6335
|
factList.push(instantiated);
|
|
6324
6336
|
pushFactIndexed(facts, instantiated);
|
|
6325
|
-
|
|
6337
|
+
const df = new DerivedFact(instantiated, r, instantiatedPremises.slice(), { ...s });
|
|
6338
|
+
derivedForward.push(df);
|
|
6339
|
+
if (typeof onDerived === 'function') onDerived(df);
|
|
6340
|
+
|
|
6326
6341
|
changed = true;
|
|
6327
6342
|
}
|
|
6328
6343
|
|
|
@@ -6386,7 +6401,10 @@ function forwardChain(facts, forwardRules, backRules) {
|
|
|
6386
6401
|
|
|
6387
6402
|
factList.push(inst);
|
|
6388
6403
|
pushFactIndexed(facts, inst);
|
|
6389
|
-
|
|
6404
|
+
const df = new DerivedFact(inst, r, instantiatedPremises.slice(), { ...s });
|
|
6405
|
+
derivedForward.push(df);
|
|
6406
|
+
if (typeof onDerived === 'function') onDerived(df);
|
|
6407
|
+
|
|
6390
6408
|
changed = true;
|
|
6391
6409
|
}
|
|
6392
6410
|
}
|
|
@@ -6722,6 +6740,53 @@ function __collectOutputStringsFromFacts(facts, prefixes) {
|
|
|
6722
6740
|
return pairs.map((p) => p.text).join('');
|
|
6723
6741
|
}
|
|
6724
6742
|
|
|
6743
|
+
function reasonStream(n3Text, opts = {}) {
|
|
6744
|
+
const { baseIri = null, proof = false, onDerived = null, includeInputFactsInClosure = true } = opts;
|
|
6745
|
+
|
|
6746
|
+
proofCommentsEnabled = !!proof;
|
|
6747
|
+
|
|
6748
|
+
const toks = lex(n3Text);
|
|
6749
|
+
const parser = new Parser(toks);
|
|
6750
|
+
if (baseIri) parser.prefixes.setBase(baseIri);
|
|
6751
|
+
|
|
6752
|
+
let prefixes, triples, frules, brules;
|
|
6753
|
+
[prefixes, triples, frules, brules] = parser.parseDocument();
|
|
6754
|
+
|
|
6755
|
+
materializeRdfLists(triples, frules, brules);
|
|
6756
|
+
|
|
6757
|
+
// facts becomes the saturated closure because pushFactIndexed(...) appends into it
|
|
6758
|
+
const facts = triples.filter((tr) => isGroundTriple(tr));
|
|
6759
|
+
|
|
6760
|
+
const derived = forwardChain(facts, frules, brules, (df) => {
|
|
6761
|
+
if (typeof onDerived === 'function') {
|
|
6762
|
+
onDerived({
|
|
6763
|
+
triple: tripleToN3(df.fact, prefixes),
|
|
6764
|
+
df,
|
|
6765
|
+
});
|
|
6766
|
+
}
|
|
6767
|
+
});
|
|
6768
|
+
|
|
6769
|
+
const closureTriples = includeInputFactsInClosure ? facts : derived.map((d) => d.fact);
|
|
6770
|
+
|
|
6771
|
+
return {
|
|
6772
|
+
prefixes,
|
|
6773
|
+
facts, // saturated closure (Triple[])
|
|
6774
|
+
derived, // DerivedFact[]
|
|
6775
|
+
closureN3: closureTriples.map((t) => tripleToN3(t, prefixes)).join('\n'),
|
|
6776
|
+
};
|
|
6777
|
+
}
|
|
6778
|
+
|
|
6779
|
+
// Minimal export surface for Node + browser/worker
|
|
6780
|
+
const EYELING_API = { reasonStream };
|
|
6781
|
+
|
|
6782
|
+
try {
|
|
6783
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = EYELING_API;
|
|
6784
|
+
} catch (_) {}
|
|
6785
|
+
|
|
6786
|
+
try {
|
|
6787
|
+
if (typeof self !== 'undefined') self.eyeling = EYELING_API;
|
|
6788
|
+
} catch (_) {}
|
|
6789
|
+
|
|
6725
6790
|
function main() {
|
|
6726
6791
|
// Drop "node" and script name; keep only user-provided args
|
|
6727
6792
|
const argv = process.argv.slice(2);
|