eyemind 0.8.0 → 0.8.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.
package/README.md CHANGED
@@ -605,24 +605,57 @@ records carrying focus node, source shape, constraint component and severity,
605
605
  plus path, value and supplied messages where applicable. Complex result
606
606
  paths retain their RDF definitions in the report.
607
607
 
608
- Implemented SHACL Core families include all four explicit targets and
609
- implicit class targets; class, datatype and node-kind constraints; counts,
610
- bounds, lengths, patterns and language constraints; sets, property pairs and
611
- closed shapes; nested properties, node/not/and/or/xone, and qualified counts
612
- with disjoint siblings. Predicate, inverse, sequence, alternative and repeated
613
- paths compute distinct values and terminate on data cycles. Repeated `xone`
614
- members count separately. Deactivated shapes conform without validation.
615
-
616
- This is a documented Core subset, not a claim of full W3C SHACL conformance.
608
+ SHACL 1.2 Core is implemented: node, class, subjects-of, objects-of and where
609
+ targets, `sh:shape` links in the data, and implicit class targets including
610
+ `sh:ShapeClass`; class, datatype, node-kind and root-class constraints, each
611
+ also with a list of alternatives; counts, bounds, lengths, patterns, single
612
+ lines and language constraints; SHACL list members, lengths and uniqueness;
613
+ sets, unique values for targets, property pairs over any path, and closed
614
+ shapes, also `sh:ByTypes`; nested properties, node/not/and/or/xone,
615
+ `sh:someValue`, reifier shapes and qualified counts with disjoint siblings.
616
+ Node expressions in `sh:values`, `sh:defaultValue`, `sh:targetNode` and
617
+ `sh:deactivated` compute value nodes, targets and deactivation. Predicate,
618
+ inverse, sequence, alternative and repeated paths compute distinct values and
619
+ terminate on data cycles. Repeated `xone` members count separately.
620
+
621
+ A reifier of a constraint triple can deactivate that constraint or give it its
622
+ own `sh:severity` and `sh:message`. Each validation of a focus node is a
623
+ separate result, so a nested shape reached by two routes reports twice, and
624
+ `sh:lessThan` reports each incomparable pair. Results whose severity is outside
625
+ the conformance-disallow set (`sh:Violation`, `sh:Warning` and `sh:Info` by
626
+ default) are reported but do not make a node or the report nonconforming; a
627
+ library caller can pass another set as `disallows`, which the report then
628
+ lists as `sh:conformanceDisallows`. Only the boolean `true` activates a
629
+ boolean parameter. Deactivated shapes conform without validation.
630
+
631
+ SHACL 1.2 node expressions compile to LS as well: constants, lists, variables,
632
+ paths, `exists`, `if`, distinct, intersection, concat, remove, filter,
633
+ limit, offset, order, flat map, find-first and match-all, counts and other
634
+ aggregates, `instancesOf`, `nodesMatching` and `conformsToShape`, the
635
+ `sparql:` functions, and custom named and list parameter functions. An
636
+ expression gives its output nodes in order, or an evaluation failure that the
637
+ enclosing expression propagates. `sh:expression` and `sh:nodeByExpression`
638
+ constrain value nodes with them, and report the expression or shape as
639
+ `sh:sourceConstraint`. A library caller can evaluate one expression with
640
+ `compileRdfLogic(graph, { profiles: ['shacl'], evaluate: { expression, focus,
641
+ scope } })`, which answers `sh_evaluation(nodes(List))` or
642
+ `sh_evaluation('failure')`. `sparql:now`, `rand`, `uuid` and `struuid` read a
643
+ captured clock and seed, so checking such a proof from its source recompiles
644
+ another context and fails.
645
+
617
646
  Shapes and path definitions must be present in the input; inference may add
618
- data and targets, but cannot dynamically define new constraints. Recursive
619
- shape dependencies, SHACL-SPARQL, JavaScript constraints, rules, custom
620
- targets and SHACL 1.2 additions are rejected when used by active shapes.
647
+ data and targets, but cannot dynamically define new constraints. A shape
648
+ selected at evaluation time, by `sh:nodeByExpression` or `conformsToShape`,
649
+ cannot itself use `sh:expression`, `sh:nodeByExpression` or expression-valued
650
+ parameters. Recursive shape dependencies, SHACL-SPARQL, JavaScript
651
+ constraints and rules are outside the implementation. An evaluation failure
652
+ in validation is not reported separately. Active shapes with unsupported
653
+ constraint predicates are rejected.
621
654
 
