eyemind 0.8.17 → 0.8.18
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 +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/qudt.js +52 -12
- package/src/version.js +1 -1
package/LS-SPEC.md
CHANGED
package/README.md
CHANGED
|
@@ -410,7 +410,7 @@ query(rdf(O, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), sosa('Obser
|
|
|
410
410
|
units: with `qudt:conversionMultiplier` and `qudt:hasDimensionVector`,
|
|
411
411
|
composed from QUDT units with `qudt:hasFactorUnit` or `qudt:prefix` and
|
|
412
412
|
`qudt:scalingOf`, or aligned with `owl:sameAs` or `skos:exactMatch`; QUDT
|
|
413
|
-
names such as `unit:NanoGM`
|
|
413
|
+
names such as `unit:NanoGM` or `unit:W-PER-M2` resolve by their parts. A
|
|
414
414
|
dimension without a CDT datatype normalizes to its coherent SI unit as a
|
|
415
415
|
`cdt:ucum` literal, and a quantity whose unit cannot be resolved, such as a
|
|
416
416
|
currency, is reported with `qconv:unresolvedUnit`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyemind",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.18",
|
|
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
|
@@ -143,6 +143,9 @@ const ucumOf = (exponents) => {
|
|
|
143
143
|
return [...factors.filter(([, e]) => e > 0), ...factors.filter(([, e]) => e < 0)]
|
|
144
144
|
.map(([code, e]) => code + (e === 1 ? '' : e)).join('.') || '1';
|
|
145
145
|
};
|
|
146
|
+
const SYMBOLS = { Quecto: 'q', Ronto: 'r', Yocto: 'y', Zepto: 'z', Atto: 'a', Femto: 'f', Pico: 'p', Nano: 'n', Micro: 'u',
|
|
147
|
+
Milli: 'm', Centi: 'c', Deci: 'd', Deca: 'da', Hecto: 'h', Kilo: 'k', Mega: 'M', Giga: 'G', Tera: 'T', Peta: 'P', Exa: 'E',
|
|
148
|
+
Zetta: 'Z', Yotta: 'Y', Ronna: 'R', Quetta: 'Q' };
|
|
146
149
|
const PREFIXES = { Quecto: 1e-30, Ronto: 1e-27, Yocto: 1e-24, Zepto: 1e-21, Atto: 1e-18, Femto: 1e-15, Pico: 1e-12, Nano: 1e-9,
|
|
147
150
|
Micro: 1e-6, Milli: 1e-3, Centi: 1e-2, Deci: 1e-1, Deca: 1e1, Hecto: 1e2, Kilo: 1e3, Mega: 1e6, Giga: 1e9, Tera: 1e12,
|
|
148
151
|
Peta: 1e15, Exa: 1e18, Zetta: 1e21, Yotta: 1e24, Ronna: 1e27, Quetta: 1e30 };
|
|
@@ -153,24 +156,54 @@ const exact = (n) => {
|
|
|
153
156
|
return rounded.toExponential().replace(/e.*$/, '').replace(/[-.]/g, '').length <= 12 ? rounded : n;
|
|
154
157
|
};
|
|
155
158
|
// A unit IRI named by an SI prefix and a catalog unit without an offset.
|
|
156
|
-
const prefixed = (
|
|
157
|
-
if (!id.startsWith(U)) return null;
|
|
158
|
-
const name = id.slice(U.length);
|
|
159
|
+
const prefixed = (name) => {
|
|
159
160
|
for (const [prefix, scale] of Object.entries(PREFIXES)) {
|
|
160
161
|
const base = builtin.get(U + name.slice(prefix.length));
|
|
161
|
-
if (name.startsWith(prefix) && base && base.offset === 0)
|
|
162
|
+
if (name.startsWith(prefix) && base && base.offset === 0) {
|
|
163
|
+
return { ...base, mult: exact(scale * base.mult), code: base.code && /^[A-Za-z]+\d*$/.test(base.code) ? SYMBOLS[prefix] + base.code : null };
|
|
164
|
+
}
|
|
162
165
|
}
|
|
163
166
|
return null;
|
|
164
167
|
};
|
|
165
|
-
|
|
168
|
+
// A unit QUDT names by its parts: a prefixed unit, as NanoGM, or factors
|
|
169
|
+
// with exponents, joined by - and divided by PER, as W-PER-M2 or
|
|
170
|
+
// KiloGM-M-PER-SEC2. As in QUDT, a factor's offset does not carry over:
|
|
171
|
+
// DEG_C-PER-HR is a rate of temperature difference.
|
|
172
|
+
const byName = (id) => {
|
|
173
|
+
if (!id.startsWith(U)) return null;
|
|
174
|
+
const name = id.slice(U.length);
|
|
175
|
+
const single = prefixed(name);
|
|
176
|
+
if (single) return single;
|
|
177
|
+
const [over, under = ''] = name.startsWith('PER-') ? ['', name.slice(4)] : name.split('-PER-');
|
|
178
|
+
if (name.split('-PER-').length > 2) return null;
|
|
179
|
+
const factor = (token) => {
|
|
180
|
+
const known = builtin.get(U + token) ?? prefixed(token);
|
|
181
|
+
if (known) return [known, 1];
|
|
182
|
+
const [, base, power] = /^(.+?)(\d+)$/.exec(token) ?? [];
|
|
183
|
+
const unit = base && (builtin.get(U + base) ?? prefixed(base));
|
|
184
|
+
return unit ? [unit, Number(power)] : null;
|
|
185
|
+
};
|
|
186
|
+
const parts = [...(over ? over.split('-').map((t) => [t, 1]) : []), ...(under ? under.split('-').map((t) => [t, -1]) : [])]
|
|
187
|
+
.map(([token, sign]) => { const f = factor(token); return f && [f[0], f[1] * sign]; });
|
|
188
|
+
if ((parts.length === 1 && parts[0]?.[1] === 1) || parts.some((part) => !part)) return null;
|
|
189
|
+
// Its UCUM code: the factors' codes, joined by . and divided by /.
|
|
190
|
+
const codes = parts.map(([u, e]) => !u.code ? null : Math.abs(e) === 1 && /^[A-Za-z]+\d*$/.test(u.code) ? u.code
|
|
191
|
+
: /^[A-Za-z]+$/.test(u.code) ? u.code + Math.abs(e) : null);
|
|
192
|
+
const code = codes.every(Boolean) ? (codes.filter((_, i) => parts[i][1] > 0).join('.') || '1') +
|
|
193
|
+
codes.filter((_, i) => parts[i][1] < 0).map((c) => '/' + c).join('') : null;
|
|
194
|
+
return { exponents: BASES.map((_, i) => parts.reduce((sum, [u, e]) => sum + u.exponents[i] * e, 0)),
|
|
195
|
+
mult: exact(parts.reduce((product, [u, e]) => product * u.mult ** e, 1)), offset: 0, code };
|
|
196
|
+
};
|
|
197
|
+
const builtin = new Map(units.map(([name, dim, mult, offset, tokens]) => [U + name, { exponents: vector(dimensions[dim]), mult, offset, code: tokens[0] ?? null }]));
|
|
166
198
|
const profiled = new Set(targets.map(([dim]) => dimensions[dim]));
|
|
167
199
|
|
|
168
200
|
// Facts for the units of these quads that QUDT composes from other units:
|
|
169
201
|
// qudt:hasFactorUnit with qudt:hasUnit and qudt:exponent, or qudt:prefix
|
|
170
202
|
// with qudt:scalingOf. Their multiplier is the product of their factors'
|
|
171
203
|
// multipliers, each to its exponent, and their dimension the sum of their
|
|
172
|
-
// factors' dimensions times it; a factor
|
|
173
|
-
//
|
|
204
|
+
// factors' dimensions times it; as in QUDT, a factor's offset does not
|
|
205
|
+
// carry over, but a unit that is one factor with an offset is not a new one.
|
|
206
|
+
// QUDT unit names such as NanoGM or W-PER-M2 compose the same way (byName).
|
|
174
207
|
export function qudtUnits(quads) {
|
|
175
208
|
const about = new Map();
|
|
176
209
|
for (const quad of quads) {
|
|
@@ -199,10 +232,8 @@ export function qudtUnits(quads) {
|
|
|
199
232
|
dims.add(dimension);
|
|
200
233
|
} else if (builtin.has(id)) {
|
|
201
234
|
found = builtin.get(id);
|
|
202
|
-
} else if (
|
|
203
|
-
|
|
204
|
-
const [scale, base] = prefixed(id);
|
|
205
|
-
found = { ...base, mult: exact(scale * base.mult) };
|
|
235
|
+
} else if (byName(id)) {
|
|
236
|
+
found = byName(id);
|
|
206
237
|
derived.push(`fact(qu_builtin(${iri(id)}, ${iri(D + vectorName(found.exponents))}, ${number(found.mult)}, ${number(0)}));`);
|
|
207
238
|
dims.add(vectorName(found.exponents));
|
|
208
239
|
} else {
|
|
@@ -216,7 +247,7 @@ export function qudtUnits(quads) {
|
|
|
216
247
|
}
|
|
217
248
|
if (parts && parts.every(([u, e]) => u && e !== null)) {
|
|
218
249
|
const resolved = parts.map(([u, e, scale = 1]) => [resolve(u, seen), e, scale]);
|
|
219
|
-
if (resolved.every(([r]) => r &&
|
|
250
|
+
if (resolved.every(([r]) => r) && (factors.length > 1 || resolved[0][1] !== 1 || resolved[0][0].offset === 0)) {
|
|
220
251
|
const exponents = BASES.map((_, i) => resolved.reduce((sum, [r, e]) => sum + r.exponents[i] * e, 0));
|
|
221
252
|
const mult = exact(resolved.reduce((product, [r, e, scale]) => product * scale * r.mult ** e, 1));
|
|
222
253
|
found = { exponents, mult, offset: 0 };
|
|
@@ -233,7 +264,16 @@ export function qudtUnits(quads) {
|
|
|
233
264
|
if (['hasFactorUnit', 'scalingOf', 'hasDimensionVector'].some((p) => values(subject, p).length)) resolve(subject);
|
|
234
265
|
}
|
|
235
266
|
for (const quad of quads) if (quad[1].args?.[0] === Q + 'unit') resolve(quad[2]);
|
|
267
|
+
// A dimension without a target normalizes to a QUDT unit of it with
|
|
268
|
+
// multiplier 1 that the input uses, as W-PER-M2, or else to the coherent
|
|
269
|
+
// SI unit eyemind names by its UCUM code, as kg.s-3.
|
|
236
270
|
const profiles = [...dims].filter((dim) => !profiled.has(dim)).map((dim) => {
|
|
271
|
+
const coherent = [...known].find(([id, u]) => id.startsWith(U) && u && u.mult === 1 && u.offset === 0 && u.code && vectorName(u.exponents) === dim);
|
|
272
|
+
if (coherent) {
|
|
273
|
+
const [unit, { code }] = coherent;
|
|
274
|
+
return `fact(qu_builtin_token(${text(code)}, ${iri(unit)}));\n` +
|
|
275
|
+
`fact(qu_builtin_profile(${iri(C + 'Profile-' + code)}, ${text('https://w3id.org/cdt/ucum')}, ${iri(unit)}, ${text(code)}));`;
|
|
276
|
+
}
|
|
237
277
|
const code = ucumOf(vector(dim)), unit = C + 'unit-' + code;
|
|
238
278
|
return `fact(qu_builtin(${iri(unit)}, ${iri(D + dim)}, ${number(1)}, ${number(0)}));\n` +
|
|
239
279
|
`fact(qu_builtin_token(${text(code)}, ${iri(unit)}));\n` +
|
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.
|
|
2
|
+
export const VERSION = '0.8.18';
|