eyemind 0.7.2 → 0.8.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/src/qudt.js ADDED
@@ -0,0 +1,109 @@
1
+ // Offline QUDT/CDT normalization. Metadata facts are a small, explicit selection
2
+ // from QUDT.org (CC BY 4.0), https://qudt.org/vocab/unit/ . Input metadata can
3
+ // extend or override it; there is no ontology download during compilation.
4
+ const Q = 'http://qudt.org/schema/qudt/';
5
+ const U = 'http://qudt.org/vocab/unit/';
6
+ const C = 'https://eyereasoner.github.io/eyemind/qudt#';
7
+ const D = 'http://qudt.org/vocab/dimensionvector/';
8
+ const dimensions = {
9
+ length: 'A0E0L1I0M0H0T0D0', area: 'A0E0L2I0M0H0T0D0', volume: 'A0E0L3I0M0H0T0D0',
10
+ time: 'A0E0L0I0M0H0T1D0', mass: 'A0E0L0I0M1H0T0D0', speed: 'A0E0L1I0M0H0T-1D0',
11
+ acceleration: 'A0E0L1I0M0H0T-2D0', temperature: 'A0E0L0I0M0H1T0D0',
12
+ pressure: 'A0E0L-1I0M1H0T-2D0', energy: 'A0E0L2I0M1H0T-2D0', power: 'A0E0L2I0M1H0T-3D0',
13
+ dimensionless: 'A0E0L0I0M0H0T0D1', current: 'A0E1L0I0M0H0T0D0', amountOfSubstance: 'A1E0L0I0M0H0T0D0',
14
+ };
15
+ const units = [
16
+ ['M', 'length', 1, 0, ['m']], ['CentiM', 'length', 0.01, 0, ['cm']], ['MilliM', 'length', 0.001, 0, ['mm']],
17
+ ['KiloM', 'length', 1000, 0, ['km']], ['IN', 'length', 0.0254, 0, ['[in_i]', 'in']],
18
+ ['FT', 'length', 0.3048, 0, ['[ft_i]', 'ft']], ['MI', 'length', 1609.344, 0, ['[mi_i]', 'mi']],
19
+ ['SEC', 'time', 1, 0, ['s']], ['MIN', 'time', 60, 0, ['min']], ['HR', 'time', 3600, 0, ['h']], ['DAY', 'time', 86400, 0, ['d']],
20
+ ['KiloGM', 'mass', 1, 0, ['kg']], ['GM', 'mass', 0.001, 0, ['g']], ['MilliGM', 'mass', 0.000001, 0, ['mg']],
21
+ ['LB', 'mass', 0.45359237, 0, ['[lb_av]', 'lb']],
22
+ ['M-PER-SEC', 'speed', 1, 0, ['m/s', 'm.s-1']], ['KiloM-PER-HR', 'speed', 1 / 3.6, 0, ['km/h', 'km.h-1']],
23
+ ['MI-PER-HR', 'speed', 0.44704, 0, ['[mi_i]/h', 'mph']], ['KN', 'speed', 1852 / 3600, 0, ['[kn_i]', 'kn']],
24
+ ['M-PER-SEC2', 'acceleration', 1, 0, ['m/s2', 'm.s-2']],
25
+ ['K', 'temperature', 1, 0, ['K']], ['DEG_C', 'temperature', 1, 273.15, ['Cel', '°C']],
26
+ ['DEG_F', 'temperature', 5 / 9, 459.67, ['[degF]', '°F']],
27
+ ['M2', 'area', 1, 0, ['m2']], ['CentiM2', 'area', 0.0001, 0, ['cm2']],
28
+ ['M3', 'volume', 1, 0, ['m3']], ['L', 'volume', 0.001, 0, ['L', 'l']], ['MilliL', 'volume', 0.000001, 0, ['mL']],
29
+ ['PA', 'pressure', 1, 0, ['Pa']], ['KiloPA', 'pressure', 1000, 0, ['kPa']], ['BAR', 'pressure', 100000, 0, ['bar']],
30
+ ['J', 'energy', 1, 0, ['J']], ['KiloJ', 'energy', 1000, 0, ['kJ']],
31
+ ['W', 'power', 1, 0, ['W']], ['KiloW', 'power', 1000, 0, ['kW']],
32
+ ['UNITLESS', 'dimensionless', 1, 0, ['1']], ['PERCENT', 'dimensionless', 0.01, 0, ['%']],
33
+ ['A', 'current', 1, 0, ['A']], ['MOL', 'amountOfSubstance', 1, 0, ['mol']],
34
+ ];
35
+ const targets = [['length', 'M', 'm'], ['area', 'M2', 'm2'], ['volume', 'M3', 'm3'], ['time', 'SEC', 's'],
36
+ ['mass', 'KiloGM', 'kg'], ['speed', 'M-PER-SEC', 'm/s'], ['acceleration', 'M-PER-SEC2', 'm/s2'],
37
+ ['temperature', 'K', 'K'], ['pressure', 'PA', 'Pa'], ['energy', 'J', 'J'], ['power', 'W', 'W'],
38
+ ['dimensionless', 'UNITLESS', '1'], ['current', 'A', 'A'], ['amountOfSubstance', 'MOL', 'mol']];
39
+ const text = (s) => JSON.stringify(s);
40
+ const iri = (s) => `iri(${text(s)})`;
41
+ const number = (n) => `float(${n})`;
42
+ const definitions = [];
43
+ for (const [name, dim, mult, offset, tokens] of units) {
44
+ definitions.push(`fact(qu_builtin(${iri(U + name)}, ${iri(D + dimensions[dim])}, ${number(mult)}, ${number(offset)}));`);
45
+ for (const token of tokens) definitions.push(`fact(qu_builtin_token(${text(token)}, ${iri(U + name)}));`);
46
+ }
47
+ for (const [dt, unit, code] of targets) {
48
+ const profile = C + dt[0].toUpperCase() + dt.slice(1) + 'Profile';
49
+ definitions.push(`fact(qu_builtin_profile(${iri(profile)}, ${text('https://w3id.org/cdt/' + (dt === 'current' ? 'electricCurrent' : dt))}, ${iri(U + unit)}, ${text(code)}));`);
50
+ }
51
+ for (const [name, base, exponent, code] of [['B', 10, 1, 'B'], ['DeciB', 10, 0.1, 'dB'],
52
+ ['NP', Math.E, 1, 'Np'], ['OCT', 2, 1, 'oct'], ['DECADE', 10, 1, 'dec'], ['PH', 10, -1, '[pH]']]) {
53
+ definitions.push(`fact(qu_builtin_log(${iri(U + name)}, ${number(base)}, ${number(exponent)}));`);
54
+ definitions.push(`fact(qu_builtin_token(${text(code)}, ${iri(U + name)}));`);
55
+ }
56
+
57
+ export const qudtRules = '\n' + definitions.join('\n') + String.raw`
58
+ const qu = (n) => iri('http://qudt.org/schema/qudt/' + n);
59
+ const qc = (n) => iri('https://eyereasoner.github.io/eyemind/qudt#' + n);
60
+ const quDouble = 'http://www.w3.org/2001/XMLSchema#double';
61
+ const quString = 'http://www.w3.org/2001/XMLSchema#string';
62
+ implied_by(qu_float(T, F), [rv_valid(T), srl_num(T, _, N), srl_float_value(N, F), is_float(F)]);
63
+ implied_by(qu_custom(U, G), ent_base(U, qu('conversionMultiplier'), _, G));
64
+ implied_by(qu_unit(U, G, D, M, O), [qu_builtin(U, D, M, O), not(qu_custom(U, G))]);
65
+ implied_by(qu_unit(U, G, D, M, O), [ent_base(U, qu('hasDimensionVector'), D, G), ent_base(U, qu('conversionMultiplier'), T, G), qu_float(T, M), ne(M, 0.0), qu_offset(U, G, O)]);
66
+ implied_by(qu_offset(U, G, O), [ent_base(U, qu('conversionOffset'), T, G), qu_float(T, O)]);
67
+ implied_by(qu_offset(U, G, float(0)), not(ent_base(U, qu('conversionOffset'), _, G)));
68
+ implied_by(qu_log(U, G, B, E), [qu_builtin_log(U, B, E), not(ent_base(U, qc('logBase'), _, G))]);
69
+ implied_by(qu_log(U, G, B, E), [ent_base(U, qc('logBase'), BT, G), ent_base(U, qc('logExponentMultiplier'), ET, G), qu_float(BT, B), gt(B, 0.0), ne(B, 1.0), qu_float(ET, E), ne(E, 0.0)]);
70
+ implied_by(qu_dimension(U, G, D), qu_unit(U, G, D, _, _));
71
+ implied_by(qu_dimension(U, G, iri('http://qudt.org/vocab/dimensionvector/A0E0L0I0M0H0T0D1')), qu_log(U, G, _, _));
72
+ implied_by(qu_token(T, U, G), qu_builtin_token(T, U));
73
+ for (const p of ['symbol', 'ucumCode', 'expression']) implied_by(qu_token(T, U, G), [ent_base(U, qu(p), L, G), srl_str(L, literal(T, datatype(quString)))]);
74
+ implied_by(qu_align(U, U, G), qu_dimension(U, G, _));
75
+ for (const p of [iri('http://www.w3.org/2002/07/owl#sameAs'), iri('http://www.w3.org/2004/02/skos/core#exactMatch'), qc('alignedQudtUnit')]) {
76
+ implied_by(qu_align(Local, U, G), [rdf(Local, p, U, G), qu_dimension(U, G, _)]);
77
+ }
78
+ implied_by(qu_custom_profile(P, G), ent_base(P, qc('targetUnit'), _, G));
79
+ implied_by(qu_profile(P, DT, U, Code, G), [qu_builtin_profile(P, DT, U, Code), not(qu_custom_profile(P, G))]);
80
+ implied_by(qu_profile(P, DT, U, Code, G), [ent_base(P, qc('targetUnit'), U, G), ent_base(P, qc('datatype'), iri(DT), G), ent_base(P, qc('targetUcumCode'), L, G), srl_str(L, literal(Code, datatype(quString)))]);
81
+ implied_by(qu_datatype(P, DT, U, Code, G), qu_profile(P, DT, U, Code, G));
82
+ implied_by(qu_datatype(P, Old, U, Code, G), [qu_profile(P, DT, U, Code, G), atom_concat('https://w3id.org/cdt/', Name, DT), atom_concat('http://w3id.org/lindt/custom_datatypes#', Name, Old)]);
83
+ // Default selection must be unambiguous by dimension. A property contract wins.
84
+ implied_by(qu_default(P, DT, U, Code, D, G), [qu_profile(P, DT, U, Code, G), qu_dimension(U, G, D), not(qu_ambiguous(P, D, G))]);
85
+ implied_by(qu_ambiguous(P, D, G), [qu_profile(Q, _, V, _, G), not_identical(P, Q), qu_dimension(V, G, D)]);
86
+ implied_by(qu_selected(Property, P, DT, U, Code, D, G), [ent_base(Property, qc('normalizationProfile'), P, G), qu_profile(P, DT, U, Code, G), qu_dimension(U, G, D)]);
87
+ implied_by(qu_selected(Property, P, DT, U, Code, D, G), [not(ent_base(Property, qc('normalizationProfile'), _, G)), qu_default(P, DT, U, Code, D, G)]);
88
+ implied_by(qu_parsed(L, U, G, V), [regex_find('^\\s*([+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?)\\s+(.+?)\\s*$', L, [_, N, Token]), float64('parse', N, 0, V), is_float(V), qu_token(Token, Local, G), qu_align(Local, U, G)]);
89
+ implied_by(qu_generic('https://w3id.org/cdt/ucum'), 'true');
90
+ implied_by(qu_generic('http://w3id.org/lindt/custom_datatypes#ucum'), 'true');
91
+ // Only input measurements are normalized, so generated results cannot recursively
92
+ // become new measurements. Inferred OWL/SKOS unit alignments are still consulted.
93
+ implied_by(qu_contract(Property, Profile, G), not(ent_base(Property, qc('normalizationProfile'), _, G)));
94
+ implied_by(qu_contract(Property, Profile, G), ent_base(Property, qc('normalizationProfile'), Profile, G));
95
+ implies([ent_base(S, P, literal(L, datatype(DT)), G), qu_parsed(L, U, G, V), qu_datatype(Profile, DT, _, _, G), qu_contract(P, Profile, G), qu_profile(Profile, Specific, T, Code, G), qu_dimension(U, G, Dim), qu_dimension(T, G, Dim)], qu_input(S, P, literal(L, datatype(DT)), qc('sourceLiteral'), U, V, T, Code, Specific, G));
96
+ implies([ent_base(S, P, literal(L, datatype(DT)), G), qu_generic(DT), qu_parsed(L, U, G, V), qu_dimension(U, G, Dim), qu_selected(P, Profile, Specific, T, Code, Dim, G)], qu_input(S, P, literal(L, datatype(DT)), qc('sourceLiteral'), U, V, T, Code, Specific, G));
97
+ implies([ent_base(S, P, Q, G), rdf(Q, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), qu('QuantityValue'), G), rdf(Q, qu('numericValue'), Value, G), rdf(Q, qu('unit'), Local, G), qu_float(Value, V), qu_align(Local, U, G), qu_dimension(U, G, Dim), qu_selected(P, Profile, DT, T, Code, Dim, G)], qu_input(S, P, Q, qc('sourceQuantity'), U, V, T, Code, DT, G));
98
+ // QUDT's offset is applied before its multiplier; this matters for Fahrenheit.
99
+ implied_by(qu_ratio(V, U, G, R), [qu_unit(U, G, _, M, O), float64('add', V, O, A), float64('mul', A, M, R), is_float(R)]);
100
+ implied_by(qu_ratio(V, U, G, R), [qu_log(U, G, B, E), float64('mul', V, E, X), is_float(X), is(LB, log(B)), float64('mul', X, LB, Ln), is_float(Ln), lt(Ln, float(709.782712893384)), is(R, pow(B, X))]);
101
+ implied_by(qu_from_ratio(R, T, G, V), [qu_unit(T, G, _, M, O), float64('div', R, M, A), float64('sub', A, O, V), is_float(V)]);
102
+ implied_by(qu_from_ratio(R, T, G, V), [qu_log(T, G, B, E), gt(R, 0.0), is(LR, log(R)), is(LB, log(B)), float64('div', LR, LB, A), float64('div', A, E, V), is_float(V)]);
103
+ implies([qu_input(S, P, Q, Kind, U, V, T, Code, DT, G), qu_ratio(V, U, G, R), qu_from_ratio(R, T, G, N), srl_make('double', N, Number), number_chars(N, Cs), atom_chars(L, Cs), atom_concat(L, ' ', A), atom_concat(A, Code, Lexical)], [
104
+ rdf(S, qc('normalizedQuantity'), B, G), rdf(S, qc('normalizedUcumLiteral'), literal(Lexical, datatype('https://w3id.org/cdt/ucum')), G),
105
+ rdf(S, qc('normalizedCdtLiteral'), literal(Lexical, datatype(DT)), G),
106
+ rdf(B, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), qu('QuantityValue'), G),
107
+ rdf(B, qu('numericValue'), Number, G), rdf(B, qu('unit'), T, G), rdf(B, qc('sourceProperty'), P, G), rdf(B, Kind, Q, G), rdf(B, qc('sourceUnit'), U, G)
108
+ ]);
109
+ `;
@@ -0,0 +1,59 @@
1
+ // Explicit RDF profiles share one working graph. Validation and reports never
2
+ // feed back into it; LS stratification closes inference before validation.
3
+ import { loadText } from './lang.js';
4
+ import { rdfDocument } from './rdf.js';
5
+ import { write } from './writer.js';
6
+ import { owl2rlRules } from './owl2rl.js';
7
+ import { skosRules } from './skos.js';
8
+ import { qudtRules } from './qudt.js';
9
+ import { compileShacl } from './shacl.js';
10
+ import { rdfValueRules } from './rdf-values.js';
11
+
12
+ export const ENTAILMENT = 'https://eyereasoner.github.io/eyemind/entailment#';
13
+ export const RDF_PROFILES = ['owl2rl', 'qudt', 'skos', 'shacl'];
14
+
15
+ export function compileRdfLogic({ quads, prefixes, shapes = quads }, { profiles, source = '<input>', disallows }) {
16
+ quads = [...new Map(quads.map((q) => [q.map((t) => write(t)).join(' '), q])).values()];
17
+ const selected = new Set(profiles);
18
+ const text = `// Generated by eyemind from ${String(source).replace(/[\r\n\u2028\u2029]/g, ' ')}, with ${profiles.map((p) => '--' + p).join(' ')}.\n` +
19
+ '// rdf(S, P, O, G) is the working graph; result_rdf contains conclusions and reports.\n' +
20
+ `facts_from({ text: ${JSON.stringify(rdfDocument(quads))} })\n` +
21
+ `facts_from({ text: ${JSON.stringify(rdfDocument(quads, 'ent_base'))} })\n` + COMMON +
22
+ (quads.length ? '' : "fact(ent_graph('default_graph'));\n") +
23
+ (profiles.some((p) => p !== 'skos') ? rdfValueRules : '') +
24
+ (selected.has('owl2rl') ? owl2rlRules : '') +
25
+ (selected.has('skos') ? skosRules : '') +
26
+ (selected.has('qudt') ? qudtRules : '') +
27
+ (selected.has('shacl') ? compileShacl(shapes, { disallows }) : '') + OUTPUT;
28
+ return { kind: profiles[0], text, program: loadText(text, source),
29
+ prefixes: { ...prefixes, ent: ENTAILMENT, ...(selected.has('skos') ? { skos: 'http://www.w3.org/2004/02/skos/core#' } : {}),
30
+ ...(selected.has('qudt') ? { qconv: 'https://eyereasoner.github.io/eyemind/qudt#', qudt: 'http://qudt.org/schema/qudt/', unit: 'http://qudt.org/vocab/unit/' } : {}),
31
+ ...(selected.has('shacl') ? { sh: 'http://www.w3.org/ns/shacl#' } : {}) }, compiled: null };
32
+ }
33
+
34
+ const COMMON = String.raw`
35
+ implied_by(ent_resource(iri(A)), is_atom(A));
36
+ implied_by(ent_resource(bnode(A, B)), [is_atom(A), is_atom(B)]);
37
+ implied_by(ent_resource(skolem(A, B, C)), 'true');
38
+ implied_by(ent_resource(triple(A, B, C)), 'true');
39
+ implies(rdf(S, P, O, G), ent_graph(G));
40
+ implies(rdf(S, P, O, G), [ent_node(S, G), ent_node(P, G), ent_node(O, G)]);
41
+ fact(ent_count([], 0));
42
+ implied_by(ent_count([_, ...T], N), [ent_count(T, M), is(N, add(M, 1))]);
43
+ fact(ent_member(X, [X, ..._]));
44
+ implied_by(ent_member(X, [_, ...T]), ent_member(X, T));
45
+ `;
46
+
47
+ const OUTPUT = String.raw`
48
+ // A report cannot create more ontology consequences or affect a constraint.
49
+ implies(ent_conflict(R, X, P, Y, G), [
50
+ ent_report(B, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), iri('https://eyereasoner.github.io/eyemind/entailment#Conflict'), G),
51
+ ent_report(B, iri('https://eyereasoner.github.io/eyemind/entailment#rule'), literal(R, datatype('http://www.w3.org/2001/XMLSchema#string')), G),
52
+ ent_report(B, iri('https://eyereasoner.github.io/eyemind/entailment#focus'), X, G),
53
+ ent_report(B, iri('https://eyereasoner.github.io/eyemind/entailment#left'), P, G),
54
+ ent_report(B, iri('https://eyereasoner.github.io/eyemind/entailment#right'), Y, G)
55
+ ]);
56
+ implies([rdf(S, iri(P), O, G), ent_resource(S), not(ent_base(S, iri(P), O, G))], result_rdf(S, iri(P), O, G));
57
+ implies(ent_report(S, P, O, G), result_rdf(S, P, O, G));
58
+ query(result_rdf(S, P, O, G));
59
+ `;
@@ -0,0 +1,98 @@
1
+ // Datatype tests and value arithmetic are ordinary LS. Exact decimals reuse
2
+ // the SPARQL library, so certificates do not trust JavaScript conversions.
3
+ import { libraryText } from './srl-functions.js';
4
+
5
+ const XSD = 'http://www.w3.org/2001/XMLSchema#';
6
+ const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
7
+ const bounds = [
8
+ ['integer', null, null], ['long', '-9223372036854775808', '9223372036854775807'],
9
+ ['int', '-2147483648', '2147483647'], ['short', '-32768', '32767'], ['byte', '-128', '127'],
10
+ ['nonNegativeInteger', '0', null], ['positiveInteger', '1', null],
11
+ ['nonPositiveInteger', null, '0'], ['negativeInteger', null, '-1'],
12
+ ['unsignedLong', '0', '18446744073709551615'], ['unsignedInt', '0', '4294967295'],
13
+ ['unsignedShort', '0', '65535'], ['unsignedByte', '0', '255'],
14
+ ];
15
+ export const RDF_DATATYPES = new Set([...bounds.map(([n]) => XSD + n), ...['decimal', 'float', 'double', 'boolean', 'string',
16
+ 'normalizedString', 'token', 'language', 'anyURI', 'date', 'dateTime', 'dateTimeStamp', 'time',
17
+ 'hexBinary', 'base64Binary'].map((n) => XSD + n), RDF + 'langString', RDF + 'dirLangString']);
18
+
19
+ const integerRules = bounds.map(([name, min, max]) => {
20
+ const facets = `${min === null ? '' : `, ge(N, ${min})`}${max === null ? '' : `, le(N, ${max})`}`;
21
+ return `implied_by(rv_lexical('${XSD}${name}', L), [srl_read_number('integer', L, N)${facets}]);\n` +
22
+ `implied_by(rv_member(T, iri('${XSD}${name}')), [rv_integer_value(T, N)${facets}]);\n` +
23
+ `fact(rv_integer_datatype(iri('${XSD}${name}')));`;
24
+ }).join('\n');
25
+
26
+ const dateRules = String.raw`
27
+ // Calendar and timezone checks use LS arithmetic, never a host clock.
28
+ implied_by(rv_digits(S, N), [atom_chars(S, Cs), number_chars(N, Cs)]);
29
+ fact(rv_zone('Z', 'utc', 0), rv_zone('', 'local', 0));
30
+ implied_by(rv_zone(Z, 'utc', N), [regex_find('^([+-])([0-9]{2}):([0-9]{2})$', Z, [_, S, H0, M0]), rv_digits(H0, H), rv_digits(M0, M), le(H, 14), lt(M, 60), or(lt(H, 14), eq(M, 0)), is(A, add(mul(H, 3600), mul(M, 60))), rv_zone_sign(S, A, N)]);
31
+ fact(rv_zone_sign('+', N, N));
32
+ implied_by(rv_zone_sign('-', N, M), is(M, neg(N)));
33
+ implied_by(rv_leap(Y), [eq(mod(Y, 4), 0), or(ne(mod(Y, 100), 0), eq(mod(Y, 400), 0))]);
34
+ ${[31,28,31,30,31,30,31,31,30,31,30,31].map((n,i)=>`fact(rv_month(${i+1}, ${n}));`).join('\n')}
35
+ implied_by(rv_day(Y, M, D, N), [rv_month(M, Base), rv_month_days(Y, M, Base, Days), ge(D, 1), le(D, Days), is(A, sub(Y, 1)), is(B, add(sub(add(mul(365, A), floordiv(A, 4)), floordiv(A, 100)), floordiv(A, 400))), rv_month_offset(Y, M, O), is(N, add(add(B, O), sub(D, 1)))]);
36
+ implied_by(rv_month_days(Y, 2, 28, 29), rv_leap(Y));
37
+ implied_by(rv_month_days(Y, 2, 28, 28), not(rv_leap(Y)));
38
+ implied_by(rv_month_days(_, M, N, N), ne(M, 2));
39
+ ${[0,31,59,90,120,151,181,212,243,273,304,334].map((n,i)=>`fact(rv_month_base(${i+1}, ${n}));`).join('\n')}
40
+ implied_by(rv_month_offset(Y, M, O), [rv_month_base(M, B), gt(M, 2), rv_leap(Y), is(O, add(B, 1))]);
41
+ implied_by(rv_month_offset(Y, M, B), [rv_month_base(M, B), or(le(M, 2), not(rv_leap(Y)))]);
42
+ implied_by(rv_clock(H, M, decimal(S, Scale), decimal(N, Scale)), [ge(H, 0), le(H, 24), ge(M, 0), lt(M, 60), is(P, pow(10, Scale)), ge(S, 0), lt(S, mul(60, P)), or(lt(H, 24), and(eq(M, 0), eq(S, 0))), is(N, add(mul(add(mul(H, 3600), mul(M, 60)), P), S))]);
43
+ implied_by(rv_date(L, Kind, N), [regex_find('^[ \\t\\r\\n]*(-?(?:[0-9]{4}|[1-9][0-9]{4,}))-([0-9]{2})-([0-9]{2})(Z|[+-][0-9]{2}:[0-9]{2})?[ \\t\\r\\n]*$', L, [_, Y0, M0, D0, Z]), not_identical(Y0, '-0000'), rv_digits(Y0, Y), rv_digits(M0, M), rv_digits(D0, D), rv_day(Y, M, D, Day), rv_zone(Z, Kind, Offset), is(N, sub(mul(Day, 86400), Offset))]);
44
+ implied_by(rv_datetime(L, Kind, N), [regex_find('^[ \\t\\r\\n]*(-?(?:[0-9]{4}|[1-9][0-9]{4,})-[0-9]{2}-[0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\\.[0-9]+)?)(Z|[+-][0-9]{2}:[0-9]{2})?[ \\t\\r\\n]*$', L, [_, Day, H0, M0, S0, Z]), rv_date(Day, 'local', D), rv_digits(H0, H), rv_digits(M0, M), srl_decimal_text(S0, S), rv_clock(H, M, S, Time), rv_zone(Z, Kind, Offset), is(Base, sub(D, Offset)), srl_calculate('add', decimal(Base, 0), Time, N)]);
45
+ implied_by(rv_time(L, Kind, N), [regex_find('^[ \\t\\r\\n]*([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\\.[0-9]+)?)(Z|[+-][0-9]{2}:[0-9]{2})?[ \\t\\r\\n]*$', L, [_, H0, M0, S0, Z]), rv_digits(H0, H), rv_digits(M0, M), srl_decimal_text(S0, S), rv_clock(H, M, S, decimal(Time, Scale)), rv_zone(Z, Kind, Offset), is(P, pow(10, Scale)), is(C, sub(mod(Time, mul(86400, P)), mul(Offset, P))), unify(N, decimal(C, Scale))]);
46
+ implied_by(rv_lexical(rvXsd + 'date', L), rv_date(L, _, _));
47
+ implied_by(rv_lexical(rvXsd + 'dateTime', L), rv_datetime(L, _, _));
48
+ implied_by(rv_lexical(rvXsd + 'dateTimeStamp', L), rv_datetime(L, 'utc', _));
49
+ implied_by(rv_lexical(rvXsd + 'time', L), rv_time(L, _, _));
50
+ implied_by(rv_temporal(literal(L, datatype(rvXsd + 'date')), 'date', K, N), rv_date(L, K, N));
51
+ implied_by(rv_temporal(literal(L, datatype(rvXsd + 'dateTime')), 'dateTime', K, N), rv_datetime(L, K, N));
52
+ implied_by(rv_temporal(literal(L, datatype(rvXsd + 'dateTimeStamp')), 'dateTime', 'utc', N), rv_datetime(L, 'utc', N));
53
+ implied_by(rv_temporal(literal(L, datatype(rvXsd + 'time')), 'time', K, N), rv_time(L, K, N));
54
+ implied_by(rv_order(A, B, O), [rv_temporal(A, T, K, X), rv_temporal(B, T, K, Y), srl_decimal_value(X, A0), srl_decimal_value(Y, B0), srl_value_compare(A0, B0, O)]);
55
+ implied_by(rv_member(T, iri(rvXsd + 'dateTime')), [rv_datatype(T, iri(rvXsd + 'dateTimeStamp')), rv_valid(T)]);
56
+ `;
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`
59
+ const rvXsd = 'http://www.w3.org/2001/XMLSchema#';
60
+ const rvRdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
61
+ implied_by(rv_datatype(N, iri(rvXsd + 'integer')), is_int(N));
62
+ fact(rv_datatype(literal(_, datatype(D)), iri(D)));
63
+ fact(rv_datatype(literal(_, lang(_)), iri(rvRdf + 'langString')));
64
+ fact(rv_datatype(literal(_, lang(_, _)), iri(rvRdf + 'dirLangString')));
65
+ implied_by(rv_literal(T), rv_datatype(T, _));
66
+ implied_by(rv_valid(T), [rv_datatype(T, D), rv_valid_as(T, D)]);
67
+ implied_by(rv_valid_as(T, iri(rvXsd + 'integer')), is_int(T));
68
+ implied_by(rv_valid_as(literal(L, datatype(D)), iri(D)), rv_lexical(D, L));
69
+ fact(rv_valid_as(literal(_, lang(_)), iri(rvRdf + 'langString')));
70
+ fact(rv_valid_as(literal(_, lang(_, _)), iri(rvRdf + 'dirLangString')));
71
+ implied_by(rv_lexical(rvXsd + 'decimal', L), srl_decimal_text(L, _));
72
+ implied_by(rv_lexical(D, L), [rv_binary_type(D), regex_match('^[ \\t\\r\\n]*(?:[+-]?(?:(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?|INF)|NaN)[ \\t\\r\\n]*$', L)]);
73
+ fact(rv_binary_type(rvXsd + 'float'), rv_binary_type(rvXsd + 'double'));
74
+ implied_by(rv_lexical(rvXsd + 'boolean', L), regex_match('^[ \\t\\r\\n]*(true|false|0|1)[ \\t\\r\\n]*$', L));
75
+ implied_by(rv_lexical(D, L), [rv_text_type(D), is_atom(L)]);
76
+ fact(rv_text_type(rvXsd + 'string'), rv_text_type(rvXsd + 'normalizedString'), rv_text_type(rvXsd + 'token'), rv_text_type(rvXsd + 'anyURI'));
77
+ implied_by(rv_lexical(rvXsd + 'language', L), regex_match('^[ \\t\\r\\n]*[A-Za-z]{1,8}(?:-[A-Za-z0-9]{1,8})*[ \\t\\r\\n]*$', L));
78
+ implied_by(rv_lexical(rvXsd + 'hexBinary', L), regex_match('^[ \\t\\r\\n]*(?:[0-9A-Fa-f]{2})*[ \\t\\r\\n]*$', L));
79
+ implied_by(rv_lexical(rvXsd + 'base64Binary', L), [regex_replace('[ \\t\\r\\n]', L, '', S), regex_match('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/][AQgw]==|[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=)?$', S)]);
80
+ implied_by(rv_exact(T), [rv_valid(T), srl_num(T, K, _), rv_exact_kind(K)]);
81
+ fact(rv_exact_kind('integer'), rv_exact_kind('decimal'));
82
+ implied_by(rv_same(A, B), [rv_exact(A), rv_exact(B), srl_order(A, B, '=')]);
83
+ implied_by(rv_different(A, B), [rv_exact(A), rv_exact(B), srl_order(A, B, O), not_identical(O, '=')]);
84
+ implied_by(rv_same(A, B), [rv_boolean(A, V), rv_boolean(B, V)]);
85
+ implied_by(rv_different(A, B), [rv_boolean(A, V), rv_boolean(B, W), not_identical(V, W)]);
86
+ implied_by(rv_boolean(literal(L, datatype(rvXsd + 'boolean')), V), [regex_find('^[ \\t\\r\\n]*(true|false|0|1)[ \\t\\r\\n]*$', L, [_, S]), rv_boolean_text(S, V)]);
87
+ fact(rv_boolean_text('true', 'true'), rv_boolean_text('1', 'true'), rv_boolean_text('false', 'false'), rv_boolean_text('0', 'false'));
88
+ implied_by(rv_same(A, B), [rv_text_value(A, S), rv_text_value(B, S)]);
89
+ implied_by(rv_different(A, B), [rv_text_value(A, S), rv_text_value(B, T), not_identical(S, T)]);
90
+ fact(rv_text_value(literal(L, datatype(rvXsd + 'string')), L));
91
+ implied_by(rv_text_value(literal(L, datatype(rvXsd + 'normalizedString')), S), regex_replace('[\\t\\r\\n]', L, ' ', S));
92
+ implied_by(rv_text_value(literal(L, datatype(rvXsd + 'token')), S), [regex_replace('[ \\t\\r\\n]+', L, ' ', A), regex_replace('^ | $', A, '', S)]);
93
+ implied_by(rv_order(A, B, O), [rv_valid(A), rv_valid(B), srl_pair(A, B, _, X, Y), srl_value_compare(X, Y, O)]);
94
+ implied_by(rv_order(A, B, O), [rv_text_value(A, S), rv_text_value(B, T), compare(O, S, T)]);
95
+ implied_by(rv_integer_value(T, N), [rv_exact(T), srl_num(T, _, V), srl_decimal_value(V, decimal(C, S)), is(P, pow(10, S)), eq(mod(C, P), 0), is(N, floordiv(C, P))]);
96
+ implied_by(rv_member(T, iri(rvXsd + 'decimal')), rv_exact(T));
97
+ implied_by(rv_member(T, D), rv_valid_as(T, D));
98
+ ` + integerRules + '\n' + [...RDF_DATATYPES].map((d) => `fact(rv_supported(iri('${d}')));`).join('\n') + dateRules;