eyeling 1.18.1 → 1.18.2

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.
Files changed (3) hide show
  1. package/HANDBOOK.md +102 -73
  2. package/README.md +1 -1
  3. package/package.json +1 -1
package/HANDBOOK.md CHANGED
@@ -1833,7 +1833,14 @@ The current CLI supports a small set of flags (see `lib/cli.js`):
1833
1833
 
1834
1834
  `rdfjs` is a small built-in RDF/JS `DataFactory`, so browser / worker code can construct quads without pulling in another package first.
1835
1835
 
1836
- ### 14.4 `index.js`: the npm API wrapper
1836
+ ### 14.4 JavaScript API
1837
+
1838
+ Eyeling exposes two JavaScript entry styles:
1839
+
1840
+ - `reason(...)` from `index.js` when you want the same text output as the CLI
1841
+ - `reasonStream(...)` / `reasonRdfJs(...)` from the bundle entry when you want in-process reasoning and structured RDF/JS results
1842
+
1843
+ #### 14.4.1 npm helper: `reason(...)`
1837
1844
 
1838
1845
  The npm `reason(...)` function does something intentionally simple and robust:
1839
1846
 
@@ -1844,119 +1851,141 @@ The npm `reason(...)` function does something intentionally simple and robust:
1844
1851
 
1845
1852
  This keeps the observable output identical to the CLI while still allowing richer JS-side inputs.
1846
1853
 
1847
- In particular, the npm API now accepts:
1854
+ CommonJS:
1848
1855
 
1849
- - raw N3 strings
1850
- - RDF/JS fact inputs (`quads`, `facts`, or `dataset`)
1851
- - Eyeling rule objects or full AST bundles like `[prefixes, triples, frules, brules]`
1852
-
1853
- For structured JavaScript input, rules are supplied as current Eyeling `Rule` / `Triple` object graphs or as JSON-serialized `--ast` output with `_type` markers.
1856
+ ```js
1857
+ const { reason } = require('eyeling');
1854
1858
 
1855
- If you want to use N3 source text, pass the whole input as a plain N3 string.
1859
+ const input = `
1860
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
1861
+ @prefix : <http://example.org/socrates#>.
1856
1862
 
1857
- #### 14.4.1 RDF/JS quads as fact input
1863
+ :Socrates a :Human.
1864
+ :Human rdfs:subClassOf :Mortal.
1858
1865
 
1859
- Eyeling can take RDF/JS quads directly as its fact input. At the npm API boundary, the input object may provide any of:
1866
+ { ?s a ?A. ?A rdfs:subClassOf ?B. } => { ?s a ?B. }.
1867
+ `;
1860
1868
 
1861
- - `quads`
1862
- - `facts`
1863
- - `dataset`
1869
+ console.log(reason({ proofComments: false }, input));
1870
+ ```
1864
1871
 
1865
- Each is treated as an iterable of RDF/JS **default-graph** quads and converted into Eyeling’s internal triple form before reasoning starts.
1872
+ ESM:
1866
1873
 
1867
1874
  ```js
1868
- const { reason, rdfjs } = require('eyeling');
1875
+ import eyeling from 'eyeling';
1869
1876
 
1870
- const input = {
1871
- quads: [
1872
- rdfjs.quad(
1873
- rdfjs.namedNode('http://example.org/Socrates'),
1874
- rdfjs.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
1875
- rdfjs.namedNode('http://example.org/Human'),
1876
- ),
1877
- ],
1878
- n3: `
1879
- @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
1880
- @prefix : <http://example.org/>.
1881
- :Human rdfs:subClassOf :Mortal.
1882
- { ?x a ?c. ?c rdfs:subClassOf ?d. } => { ?x a ?d. }.
1883
- `,
1884
- };
1877
+ const input = `
1878
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
1879
+ @prefix : <http://example.org/socrates#>.
1885
1880
 
1886
- const out = reason(input);
1881
+ :Socrates a :Human.
1882
+ :Human rdfs:subClassOf :Mortal.
1883
+
1884
+ { ?s a ?A. ?A rdfs:subClassOf ?B. } => { ?s a ?B. }.
1885
+ `;
1886
+
1887
+ console.log(eyeling.reason({ proofComments: false }, input));
1887
1888
  ```