622
655
  Datatype checks support XSD integer subtypes, decimal, float/double, boolean,
623
656
  string/normalizedString/token/language/anyURI, hex/base64 binary,
624
- date/dateTime/dateTimeStamp/time and RDF language strings. Other requested
625
- datatypes raise an error. Numeric bounds use exact integers/decimals with
657
+ date/dateTime/dateTimeStamp/time and RDF language strings; a literal of
658
+ another datatype matches that datatype's IRI. Numeric bounds use exact integers/decimals with
626
659
  SPARQL promotion for binary floats; string and same-kind temporal bounds
627
660
  are also supported. Temporal fractions remain exact. Timezones compare
628
661
  when both values have one or both omit one; a mixed pair is incomparable.
@@ -637,6 +670,33 @@ errors instead of a conforming report.
637
670
  Try the [directory](https://eyereasoner.github.io/eyemind/examples/deck/people-shacl)
638
671
  and [normalized speed readings](https://eyereasoner.github.io/eyemind/examples/deck/measurement-shacl).
639
672
 
673
+ The [W3C SHACL 1.2 manifest](https://w3c.github.io/data-shapes/shacl12-test-suite/tests/manifest.ttl)
674
+ is scored on every `npm test`, including filtered runs. eyemind targets its
675
+ Core and node-expression groups; SHACL-SPARQL and inference rules are out of
676
+ scope and not scored. At upstream revision
677
+ `0ed3f9b4273c2debba0125a7ed5c9dc3cd4b741c`, **all 162 Core tests pass
678
+ complete-report comparison**, as do all 284 node-expression tests.
679
+
680
+ The two groups are reported separately in
681
+ [REPORT.md](REPORT.md) and [SHACL EARL](reports/w3c-shacl-earl.ttl). The runner
682
+ preserves separate data and shapes graphs, follows manifest includes and
683
+ compares complete top-level results, their multiplicity, messages and paths.
684
+ A matching conformance boolean alone is not a pass. Unimplemented processor
685
+ families are explicitly untested in EARL; attempted validation cases that
686
+ reject unsupported constraints or produce wrong reports are failed.
687
+
688
+ ```sh
689
+ node tools/shacltests.js
690
+ node tools/shacltests.js --json > /tmp/shacl-coverage.json
691
+ node tools/shacltests.js --strict
692
+ ```
693
+
694
+ The default scorer and `npm test` report SHACL coverage without making missing
695
+ support fail the release checks, as with the Notation3 scorer. `--strict` exits
696
+ with code 1 for any non-passing SHACL case. Broken manifests and missing test
697
+ resources always fail the run. These commands reuse the cached suite; an
698
+ optional suite directory can select a different copy.
699
+
640
700
  ### ODRL snapshots
641
701
 
642
702
  Use `--odrl` to add ODRL validation and evaluation to one Turtle file
@@ -1013,7 +1073,8 @@ EYEMIND_PROPERTY_SCALE=20 npm test -- -k properties # deeper generated tests
1013
1073
  node tools/update-examples.js # regenerate example artifacts after an intended change
1014
1074
  node tools/report.js # run the full suite and write REPORT.md
1015
1075
  node tools/notation3tests.js # the cached Notation3 suite
1016
- npm run sync # refresh all three upstream test suites
1076
+ node tools/shacltests.js # SHACL 1.2 coverage; --strict fails for missing support
1077
+ npm run sync # refresh all four upstream test suites
1017
1078
  node conformance/run.js --command "my-eyemind" # run the conformance suite against another implementation
1018
1079
  ```
1019
1080
 
@@ -1023,16 +1084,18 @@ A full `npm test` writes `REPORT.md` from the summary table it prints.
1023
1084
 
1024
1085
  Every `npm test` invocation, including a filtered run, also runs both cached
1025
1086
  W3C format suites and rewrites [reports/w3c-rdf-earl.ttl](reports/w3c-rdf-earl.ttl)
1026
- and [reports/w3c-sparql-rl-earl.ttl](reports/w3c-sparql-rl-earl.ttl).
1087
+ and [reports/w3c-sparql-rl-earl.ttl](reports/w3c-sparql-rl-earl.ttl). It also scores
1088
+ the Core and node-expression groups of the SHACL 1.2 manifest and writes
1089
+ [reports/w3c-shacl-earl.ttl](reports/w3c-shacl-earl.ttl).
1027
1090
  These [EARL](https://www.w3.org/TR/EARL10-Schema/) reports contain one
1028
1091
  assertion per manifest case, its actual outcome and diagnostic, the eyemind
1029
- version and the run date. A W3C failure makes the command fail. A negative
1092
+ version and the run date. An RDF or SRL failure makes the command fail; SHACL is reported as coverage. A negative
1030
1093
  syntax test passes when the parser rejects its input as required.
1031
1094
 
1032
1095
  The [upstream suites](test/UPSTREAM.md) live in Git-ignored `.cache/`.
1033
1096
  `npm test` reuses them without fetching. If the cache is missing or incomplete,
1034
1097
  it downloads the suites first; that first run needs Git and network access.
1035
- `npm run sync` explicitly refreshes all three suites and the Notation3 document
1098
+ `npm run sync` explicitly refreshes all four suites and the Notation3 document
1036
1099
  fixtures. Downloads and manifest resource checks finish before the cached
1037
1100
  suites are replaced; a failed refresh retains the old set. Upstream licensing
1038
1101
  and documentation stay with the cached files. The small tracked
@@ -1045,6 +1108,9 @@ Local Git checkouts can supply any of the sources:
1045
1108
  npm run sync -- --notation3tests /path/to/notation3tests --w3c-rdf /path/to/rdf-tests --w3c-sparql-rl /path/to/data-shapes
1046
1109
  ```
1047
1110
 
1111
+ The data-shapes checkout supplies both SRL and SHACL; `--w3c-shacl PATH` can
1112
+ select a separate checkout for SHACL.
1113
+
1048
1114
  `node tools/sync-notation3tests.js [UPSTREAM_CHECKOUT]` still refreshes only
1049
1115
  Notation3 in `.cache/`. Once cached, tests use saved documents with no network fallback;
1050
1116
  the scorer's `--live` option checks the current remote resources instead.
package/SPEC.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ```text
4
4
  Title: The Logic Script (LS) Language and Proof Format
5
- Version: eyemind 0.8.0
5
+ Version: eyemind 0.8.2
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
@@ -559,7 +559,7 @@ primitive called outside its patterns raises an error.
559
559
  | `number_chars` | `number_chars(?N, +L)`, `number_chars(+N, -L)` | A bound `L` is read as a number: an optional sign and decimal digits give an integer, and with a fraction or an exponent a float, as in `'007'`, `'-21.5'`, `'.5'`, `'1.'` and `'2E-2'`; other text fails, as does text whose value is too large for a finite float, such as `'1e400'`. Otherwise `L` spells `N` in its canonical text ([Section 9.2](#92-canonical-atoms-numbers-variables-and-lists)). |
560
560
  | `atom_concat` | `atom_concat(+A, +B, ?AB)`, `atom_concat(?A, ?B, +AB)` | `AB` is `A` followed by `B`; with `AB` given, every split, shortest `A` first. |
561
561
  | `atom_lower`, `atom_upper` | `atom_lower(+A, ?L)`, `atom_upper(+A, ?U)` | `L` is `A` in lower case, `U` in upper case, by Unicode default case conversion: the full mappings, independent of locale, with the final sigma of a word lowered to `'ς'`, so `atom_upper('straße', 'STRASSE')` holds. |
562
- | `digest` | `digest(+H, +A, ?D)` | `D` is the digest of the UTF-8 encoding of the atom `A` by the hash function `H`, one of `'md5'`, `'sha1'`, `'sha256'` and `'sha512'`, as lowercase hexadecimal. A lone surrogate is encoded as U+FFFD. Another `H` raises an error. |
562
+ | `digest` | `digest(+H, +A, ?D)` | `D` is the digest of the UTF-8 encoding of the atom `A` by the hash function `H`, one of `'md5'`, `'sha1'`, `'sha256'`, `'sha384'` and `'sha512'`, as lowercase hexadecimal. A lone surrogate is encoded as U+FFFD. Another `H` raises an error. |
563
563
  | `term_text` | `term_text(+T, ?A)` | `A` is the canonical text of `T` ([Section 9.2](#92-canonical-atoms-numbers-variables-and-lists)), which MUST be ground: `term_text(f('a', [1, 2.0]), "f('a', [1, 2.0])")` holds. |
564
564
  | `float64` | `float64(+Op, +A, +B, ?R)` | Explicit IEEE-754 binary64 computation, including exceptional values represented as atoms, as defined below. |
565
565
  | `regex_match` | `regex_match(+P, +T)` | Some part of the atom `T` matches the regular expression `P`. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3) and SPARQL 1.2 RL (SRL) interoperability.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/builtins.js CHANGED
@@ -199,10 +199,10 @@ function caseConversion(name, convert) {
199
199
  }
200
200
 
201
201
  // digest(+Algorithm, +A, ?Hex): the lowercase hexadecimal digest of A's UTF-8
202
- // bytes, by md5, sha1, sha256 or sha512.
202
+ // bytes, by md5, sha1, sha256, sha384 or sha512.
203
203
  function digest(args, resolved, env, bind) {
204
204
  const algorithm = DIGESTS.get(resolved[0]);
205
- if (algorithm === undefined) throw new EyemindError(`digest/3 needs md5, sha1, sha256 or sha512, not ${write(resolved[0])}`);
205
+ if (algorithm === undefined) throw new EyemindError(`digest/3 needs md5, sha1, sha256, sha384 or sha512, not ${write(resolved[0])}`);
206
206
  return bind(args[2], algorithm(utf8(text('digest/3', resolved[1], 'atom'))));
207
207
  }
208
208
 
package/src/digest.js CHANGED
@@ -132,10 +132,18 @@ bef9a3f7b2c67915 c67178f2e372532b ca273eceea26619c d186b8c721c0c207 eada7dd6cde0
132
132
  4cc5d4becb3e42b6 597f299cfc657e2a 5fcb6fab3ad6faec 6c44198c4a475817`.split(/\s+/).map((x) => BigInt(`0x${x}`));
133
133
  const rotr64 = (x, n) => ((x >> n) | (x << (64n - n))) & MASK64;
134
134
 
135
- function sha512(bytes) {
136
- const m = pad(bytes, 128, 16, false);
137
- let h = `6a09e667f3bcc908 bb67ae8584caa73b 3c6ef372fe94f82b a54ff53a5f1d36f1 510e527fade682d1 9b05688c2b3e6c1f
135
+ const SHA512_IV = `6a09e667f3bcc908 bb67ae8584caa73b 3c6ef372fe94f82b a54ff53a5f1d36f1 510e527fade682d1 9b05688c2b3e6c1f
138
136
  1f83d9abfb41bd6b 5be0cd19137e2179`.split(/\s+/).map((x) => BigInt(`0x${x}`));
137
+ // SHA-384 is SHA-512 from other initial values, truncated to six words.
138
+ const SHA384_IV = `cbbb9d5dc1059ed8 629a292a367cd507 9159015a3070dd17 152fecd8f70e5939 67332667ffc00b31 8eb44a8768581511
139
+ db0c2e0d64f98fa7 47b5481dbefa4fa4`.split(/\s+/).map((x) => BigInt(`0x${x}`));
140
+
141
+ const sha512 = (bytes) => sha512Words(bytes, SHA512_IV, 8);
142
+ const sha384 = (bytes) => sha512Words(bytes, SHA384_IV, 6);
143
+
144
+ function sha512Words(bytes, iv, words) {
145
+ const m = pad(bytes, 128, 16, false);
146
+ let h = iv;
139
147
  for (let offset = 0; offset < m.length; offset += 128) {
140
148
  const w = [];
141
149
  for (let i = 0; i < 16; i++) {
@@ -156,7 +164,7 @@ function sha512(bytes) {
156
164
  }
157
165
  h = h.map((x, i) => (x + [a, b, c, d, e, f, g, k][i]) & MASK64);
158
166
  }
159
- return h.map((x) => x.toString(16).padStart(16, '0')).join('');
167
+ return h.slice(0, words).map((x) => x.toString(16).padStart(16, '0')).join('');
160
168
  }
161
169
 
162
- export const DIGESTS = new Map([['md5', md5], ['sha1', sha1], ['sha256', sha256], ['sha512', sha512]]);
170
+ export const DIGESTS = new Map([['md5', md5], ['sha1', sha1], ['sha256', sha256], ['sha384', sha384], ['sha512', sha512]]);
package/src/rdf-logic.js CHANGED
@@ -7,24 +7,32 @@ import { owl2rlRules } from './owl2rl.js';
7
7
  import { skosRules } from './skos.js';
8
8
  import { qudtRules } from './qudt.js';
9
9
  import { compileShacl } from './shacl.js';
10
+ import { NODE_FUNCTIONS } from './shacl-expr.js';
11
+ import { executionContext } from './srl.js';
10
12
  import { rdfValueRules } from './rdf-values.js';
11
13
 
12
14
  export const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
13
15
  export const RDF_PROFILES = ['owl2rl', 'qudt', 'skos', 'shacl'];
14
16
 
15
- export function compileRdfLogic({ quads, prefixes }, { profiles, source = '<input>' }) {
17
+ export function compileRdfLogic({ quads, prefixes, shapes = quads }, { profiles, source = '<input>', disallows, evaluate, context }) {
16
18
  quads = [...new Map(quads.map((q) => [q.map((t) => write(t)).join(' '), q])).values()];
17
- const selected = new Set(profiles);
19
+ const selected = new Set(profiles), needs = new Set();
20
+ // SHACL node expressions may call SPARQL functions beyond the value rules.
21
+ const shacl = selected.has('shacl') ? compileShacl(shapes, { disallows, needs, evaluate }) : '';
22
+ const own = [...needs].filter((n) => NODE_FUNCTIONS[n]);
23
+ const execution = ['srl_now', 'srl_uuid', 'sh_ne_rand'].some((n) => needs.has(n)) ? executionContext(context ?? null) : null;
18
24
  const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, with ${profiles.map((p) => '--' + p).join(' ')}.\n` +
19
25
  '// rdf(S, P, O, G) is the working graph; result_rdf contains conclusions and reports.\n' +
20
26
  `facts_from({ text: ${JSON.stringify(rdfDocument(quads))} })\n` +
21
27
  `facts_from({ text: ${JSON.stringify(rdfDocument(quads, 'ent_base'))} })\n` + COMMON +
22
28
  (quads.length ? '' : "fact(ent_graph('default_graph'));\n") +
23
- (profiles.some((p) => p !== 'skos') ? rdfValueRules : '') +
29
+ (profiles.some((p) => p !== 'skos') ? rdfValueRules([...needs].filter((n) => !NODE_FUNCTIONS[n])) : '') +
30
+ own.map((n) => NODE_FUNCTIONS[n] + '\n').join('') +
31
+ (execution ? `implied_by(srl_execution(${JSON.stringify(execution.now)}, ${JSON.stringify(execution.seed)}), 'true');\n` : '') +
24
32
  (selected.has('owl2rl') ? owl2rlRules : '') +
25
33
  (selected.has('skos') ? skosRules : '') +
26
34
  (selected.has('qudt') ? qudtRules : '') +
27
- (selected.has('shacl') ? compileShacl(quads) : '') + OUTPUT;
35
+ shacl + (evaluate ? "query(sh_evaluation(R));\n" : OUTPUT);
28
36
  return { kind: profiles[0], text, program: loadText(text, source),
29
37
  prefixes: { ...prefixes, ent: ENTAILMENT, ...(selected.has('skos') ? { skos: 'http://www.w3.org/2004/02/skos/core#' } : {}),
30
38
  ...(selected.has('qudt') ? { qconv: 'https://eyereasoner.github.io/eyemind/qudt#', qudt: 'http://qudt.org/schema/qudt/', unit: 'http://qudt.org/vocab/unit/' } : {}),
package/src/rdf-values.js CHANGED
@@ -55,7 +55,10 @@ implied_by(rv_order(A, B, O), [rv_temporal(A, T, K, X), rv_temporal(B, T, K, Y),
55
55
  implied_by(rv_member(T, iri(rvXsd + 'dateTime')), [rv_datatype(T, iri(rvXsd + 'dateTimeStamp')), rv_valid(T)]);
56
56
  `;
57
57
 
58
- export const rdfValueRules = '\n' + libraryText(new Set(['srl_num', 'srl_make', 'srl_add', 'srl_sub', 'srl_mul', 'srl_div', 'srl_order', 'srl_str', 'srl_lang'])) + '\n' + String.raw`
58
+ // The SPARQL definitions the value rules use; a profile may add more.
59
+ const VALUE_LIBRARY = ['srl_num', 'srl_make', 'srl_add', 'srl_sub', 'srl_mul', 'srl_div', 'srl_order', 'srl_str', 'srl_lang'];
60
+ export const rdfValueRules = (extra = []) => '\n' + libraryText(new Set([...VALUE_LIBRARY, ...extra])) + '\n' + VALUE_RULES;
61
+ const VALUE_RULES = String.raw`
59
62
  const rvXsd = 'http://www.w3.org/2001/XMLSchema#';
60
63
  const rvRdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
61
64
  implied_by(rv_datatype(N, iri(rvXsd + 'integer')), is_int(N));