eyereasoner 2.9.4 → 2.10.1

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 CHANGED
@@ -9,94 +9,81 @@ Distributing the [EYE](https://github.com/eyereasoner/eye) reasoner for browser
9
9
 
10
10
  ## Usage
11
11
 
12
- The simplest way to use this package is to execute a query over a dataset and get the results
13
-
14
- **Note**: the `dataQuads` should include any inference rules that you wish to apply to the dataset
12
+ The simplest way to use this package is to use the `n3reasoner` to execute a query over a dataset and get the results. The input `data` should include the data and any inference rules that you wish to apply to the dataset; the optional `query` should match the pattern of data you wish the engine to return; if left undefined, all inferred facts will be returned. For example:
15
13
 
16
14
  ```ts
17
- import { basicQuery } from 'eyereasoner';
15
+ import { n3reasoner } from 'eyereasoner';
18
16
 
19
- async function main() {
20
- // The result of the query (as an array of quads)
21
- const result = await basicQuery(dataQuads, queryQuads);
22
- }
17
+ export const queryString = `
18
+ @prefix : <http://example.org/socrates#>.
23
19
 
24
- main();
20
+ {:Socrates a ?WHAT} => {:Socrates a ?WHAT}.
21
+ `;
22
+
23
+ export const dataString = `
24
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
25
+ @prefix : <http://example.org/socrates#>.
26
+
27
+ :Socrates a :Human.
28
+ :Human rdfs:subClassOf :Mortal.
29
+
30
+ {?A rdfs:subClassOf ?B. ?S a ?A} => {?S a ?B}.
31
+ `;
32
+
33
+ // The result of the query (as a string)
34
+ const resultString = await n3reasoner(dataString, queryString);
35
+
36
+ // All inferred data
37
+ const resultString = await n3reasoner(dataString);
25
38
  ```
26
39
 
27
- or if you just wish to get all inferred facts
40
+ The `n3reasoner` accepts both `string`s (formatted in Notation3 syntax) and `quad`s as input. The output will be of the same type as the input `data`. This means that we can use `n3reasoner` with RDF/JS quads as follows:
28
41
 
29
42
  ```ts
30
- import { basicQuery } from 'eyereasoner';
43
+ import { Parser } from 'n3';
31
44
 
32
- async function main() {
33
- // The result of the query (as an array of quads)
34
- const result = await basicQuery(dataQuads);
35
- }
45
+ const parser = new Parser({ format: 'text/n3' });
46
+ export const queryQuads = parser.parse(queryString);
47
+ export const dataQuads = parser.parse(dataString);
36
48
 
37
- main();
49
+ // The result of the query (as an array of quads)
50
+ const resultQuads = await n3reasoner(dataQuads, queryQuads);
38
51
  ```
39
52
 
40
- Here the inputs and outputs are both arrays of RDF/JS Quads; for instance
53
+ ### Options
54
+
55
+ The `n3reasoner` function allows one to optionally pass along a set of options
41
56
 
42
57
  ```ts
43
- const queryQuads = [
44
- DF.quad(
45
- DF.namedNode('http://example.org/socrates#Socrates'),
46
- DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
47
- DF.variable('WHAT'),
48
- DF.blankNode('b1')
49
- ),
50
- DF.quad(
51
- DF.namedNode('http://example.org/socrates#Socrates'),
52
- DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
53
- DF.variable('WHAT'),
54
- DF.blankNode('b2')
55
- ),
56
- DF.quad(
57
- DF.blankNode('b1'),
58
- DF.namedNode('http://www.w3.org/2000/10/swap/log#implies'),
59
- DF.blankNode('b2')
60
- )
61
- ]
62
-
63
- const dataQuads = [
64
- DF.quad(
65
- DF.namedNode('http://example.org/socrates#Socrates'),
66
- DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
67
- DF.namedNode('http://example.org/socrates#Human'),
68
- ),
69
- DF.quad(
70
- DF.namedNode('http://example.org/socrates#Human'),
71
- DF.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'),
72
- DF.namedNode('http://example.org/socrates#Mortal'),
73
- ),
74
- DF.quad(
75
- DF.variable('A'),
76
- DF.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'),
77
- DF.variable('B'),
78
- DF.blankNode('b1')
79
- ),
80
- DF.quad(
81
- DF.variable('S'),
82
- DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
83
- DF.variable('A'),
84
- DF.blankNode('b1')
85
- ),
86
- DF.quad(
87
- DF.variable('S'),
88
- DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
89
- DF.variable('B'),
90
- DF.blankNode('b2')
91
- ),
92
- DF.quad(
93
- DF.blankNode('b1'),
94
- DF.namedNode('http://www.w3.org/2000/10/swap/log#implies'),
95
- DF.blankNode('b2')
96
- ),
97
- ]
58
+ import { n3reasoner } from 'eyereasoner';
59
+
60
+ const data = `
61
+ @prefix : <urn:example.org:> .
62
+ :Alice a :Person .
63
+ { ?S a :Person } => { ?S a :Human } .
64
+ `;
65
+
66
+ const result = await n3reasoner(data, undefined, {
67
+ output: 'derivations',
68
+ blogic: false,
69
+ outputType: 'string'
70
+ });
98
71
  ```
99
72
 
73
+ The `options` parameter can be used to configure the reasoning process. The following options are available:
74
+ - `output`: What to output with implicit queries.
75
+ - undefined: no implicit query is passed (default)
76
+ - `derivations`: output only new derived triples, a.k.a `--pass-only-new`
77
+ - `deductive_closure`: output deductive closure, a.k.a `--pass`
78
+ - `deductive_closure_plus_rules`: output deductive closure plus rules, a.k.a `--pass-all`
79
+ - `grounded_deductive_closure_plus_rules`: ground the rules and output deductive closure plus rules, a.k.a `--pass-all-ground`
80
+ - `blogic`: Whether to use the blogic or not. Used to support [RDF surfaces](https://w3c-cg.github.io/rdfsurfaces/).
81
+ - `true`: use blogic
82
+ - `false`: do not use blogic (default)
83
+ - `outputType`: The type of output (if different from the input)
84
+ - `string`: output as string
85
+ - `quads`: output as array of RDF/JS Quads
86
+
100
87
  ## Advanced usage
101
88
 
102
89
  To have more granular control one can also use this module as follows
@@ -223,6 +210,22 @@ We provide some examples of using `eyereasoner`:
223
210
  - Using as an npm package and bundling using webpack ([`./examples/rollup`](https://github.com/eyereasoner/eye-js/tree/main/examples/rollup)).
224
211
  - Using a prebuilt version of `eyereasoner` ([`./examples/prebuilt`](https://github.com/eyereasoner/eye-js/tree/main/examples/prebuilt)) - this example is [deployed on github pages](https://eyereasoner.github.io/eye-js/example/index.html).
225
212
 
213
+ ## Other Notes
214
+
215
+ ### `MaxListenersExceededWarning`
216
+
217
+ If you instantiate `SWIPL` more than 10 times in the same process, then you may see the warning:
218
+
219
+ ```
220
+ (node:29436) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit
221
+ ```
222
+
223
+ this is caused by the fact that each instantiation of SWIPL adds a new listener to the global process. To fix this problem increase the maximum number of listeners allowed on the global process.
224
+
225
+ ```
226
+ process.setMaxListeners(100)
227
+ ```
228
+
226
229
  ## License
227
230
  ©2022–present
228
231
  [Jesse Wright](https://github.com/jeswr),