1888
1889
 
1889
- The important point is architectural: RDF/JS quads can be used as the **fact channel**, while rules may still come from N3 text or Eyeling rule objects. Named-graph quads are intentionally rejected here; Eyeling’s input model is triple-oriented and expects the default graph only.
1890
+ Notes:
1891
+
1892
+ - `reason()` returns the same textual output you would get from the CLI for the same input and options.
1893
+ - By default, the npm helper keeps output machine-friendly (`proofComments: false`).
1894
+ - Use this path when you want CLI-equivalent behavior inside JavaScript.
1895
+
1896
+ #### 14.4.2 RDF-JS and Eyeling rule-object interoperability
1897
+
1898
+ The JavaScript APIs accept three input styles:
1890
1899
 
1891
- #### 14.4.2 Passing Eyeling rule objects directly
1900
+ 1. plain N3 text
1901
+ 2. RDF/JS fact input (`quads`, `facts`, or `dataset`)
1902
+ 3. Eyeling rule objects or full AST bundles
1892
1903
 
1893
- The JS API also accepts Eyeling rule objects directly, so you do not have to serialize everything back into N3 first.
1904
+ If you want to use N3 source text, pass the whole input as a plain string.
1894
1905
 
1895
- That means an input such as this is valid:
1906
+ For RDF/JS facts, the graph must be the default graph. Named-graph quads are rejected.
1907
+
1908
+ If you already have rules in structured form, Eyeling rule objects can be passed directly in the API:
1896
1909
 
1897
1910
  ```js
1898
- const { reason } = require('eyeling');
1911
+ const { reason, rdfjs } = require('eyeling');
1899
1912
 
1900
- const input = {
1901
- triples: [
1902
- /* Eyeling Triple objects */
1903
- ],
1904
- forwardRules: [
1905
- /* Eyeling Rule objects */
1913
+ const ex = 'http://example.org/';
1914
+
1915
+ const rule = {
1916
+ _type: 'Rule',
1917
+ premise: [
1918
+ {
1919
+ _type: 'Triple',
1920
+ s: { _type: 'Var', name: 'x' },
1921
+ p: { _type: 'Iri', value: ex + 'parent' },
1922
+ o: { _type: 'Var', name: 'y' },
1923
+ },
1906
1924
  ],
1907
- backwardRules: [
1908
- /* optional Eyeling Rule objects */
1925
+ conclusion: [
1926
+ {
1927
+ _type: 'Triple',
1928
+ s: { _type: 'Var', name: 'x' },
1929
+ p: { _type: 'Iri', value: ex + 'ancestor' },
1930
+ o: { _type: 'Var', name: 'y' },
1931
+ },
1909
1932
  ],
1933
+ isForward: true,
1934
+ isFuse: false,
1935
+ headBlankLabels: [],
1910
1936
  };
1911
1937
 
1912
- const out = reason(input);
1913
- ```
1914
-
1915
- The accepted shapes are intentionally flexible:
1938
+ const out = reason(
1939
+ { proofComments: false },
1940
+ {
1941
+ quads: [rdfjs.quad(rdfjs.namedNode(ex + 'alice'), rdfjs.namedNode(ex + 'parent'), rdfjs.namedNode(ex + 'bob'))],
1942
+ rules: [rule],
1943
+ },
1944
+ );
1916
1945
 
