eyeling 1.5.27 → 1.5.29
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/README.md +42 -46
- package/examples/easter.n3 +78 -0
- package/examples/output/easter.n3 +3602 -0
- package/eyeling.js +110 -10
- package/package.json +1 -1
- package/test/api.test.js +36 -0
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ A minimal [Notation3 (N3)](https://notation3.org/) reasoner in **JavaScript**.
|
|
|
9
9
|
- a practical N3/Turtle superset (enough for lots of real rulesets)
|
|
10
10
|
- supports forward (`=>`) + backward (`<=`) chaining over Horn-style rules
|
|
11
11
|
- prints only newly derived forward facts, optionally preceded by compact proof comments
|
|
12
|
-
- we never want to leak raw data
|
|
13
|
-
-
|
|
12
|
+
- “pass-only-new” style output (we never want to leak raw input data; backward rules can act like “functions” over raw data)
|
|
13
|
+
- works fully client-side (browser) and in Node.js
|
|
14
14
|
|
|
15
15
|
## Playground (in your browser)
|
|
16
16
|
|
|
@@ -75,14 +75,13 @@ ESM:
|
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
77
|
import eyeling from "eyeling";
|
|
78
|
-
|
|
79
78
|
const output = eyeling.reason({ proofComments: false }, input);
|
|
80
79
|
console.log(output);
|
|
81
80
|
```
|
|
82
81
|
|
|
83
82
|
Note: the API currently shells out to the bundled `eyeling.js` CLI under the hood (simple + robust).
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
## Testing
|
|
86
85
|
|
|
87
86
|
From a repo checkout:
|
|
88
87
|
|
|
@@ -99,10 +98,10 @@ npm run test:package
|
|
|
99
98
|
npm run test:packlist
|
|
100
99
|
```
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
* `test:api` runs an independent JS API test suite (does not rely on `examples/`).
|
|
102
|
+
* `test:examples` runs the examples in the `examples` directory and compares against the golden outputs in `examples/output`.
|
|
103
|
+
* `test:package` does a “real consumer” smoke test: `npm pack` → install tarball into a temp project → run API + CLI + examples.
|
|
104
|
+
* `test:packlist` sanity-checks what will be published in the npm tarball (and the CLI shebang/bin wiring).
|
|
106
105
|
|
|
107
106
|
### Run a single file
|
|
108
107
|
|
|
@@ -134,15 +133,6 @@ node eyeling.js --no-proof-comments examples/socrates.n3
|
|
|
134
133
|
node eyeling.js -n examples/socrates.n3
|
|
135
134
|
```
|
|
136
135
|
|
|
137
|
-
### Run all examples
|
|
138
|
-
|
|
139
|
-
```bash
|
|
140
|
-
npm run test:examples
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
This runs `eyeling.js` over each example and compares against the golden outputs in `examples/output`
|
|
144
|
-
(works both in a git checkout and in an npm-installed package).
|
|
145
|
-
|
|
146
136
|
## What output do I get?
|
|
147
137
|
|
|
148
138
|
For each newly derived triple, `eyeling` prints:
|
|
@@ -156,14 +146,14 @@ The proof comments are compact “local justifications” per derived triple (no
|
|
|
156
146
|
|
|
157
147
|
### Forward + backward chaining
|
|
158
148
|
|
|
159
|
-
|
|
160
|
-
|
|
149
|
+
* **Forward chaining to fixpoint** for forward rules written as `{ P } => { C } .`
|
|
150
|
+
* **Backward chaining (SLD-style)** for backward rules written as `{ H } <= { B } .` and for built-ins.
|
|
161
151
|
|
|
162
152
|
Forward rule premises are proved using:
|
|
163
153
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
154
|
+
* ground facts (input + derived)
|
|
155
|
+
* backward rules
|
|
156
|
+
* built-ins
|
|
167
157
|
|
|
168
158
|
The CLI prints only newly derived forward facts.
|
|
169
159
|
|
|
@@ -182,24 +172,30 @@ The CLI prints only newly derived forward facts.
|
|
|
182
172
|
|
|
183
173
|
Supported:
|
|
184
174
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
175
|
+
* `@prefix` / `@base`
|
|
176
|
+
* triples with `;` and `,`
|
|
177
|
+
* variables `?x`
|
|
178
|
+
* blank nodes:
|
|
179
|
+
|
|
180
|
+
* anonymous `[]`
|
|
181
|
+
* property lists `[ :p :o; :q :r ]`
|
|
182
|
+
* collections `( ... )`
|
|
183
|
+
* quoted formulas `{ ... }`
|
|
184
|
+
* implications:
|
|
185
|
+
|
|
186
|
+
* forward rules `{ P } => { C } .`
|
|
187
|
+
* backward rules `{ H } <= { B } .`
|
|
188
|
+
* datatyped literals with `^^`
|
|
189
|
+
* language-tagged string literals: `"hello"@en`, `"colour"@en-GB`
|
|
190
|
+
* long string literals: `"""..."""` (can contain newlines; can also carry a language tag)
|
|
191
|
+
* inverted predicate sugar: `?x <- :p ?y` (swaps subject/object for that predicate)
|
|
192
|
+
* resource paths (forward `!` and reverse `^`): `:joe!:hasAddress!:hasCity "Metropolis".`
|
|
193
|
+
* `#` line comments
|
|
198
194
|
|
|
199
195
|
Non-goals / current limits:
|
|
200
196
|
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
* not a full W3C N3 grammar (some edge cases for identifiers, quantifiers, advanced syntax)
|
|
198
|
+
* proof output is local per derived triple (not a global exported proof tree)
|
|
203
199
|
|
|
204
200
|
## Blank nodes and quantification (pragmatic N3/EYE-style)
|
|
205
201
|
|
|
@@ -217,12 +213,12 @@ Equal facts up to renaming of Skolem IDs are treated as duplicates and are not r
|
|
|
217
213
|
|
|
218
214
|
Top level:
|
|
219
215
|
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
* `{ P } log:implies { C } .` becomes a forward rule `{ P } => { C } .`
|
|
217
|
+
* `{ H } log:impliedBy { B } .` becomes a backward rule `{ H } <= { B } .`
|
|
222
218
|
|
|
223
219
|
During reasoning:
|
|
224
220
|
|
|
225
|
-
|
|
221
|
+
* any **derived** `log:implies` / `log:impliedBy` triple with formula subject/object is turned into a new live forward/backward rule.
|
|
226
222
|
|
|
227
223
|
## Inference fuse — `{ ... } => false.`
|
|
228
224
|
|
|
@@ -241,12 +237,12 @@ As soon as the premise is provable, `eyeling` exits with status code `2`.
|
|
|
241
237
|
|
|
242
238
|
`eyeling` implements a pragmatic subset of common N3 builtin families and evaluates them during backward goal proving:
|
|
243
239
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
240
|
+
* **crypto**: `crypto:md5` `crypto:sha` `crypto:sha256` `crypto:sha512`
|
|
241
|
+
* **list**: `list:append` `list:first` `list:firstRest` `list:in` `list:iterate` `list:last` `list:length` `list:map` `list:member` `list:memberAt` `list:notMember` `list:remove` `list:rest` `list:reverse` `list:sort`
|
|
242
|
+
* **log**: `log:collectAllIn` `log:equalTo` `log:forAllIn` `log:impliedBy` `log:implies` `log:notEqualTo` `log:notIncludes` `log:skolem` `log:uri`
|
|
243
|
+
* **math**: `math:absoluteValue` `math:acos` `math:asin` `math:atan` `math:cos` `math:cosh` `math:degrees` `math:difference` `math:equalTo` `math:exponentiation` `math:greaterThan` `math:integerQuotient` `math:lessThan` `math:negation` `math:notEqualTo` `math:notGreaterThan` `math:notLessThan` `math:product` `math:quotient` `math:remainder` `math:rounded` `math:sin` `math:sinh` `math:sum` `math:tan` `math:tanh`
|
|
244
|
+
* **string**: `string:concatenation` `string:contains` `string:containsIgnoringCase` `string:endsWith` `string:equalIgnoringCase` `string:format` `string:greaterThan` `string:lessThan` `string:matches` `string:notEqualIgnoringCase` `string:notGreaterThan` `string:notLessThan` `string:notMatches` `string:replace` `string:scrape` `string:startsWith`
|
|
245
|
+
* **time**: `time:localTime`
|
|
250
246
|
|
|
251
247
|
## License
|
|
252
248
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# =====================================================================
|
|
2
|
+
# Easter Date
|
|
3
|
+
# Calculation of easter dates.
|
|
4
|
+
# original copy at http://www.w3.org/2000/10/swap/test/easter/easter.n3
|
|
5
|
+
# =====================================================================
|
|
6
|
+
|
|
7
|
+
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
|
|
8
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
|
|
9
|
+
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
|
|
10
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
|
11
|
+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
|
|
12
|
+
@prefix prolog: <http://eulersharp.sourceforge.net/2003/03swap/prolog#>.
|
|
13
|
+
@prefix : <http://www.agfa.com/w3c/euler/easterP#>.
|
|
14
|
+
|
|
15
|
+
<> rdfs:comment """
|
|
16
|
+
Divide by Quotient Remainder
|
|
17
|
+
---------------------------------------------------
|
|
18
|
+
y 19 j
|
|
19
|
+
y 100 k h
|
|
20
|
+
k 4 m n
|
|
21
|
+
k + 8 25 p
|
|
22
|
+
k - p + 1 3 q
|
|
23
|
+
19j + k - m - q + 15 30 r
|
|
24
|
+
h 4 s u
|
|
25
|
+
32 + 2n + 2s - r - u 7 v
|
|
26
|
+
j + 11r + 22v 451 w
|
|
27
|
+
r + v - 7w + 114 31 x z
|
|
28
|
+
|
|
29
|
+
Here x is the number of the month ond 1 + z is the day of that
|
|
30
|
+
month upon which Easter Sunday falls in the year y.
|
|
31
|
+
""".
|
|
32
|
+
|
|
33
|
+
2021 a :Year.
|
|
34
|
+
2022 a :Year.
|
|
35
|
+
2023 a :Year.
|
|
36
|
+
2024 a :Year.
|
|
37
|
+
2025 a :Year.
|
|
38
|
+
2026 a :Year.
|
|
39
|
+
2027 a :Year.
|
|
40
|
+
2028 a :Year.
|
|
41
|
+
2029 a :Year.
|
|
42
|
+
2030 a :Year.
|
|
43
|
+
2031 a :Year.
|
|
44
|
+
2032 a :Year.
|
|
45
|
+
2033 a :Year.
|
|
46
|
+
2034 a :Year.
|
|
47
|
+
2035 a :Year.
|
|
48
|
+
2036 a :Year.
|
|
49
|
+
2037 a :Year.
|
|
50
|
+
2038 a :Year.
|
|
51
|
+
2039 a :Year.
|
|
52
|
+
2040 a :Year.
|
|
53
|
+
2041 a :Year.
|
|
54
|
+
2042 a :Year.
|
|
55
|
+
2043 a :Year.
|
|
56
|
+
2044 a :Year.
|
|
57
|
+
2045 a :Year.
|
|
58
|
+
2046 a :Year.
|
|
59
|
+
2047 a :Year.
|
|
60
|
+
2048 a :Year.
|
|
61
|
+
2049 a :Year.
|
|
62
|
+
2050 a :Year.
|
|
63
|
+
|
|
64
|
+
{ ?Y a :Year.
|
|
65
|
+
(?Y 19) math:remainder ?J.
|
|
66
|
+
(?Y 100) math:integerQuotient ?K; math:remainder ?H.
|
|
67
|
+
(?K 4) math:integerQuotient ?M; math:remainder ?N.
|
|
68
|
+
((?K 8)!math:sum 25) math:integerQuotient ?P.
|
|
69
|
+
(((?K ?P)!math:difference 1)!math:sum 3) math:integerQuotient ?Q.
|
|
70
|
+
((((((19 ?J)!math:product ?K)!math:sum ?M)!math:difference ?Q)!math:difference 15)!math:sum 30) math:remainder ?R.
|
|
71
|
+
(?H 4) math:integerQuotient ?S; math:remainder ?U.
|
|
72
|
+
((32 (2 ?N)!math:product (2 ?S)!math:product ?R!math:negation ?U!math:negation)!math:sum 7) math:remainder ?V.
|
|
73
|
+
((?J (11 ?R)!math:product (22 ?V)!math:product)!math:sum 451) math:integerQuotient ?W.
|
|
74
|
+
((?R ?V (7 ?W)!math:product!math:negation 114)!math:sum 31) math:integerQuotient ?X; math:remainder ?Z.
|
|
75
|
+
(?Z 1) math:sum ?DAY.
|
|
76
|
+
} => {
|
|
77
|
+
(?DAY ?X) :easterFor ?Y.
|
|
78
|
+
}.
|