eyemind 0.8.34 → 0.8.35

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/LS-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.34
5
+ Version: eyemind 0.8.35
6
6
  ```
7
7
 
8
8
  This document specifies Logic Script (LS): the syntax and meaning of its
package/README.md CHANGED
@@ -394,8 +394,9 @@ query(rdf(O, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), sosa('Obser
394
394
  an offline catalog adapted from [QUDT.org](https://qudt.org/) (CC BY 4.0):
395
395
  `"36 km/h"^^cdt:speed` yields `"10.0 m/s"^^cdt:speed`. Input metadata adds
396
396
  units: with `qudt:conversionMultiplier` and `qudt:hasDimensionVector`,
397
- composed from QUDT units with `qudt:hasFactorUnit` or `qudt:prefix` and
398
- `qudt:scalingOf`, or aligned with `owl:sameAs` or `skos:exactMatch`. The
397
+ composed from QUDT units with `qudt:hasFactorUnit` and an optional
398
+ `qudt:factorUnitScalar`, derived from `qudt:prefix` and `qudt:scalingOf`,
399
+ or aligned with `owl:sameAs` or `skos:exactMatch`. The
399
400
  other units of the QUDT unit vocabulary with a fixed conversion, such as
400
401
  `unit:W-PER-M2`, come from an offline catalog that `tools/qudt-catalog.js`
401
402
  generates from a QUDT release, also by the UCUM code of a CDT literal. A
@@ -404,8 +405,12 @@ query(rdf(O, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), sosa('Obser
404
405
  separate runs agree: one that shares a quantity kind with it (QUDT's, or
405
406
  those the input states with `qudt:hasQuantityKind`), then one of SI base
406
407
  units, then the one with the fewest UCUM factors. So kW/m² is W/m² in any
407
- run, and a radiance stays W/(m²·sr). A quantity whose unit cannot be
408
- resolved, such as a currency, is reported with `qconv:unresolvedUnit`.
408
+ run, and a radiance stays W/(m²·sr). A property can choose another unit
409
+ with `qconv:normalizationProfile`. That profile supplies `qconv:targetUnit`,
410
+ `qconv:targetUcumCode` and `qconv:datatype`.
411
+ `qconv:unresolvedUnit` reports quantity values whose units lack a usable
412
+ conversion, including composed units whose multipliers are zero or
413
+ overflow binary64.
409
414
  - `--skos` adds positive [SKOS Core](https://www.w3.org/TR/skos-reference/)
410
415
  entailments, without integrity checks or SKOS-XL.
411
416
  - `--shacl` compiles shapes to LS and writes a standard `sh:ValidationReport`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.8.34",
3
+ "version": "0.8.35",
4
4
  "description": "A dependency-free Logic Script (LS) reasoner with forward and backward reasoning, checkable proofs, and RDF 1.2, Notation3 (N3), SPARQL 1.2 RL (SRL) and Logical English (LE) interoperability.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/qudt.js CHANGED
@@ -13,6 +13,7 @@ const K = 'http://qudt.org/vocab/quantitykind/';
13
13
  const SAME_AS = 'http://www.w3.org/2002/07/owl#sameAs';
14
14
  const EXACT_MATCH = 'http://www.w3.org/2004/02/skos/core#exactMatch';
15
15
  const ALIGNED_UNIT = C + 'alignedQudtUnit';
16
+ const TARGET_UNIT = C + 'targetUnit';
16
17
  const dimensions = {
17
18
  length: 'A0E0L1I0M0H0T0D0', area: 'A0E0L2I0M0H0T0D0', volume: 'A0E0L3I0M0H0T0D0',
18
19
  time: 'A0E0L0I0M0H0T1D0', mass: 'A0E0L0I0M1H0T0D0', speed: 'A0E0L1I0M0H0T-1D0',
@@ -166,6 +167,7 @@ const exact = (n) => {
166
167
  const rounded = Number(n.toPrecision(15));
167
168
  return rounded.toExponential().replace(/e.*$/, '').replace(/[-.]/g, '').length <= 12 ? rounded : n;
168
169
  };
170
+ const usableMultiplier = (n) => Number.isFinite(n) && n !== 0;
169
171
  // QUDT's units with a fixed conversion (qudt-catalog.js), read on first use:
170
172
  // each one's dimension vector, multiplier, offset, whether it is a coherent
171
173
  // SI unit and its UCUM code; and the units a UCUM code names, when it names
@@ -194,10 +196,11 @@ const builtinTokens = new Set(units.flatMap(([, , , , tokens]) => tokens));
194
196
 
195
197
  // Facts for the units of these quads that QUDT composes from other units:
196
198
  // qudt:hasFactorUnit with qudt:hasUnit and qudt:exponent, or qudt:prefix
197
- // with qudt:scalingOf. Their multiplier is the product of their factors'
198
- // multipliers, each to its exponent, and their dimension the sum of their
199
- // factors' dimensions times it; as in QUDT, a factor's offset does not
200
- // carry over, but a unit that is one factor with an offset is not a new one.
199
+ // with qudt:scalingOf. The conversion multiplier is the product of the
200
+ // factors' multipliers raised to their exponents, times qudt:factorUnitScalar
201
+ // if given. The dimension is the sum of the factors' scaled dimensions.
202
+ // A factor's offset does not carry over, but a unit that is one factor with
203
+ // an offset is not a new one.
201
204
  // The QUDT units the quads use and the catalog of builtin units lacks, by
202
205
  // IRI or by the UCUM code of a CDT literal, come from QUDT's catalog.
203
206
  export function qudtUnits(quads) {
@@ -222,9 +225,13 @@ export function qudtUnits(quads) {
222
225
  seen.add(id);
223
226
  let found = null;
224
227
  const multiplier = numberOf(values(unit, 'conversionMultiplier')[0]);
225
- const dimension = values(unit, 'hasDimensionVector')[0]?.args?.[0]?.slice(D.length);
226
- if (multiplier !== null && dimension && vector(dimension)) {
227
- found = { exponents: vector(dimension), mult: multiplier, offset: numberOf(values(unit, 'conversionOffset')[0]) ?? 0 };
228
+ const exponents = vector(values(unit, 'hasDimensionVector')[0]?.args?.[0]?.slice(D.length));
229
+ if (multiplier !== null && exponents !== null) {
230
+ const offset = values(unit, 'conversionOffset')[0];
231
+ const offsetValue = offset === undefined ? 0 : numberOf(offset);
232
+ if (usableMultiplier(multiplier) && Number.isFinite(offsetValue) && exponents.every(Number.isFinite)) {
233
+ found = { exponents, mult: multiplier, offset: offsetValue };
234
+ }
228
235
  } else if (builtin.has(id)) {
229
236
  found = builtin.get(id);
230
237
  } else if (catalogUnits().units.has(id)) {
@@ -236,16 +243,22 @@ export function qudtUnits(quads) {
236
243
  let parts = null;
237
244
  if (factors.length) parts = factors.map((f) => [values(f, 'hasUnit')[0], numberOf(values(f, 'exponent')[0])]);
238
245
  else if (prefix && base) {
239
- const scale = numberOf(values(prefix, 'prefixMultiplier')[0]) ?? PREFIXES[prefix.args?.[0]?.slice('http://qudt.org/vocab/prefix/'.length)];
240
- if (scale !== undefined && scale !== null) parts = [[base, 1, scale]];
246
+ const stated = values(prefix, 'prefixMultiplier')[0];
247
+ const scale = stated === undefined ? PREFIXES[prefix.args?.[0]?.slice('http://qudt.org/vocab/prefix/'.length)] : numberOf(stated);
248
+ if (usableMultiplier(scale)) parts = [[base, 1, scale]];
241
249
  }
242
- if (parts && parts.every(([u, e]) => u && e !== null)) {
250
+ const scalar = factors.length ? values(unit, 'factorUnitScalar')[0] : undefined;
251
+ const factor = scalar === undefined ? 1 : numberOf(scalar);
252
+ if (usableMultiplier(factor) && parts?.every(([u, e]) => u && Number.isFinite(e))) {
243
253
  const resolved = parts.map(([u, e, scale = 1]) => [resolve(u, seen), e, scale]);
244
254
  if (resolved.every(([r]) => r) && (factors.length > 1 || resolved[0][1] !== 1 || resolved[0][0].offset === 0)) {
245
- const exponents = BASES.map((_, i) => resolved.reduce((sum, [r, e]) => sum + r.exponents[i] * e, 0));
246
- const mult = exact(resolved.reduce((product, [r, e, scale]) => product * scale * r.mult ** e, 1));
247
- found = { exponents, mult, offset: 0 };
248
- derived.push(`fact(qu_derived(${iri(id)}, ${graphOf(unit)}, ${iri(D + vectorName(exponents))}, ${number(mult)}));`);
255
+ const powers = BASES.map((_, i) => resolved.reduce((sum, [r, e]) => sum + r.exponents[i] * e, 0));
256
+ const mult = exact(factor * resolved.reduce((product, [r, e, scale]) => product * scale * r.mult ** e, 1));
257
+ const dim = vectorName(powers);
258
+ if (usableMultiplier(mult) && vector(dim)) {
259
+ found = { exponents: powers, mult, offset: 0 };
260
+ derived.push(`fact(qu_derived(${iri(id)}, ${graphOf(unit)}, ${iri(D + dim)}, ${number(mult)}));`);
261
+ }
249
262
  }
250
263
  }
251
264
  }
@@ -256,7 +269,10 @@ export function qudtUnits(quads) {
256
269
  const subject = about.get(id)[0][0];
257
270
  if (['hasFactorUnit', 'scalingOf', 'hasDimensionVector'].some((p) => values(subject, p).length)) resolve(subject);
258
271
  }
259
- for (const quad of quads) if (quad[1].args?.[0] === Q + 'unit') resolve(quad[2]);
272
+ for (const [, predicate, unit] of quads) {
273
+ const p = predicate.args?.[0];
274
+ if (p === Q + 'unit' || p === TARGET_UNIT) resolve(unit);
275
+ }
260
276
  // An alignment can be the only mention of a catalog unit, for example
261
277
  // when a CDT literal uses a local symbol. OWL and SKOS can reverse it.
262
278
  const resolveCatalog = (unit) => {
package/src/rdf-logic.js CHANGED
@@ -72,8 +72,10 @@ function shapePatterns(quads, name, input) {
72
72
  const value = (node, property) => values(node, property)[0];
73
73
  const list = (node) => {
74
74
  const items = [];
75
- for (let at = node, seen = new Set(); at && !(at.name === 'iri' && at.args[0] === RDF + 'nil') && !seen.has(identity(at)); at = value(at, RDF + 'rest')) {
76
- seen.add(identity(at));
75
+ for (let at = node, seen = new Set(); at && !(at.name === 'iri' && at.args[0] === RDF + 'nil'); at = value(at, RDF + 'rest')) {
76
+ const id = identity(at);
77
+ if (seen.has(id)) throw new EyemindError(`${name}: cyclic RDF list in SHACL shapes`);
78
+ seen.add(id);
77
79
  items.push(value(at, RDF + 'first'));
78
80
  }
79
81
  return items.filter(Boolean);
@@ -102,14 +104,20 @@ function shapePatterns(quads, name, input) {
102
104
  return [any()];
103
105
  };
104
106
  // The predicates of a path, and whether it is a predicate or its inverse.
107
+ const readingPath = new Set();
105
108
  const path = (node) => {
106
109
  if (named(node)) return { predicates: [named(node)], direct: true };
110
+ const id = identity(node);
111
+ if (readingPath.has(id)) throw new EyemindError(`${name}: cyclic SHACL path`);
107
112
  const inverse = value(node, SH + 'inversePath');
108
113
  if (named(inverse)) return { predicates: [named(inverse)], inverse: true };
109
114
  const parts = [inverse, ...values(node, SH + 'alternativePath').flatMap(list),
110
115
  ...['zeroOrMorePath', 'oneOrMorePath', 'zeroOrOnePath'].map((p) => value(node, SH + p)), ...list(node)].filter(Boolean);
111
116
  if (!parts.length) throw new EyemindError(`${name}: a SHACL path is a predicate, a list or one of the sh: path forms`);
112
- return { predicates: parts.flatMap((part) => path(part).predicates) };
117
+ readingPath.add(id);
118
+ const predicates = parts.flatMap((part) => path(part).predicates);
119
+ readingPath.delete(id);
120
+ return { predicates };
113
121
  };
114
122
  const owners = new Map();
115
123
  for (const quad of quads) {
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The release this checkout is; ./release keeps it in step with package.json.
2
- export const VERSION = '0.8.34';
2
+ export const VERSION = '0.8.35';