1917
- - `triples`
1918
- - `forwardRules` or `frules`
1919
- - `backwardRules` or `brules`
1920
- - `queryRules`, `logQueryRules`, or `qrules`
1921
- - a full AST bundle like `[prefixes, triples, frules, brules, queryRules]`
1946
+ console.log(out);
1947
+ ```
1922
1948
 
1923
- So Eyeling rule objects can be passed directly in the API, either as separate arrays or bundled into the same object graph the parser itself uses.
1949
+ You can also pass a full AST bundle directly, for example `[prefixes, triples, forwardRules, backwardRules]`.
1924
1950
 
1925
- #### 14.4.3 Consuming derived RDF/JS results
1951
+ #### 14.4.3 In-process bundle API: `reasonStream(...)` and `reasonRdfJs(...)`
1926
1952
 
1927
- There are two main ways to consume derived results in RDF/JS form.
1953
+ Use the bundle entry if you want structured results while the engine is running instead of final CLI text after the fact.
1928
1954
 
1929
- First, `reasonStream(...)` can emit RDF/JS quads **while reasoning runs**. Pass `rdfjs: true` and an `onDerived(...)` callback:
1955
+ `reasonStream(...)` can emit RDF/JS quads while reasoning runs:
1930
1956
 
1931
1957
  ```js
1932
- const { reasonStream } = require('eyeling/lib/entry');
1958
+ import eyeling from './eyeling.js';
1933
1959
 
1934
- reasonStream(input, {
1935
- rdfjs: true,
1936
- onDerived({ triple, quad }) {
1937
- // triple = Eyeling's N3 string form
1938
- // quad = RDF/JS Quad for the same derived fact
1960
+ const result = eyeling.reasonStream(input, {
1961
+ proof: false,
1962
+ onDerived: ({ quad }) => {
1963
+ if (quad) console.log(quad);
1939
1964
  },
1940
1965
  });
1941
1966
  ```
1942
1967
 
1943
- This is the “push” interface: each newly derived forward fact is reported as soon as it is produced.
1944
-
1945
- Second, `reasonRdfJs(...)` exposes the same derived results as an **async stream of RDF/JS quads**:
1968
+ That same path also lets derived results be consumed as an async stream of RDF/JS quads:
1946
1969
 
1947
1970
  ```js
1948
- const { reasonRdfJs } = require('eyeling/lib/entry');
1949
-
1950
- for await (const quad of reasonRdfJs(input)) {
1951
- // consume RDF/JS quads incrementally
1971
+ for await (const quad of eyeling.reasonRdfJs(input)) {
1972
+ console.log(quad);
1952
1973
  }
1953
1974
  ```
1954
1975
 
1955
- This is the “pull” interface: the consumer iterates an async iterable of quads instead of registering a callback.
1976
+ Use these entry points when you need one or more of the following:
1977
+
1978
+ - RDF/JS quads as fact input
1979
+ - Eyeling rule objects passed directly from JavaScript
1980
+ - derived results consumed as RDF/JS quads
1981
+ - streaming derived RDF/JS quads during reasoning
1982
+
1983
+ ### 14.5 Choosing the right entry point
1956
1984
 
1957
- One practical implication remains:
1985
+ A practical rule of thumb:
1958
1986
 
1959
- - if you want _in-process_ access to the engine objects (facts arrays, derived proof objects), use `reasonStream` / `reasonRdfJs` from the bundle entry rather than the subprocess-based API.
1987
+ - if you want the same final text output as the CLI, use `reason(...)`
1988
+ - if you want in-process access to structured facts, quads, or streaming derivations, use `reasonStream(...)` / `reasonRdfJs(...)`
1960
1989
 
1961
1990
  ---
1962
1991
 
package/README.md CHANGED
@@ -14,6 +14,6 @@ npx eyeling examples/socrates.n3
14
14
  ## Read more
15
15
 
16
16
  - **Handbook:** [eyereasoner.github.io/eyeling/HANDBOOK](https://eyereasoner.github.io/eyeling/HANDBOOK)
17
- - **Semantics:** [eyereasoner.github.io/eyeling/SEMANTICS](https://eyereasoner.github.io/eyeling/SEMANTICS)
18
17
  - **Playground:** [eyereasoner.github.io/eyeling/demo](https://eyereasoner.github.io/eyeling/demo)
18
+ - **Semantics:** [eyereasoner.github.io/eyeling/SEMANTICS](https://eyereasoner.github.io/eyeling/SEMANTICS)
19
19
  - **Conformance report:** [codeberg.org/phochste/notation3tests/.../report.md](https://codeberg.org/phochste/notation3tests/src/branch/main/reports/report.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [