@rsconcept/domain 1.8.0 → 2.0.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/dist/{analyzer-DpE0qknt.d.ts → analyzer-iqAXyROE.d.ts} +2 -2
- package/dist/{arguments-extractor-Dd1lFom9.d.ts → arguments-extractor-ngatANBI.d.ts} +2 -2
- package/dist/{ast-annotations-CZCzs9Uk.d.ts → ast-annotations-D6KZDu12.d.ts} +2 -2
- package/dist/{calculator-Dt03dsnd.d.ts → calculator-k8BGIKmj.d.ts} +2 -2
- package/dist/diagnostics-Clo3mkba.d.ts +279 -0
- package/dist/diagnostics-DYMvTSev.js +532 -0
- package/dist/diagnostics-DYMvTSev.js.map +1 -0
- package/dist/index.d.ts +14 -15
- package/dist/index.js +7 -6
- package/dist/library/diagnostics.d.ts +2 -0
- package/dist/library/diagnostics.js +2 -0
- package/dist/library/index.d.ts +15 -6
- package/dist/library/index.js +41 -13
- package/dist/library/index.js.map +1 -1
- package/dist/library/oss-api.d.ts +1 -1
- package/dist/library/oss-api.js +1 -1
- package/dist/library/rsengine.d.ts +2 -3
- package/dist/library/rsengine.js +1 -1
- package/dist/library/rsform-api.d.ts +4 -4
- package/dist/library/rsform-api.js +1 -404
- package/dist/library/rsform.d.ts +2 -198
- package/dist/library/rsform.js.map +1 -1
- package/dist/library/rsmodel-api.d.ts +2 -3
- package/dist/library/rsmodel-api.js +2 -4
- package/dist/library/rsmodel-api.js.map +1 -1
- package/dist/library/rsmodel.d.ts +2 -46
- package/dist/library/structure-planner.d.ts +2 -2
- package/dist/library/structure-planner.js +1 -1
- package/dist/rslang/api.d.ts +1 -1
- package/dist/rslang/api.js +2 -1
- package/dist/rslang/api.js.map +1 -1
- package/dist/rslang/ast-annotations.d.ts +1 -1
- package/dist/rslang/eval/calculator.d.ts +1 -1
- package/dist/rslang/eval/evaluator.js +2 -2
- package/dist/rslang/eval/value-api.d.ts +1 -1
- package/dist/rslang/index.d.ts +8 -8
- package/dist/rslang/index.js +2 -2
- package/dist/rslang/labels.d.ts +4 -2
- package/dist/rslang/labels.js +8 -2
- package/dist/rslang/labels.js.map +1 -1
- package/dist/rslang/parser/syntax-errors/index.d.ts +1 -1
- package/dist/rslang/parser/syntax-errors/index.js +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +1 -1
- package/dist/rslang/semantic/analyzer.js +3 -3
- package/dist/rslang/semantic/arguments-extractor.d.ts +1 -1
- package/dist/rslang/semantic/arguments-extractor.js +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +1 -1
- package/dist/rslang/semantic/type-auditor.js +4 -4
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/typification-api.d.ts +1 -1
- package/dist/rslang/semantic/typification-parser.d.ts +1 -1
- package/dist/rslang/semantic/typification.d.ts +2 -2
- package/dist/rslang/semantic/typification.js +14 -6
- package/dist/rslang/semantic/typification.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.js +2 -2
- package/dist/rslang/typification-graph.d.ts +1 -1
- package/dist/{syntax-errors-B6c2vsan.js → syntax-errors-D_VV5hAM.js} +3 -3
- package/dist/{syntax-errors-B6c2vsan.js.map → syntax-errors-D_VV5hAM.js.map} +1 -1
- package/dist/{typification-DDuv88ir.d.ts → typification-9lNu9R4k.d.ts} +8 -4
- package/dist/{typification-graph-8VdK6_Fh.d.ts → typification-graph-BY_oGT82.d.ts} +2 -2
- package/dist/{typification-parser-DHO42ZRc.d.ts → typification-parser-Dytsv9CI.d.ts} +2 -2
- package/dist/{value-api-C2X4Pom5.d.ts → value-api-CXLl_zg0.d.ts} +2 -2
- package/package.json +5 -1
- package/src/index.ts +8 -0
- package/src/library/diagnostics.ts +188 -0
- package/src/library/index.ts +9 -0
- package/src/library/oss-api.test.ts +1 -2
- package/src/library/rsform-api.ts +12 -17
- package/src/library/rsform.ts +4 -2
- package/src/library/rsmodel-api.ts +2 -8
- package/src/library/template-instantiation.test.ts +123 -5
- package/src/library/template-instantiation.ts +42 -12
- package/src/rslang/api.ts +2 -1
- package/src/rslang/labels.ts +10 -1
- package/src/rslang/semantic/type-auditor.test.ts +25 -6
- package/src/rslang/semantic/type-auditor.ts +2 -1
- package/src/rslang/semantic/typification-api.test.ts +21 -5
- package/src/rslang/semantic/typification-parser.test.ts +6 -1
- package/src/rslang/semantic/typification.ts +16 -6
- package/dist/library/rsform-api.js.map +0 -1
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { TypeClass, TypeID, basic, bool, constant, isTypification } from "./rslang/semantic/typification.js";
|
|
2
|
+
import { labelType } from "./rslang/labels.js";
|
|
3
|
+
import { applyEntityReferenceMapping } from "./cctext/language-api.js";
|
|
4
|
+
import { RSErrorCode } from "./rslang/error.js";
|
|
5
|
+
import { generateExpressionFromAst } from "./rslang/parser/expression-generator.js";
|
|
6
|
+
import { applyAliasMapping, applyTypificationMapping, parseRSLangExpression } from "./rslang/api.js";
|
|
7
|
+
import { applyPath } from "./rslang/semantic/typification-api.js";
|
|
8
|
+
import { ValueClass } from "./rslang/semantic/value-class.js";
|
|
9
|
+
import "./rslang/index.js";
|
|
10
|
+
import { CstClass, CstStatus, CstType } from "./library/rsform.js";
|
|
11
|
+
import { EvalStatus } from "./library/rsmodel.js";
|
|
12
|
+
//#region src/library/rsform-api.ts
|
|
13
|
+
/**
|
|
14
|
+
* Module: API for formal representation for systems of concepts.
|
|
15
|
+
*/
|
|
16
|
+
/** Record of {@link CstType} prefixes. */
|
|
17
|
+
const CST_TYPE_PREFIX = {
|
|
18
|
+
[CstType.NOMINAL]: "N",
|
|
19
|
+
[CstType.BASE]: "X",
|
|
20
|
+
[CstType.CONSTANT]: "C",
|
|
21
|
+
[CstType.STRUCTURED]: "S",
|
|
22
|
+
[CstType.AXIOM]: "A",
|
|
23
|
+
[CstType.TERM]: "D",
|
|
24
|
+
[CstType.FUNCTION]: "F",
|
|
25
|
+
[CstType.PREDICATE]: "P",
|
|
26
|
+
[CstType.STATEMENT]: "T"
|
|
27
|
+
};
|
|
28
|
+
/** Record of {@link CstType} to {@link CstClass} mapping. */
|
|
29
|
+
const CST_TYPE_TO_CLASS = {
|
|
30
|
+
[CstType.NOMINAL]: CstClass.NOMINAL,
|
|
31
|
+
[CstType.BASE]: CstClass.BASIC,
|
|
32
|
+
[CstType.CONSTANT]: CstClass.BASIC,
|
|
33
|
+
[CstType.STRUCTURED]: CstClass.BASIC,
|
|
34
|
+
[CstType.TERM]: CstClass.DERIVED,
|
|
35
|
+
[CstType.FUNCTION]: CstClass.DERIVED,
|
|
36
|
+
[CstType.AXIOM]: CstClass.STATEMENT,
|
|
37
|
+
[CstType.PREDICATE]: CstClass.DERIVED,
|
|
38
|
+
[CstType.STATEMENT]: CstClass.STATEMENT
|
|
39
|
+
};
|
|
40
|
+
/** Checks if {@link Constituenta} is a schema issue. */
|
|
41
|
+
function isSchemaIssue(cst) {
|
|
42
|
+
return (cst.diagnostics?.length ?? 0) > 0 || cst.status === CstStatus.INCORRECT || cst.status === CstStatus.INCALCULABLE;
|
|
43
|
+
}
|
|
44
|
+
/** Infers the status of an expression based on parsing and value information. */
|
|
45
|
+
function inferStatus(parse, value) {
|
|
46
|
+
if (!parse) return CstStatus.INCORRECT;
|
|
47
|
+
if (value === null) return CstStatus.INCALCULABLE;
|
|
48
|
+
if (value === ValueClass.PROPERTY) return CstStatus.PROPERTY;
|
|
49
|
+
return CstStatus.VERIFIED;
|
|
50
|
+
}
|
|
51
|
+
/** Infers type of constituent for a given template and arguments. */
|
|
52
|
+
function inferTemplatedType(templateType, args) {
|
|
53
|
+
if (args.length === 0 || args.some((arg) => !arg.value)) return templateType;
|
|
54
|
+
else if (templateType === CstType.PREDICATE) return CstType.AXIOM;
|
|
55
|
+
else return CstType.TERM;
|
|
56
|
+
}
|
|
57
|
+
/** Build alias mapping from template argument bindings. */
|
|
58
|
+
function argumentValuesToMapping(args) {
|
|
59
|
+
const mapping = {};
|
|
60
|
+
for (const arg of args) if (arg.value) mapping[arg.alias] = arg.value;
|
|
61
|
+
return mapping;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Normalize a RSLang expression for duplicate comparison.
|
|
65
|
+
*
|
|
66
|
+
* Returns `null` for basic concepts without formal definitions. Pass a pre-parsed `ast`
|
|
67
|
+
* when the expression was already analyzed to avoid re-parsing.
|
|
68
|
+
*/
|
|
69
|
+
function normalizeExpression(expression, cst_type, ast) {
|
|
70
|
+
if (isBasicConcept(cst_type) && cst_type !== CstType.AXIOM) return null;
|
|
71
|
+
const parsed = ast ?? parseRSLangExpression(expression);
|
|
72
|
+
let normalized = "";
|
|
73
|
+
if (parsed && !parsed.hasError) normalized = generateExpressionFromAst(parsed, { normalize: true });
|
|
74
|
+
else normalized = expression;
|
|
75
|
+
normalized = normalized.replace(/\s+/g, "");
|
|
76
|
+
return normalized === "" ? null : normalized;
|
|
77
|
+
}
|
|
78
|
+
/** Checks if given expression is a template. */
|
|
79
|
+
function inferTemplate(expression) {
|
|
80
|
+
const match = expression.match(/R\d+/g);
|
|
81
|
+
return (match && match?.length > 0) ?? false;
|
|
82
|
+
}
|
|
83
|
+
/** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */
|
|
84
|
+
function inferClass(type, isTemplate = false) {
|
|
85
|
+
if (isTemplate) return CstClass.TEMPLATE;
|
|
86
|
+
return CST_TYPE_TO_CLASS[type];
|
|
87
|
+
}
|
|
88
|
+
/** Check if {@link Constituenta} is a template or a category. */
|
|
89
|
+
function isTemplateCst(cst) {
|
|
90
|
+
return cst.cst_type === CstType.FUNCTION || cst.cst_type === CstType.PREDICATE || cst.cst_type === CstType.STATEMENT;
|
|
91
|
+
}
|
|
92
|
+
/** Apply filter based on start {@link Constituenta} type. */
|
|
93
|
+
function applyFilterCategory(start, items) {
|
|
94
|
+
const startIndex = items.indexOf(start);
|
|
95
|
+
if (startIndex === -1) return [];
|
|
96
|
+
const nextCategoryIndex = items.findIndex((cst, index) => index > startIndex && cst.cst_type === CstType.STATEMENT);
|
|
97
|
+
return items.filter((_, index) => index >= startIndex && (nextCategoryIndex === -1 || index < nextCategoryIndex));
|
|
98
|
+
}
|
|
99
|
+
/** Prefix for alias indicating {@link CstType}. */
|
|
100
|
+
function getCstTypePrefix(type) {
|
|
101
|
+
return CST_TYPE_PREFIX[type];
|
|
102
|
+
}
|
|
103
|
+
/** Guess {@link CstType} from user input hint. */
|
|
104
|
+
function guessCstType(hint) {
|
|
105
|
+
if (hint.length !== 1) return null;
|
|
106
|
+
for (const [type, prefix] of Object.entries(CST_TYPE_PREFIX)) if (hint === prefix) return type;
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/** Evaluate if {@link CstType} is basic concept. */
|
|
110
|
+
function isBasicConcept(type) {
|
|
111
|
+
switch (type) {
|
|
112
|
+
case CstType.NOMINAL:
|
|
113
|
+
case CstType.BASE:
|
|
114
|
+
case CstType.CONSTANT:
|
|
115
|
+
case CstType.STRUCTURED:
|
|
116
|
+
case CstType.AXIOM: return true;
|
|
117
|
+
case CstType.TERM:
|
|
118
|
+
case CstType.FUNCTION:
|
|
119
|
+
case CstType.PREDICATE:
|
|
120
|
+
case CstType.STATEMENT: return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Evaluate if {@link CstType} is base set or constant set. */
|
|
124
|
+
function isBaseSet(type) {
|
|
125
|
+
switch (type) {
|
|
126
|
+
case CstType.BASE:
|
|
127
|
+
case CstType.CONSTANT: return true;
|
|
128
|
+
case CstType.NOMINAL:
|
|
129
|
+
case CstType.STRUCTURED:
|
|
130
|
+
case CstType.AXIOM:
|
|
131
|
+
case CstType.TERM:
|
|
132
|
+
case CstType.FUNCTION:
|
|
133
|
+
case CstType.PREDICATE:
|
|
134
|
+
case CstType.STATEMENT: return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Evaluate if {@link CstType} is a function. */
|
|
138
|
+
function isFunctional(type) {
|
|
139
|
+
switch (type) {
|
|
140
|
+
case CstType.FUNCTION:
|
|
141
|
+
case CstType.PREDICATE: return true;
|
|
142
|
+
case CstType.NOMINAL:
|
|
143
|
+
case CstType.BASE:
|
|
144
|
+
case CstType.CONSTANT:
|
|
145
|
+
case CstType.STRUCTURED:
|
|
146
|
+
case CstType.AXIOM:
|
|
147
|
+
case CstType.TERM:
|
|
148
|
+
case CstType.STATEMENT: return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Evaluate if {@link CstType} is logical. */
|
|
152
|
+
function isLogical(type) {
|
|
153
|
+
switch (type) {
|
|
154
|
+
case CstType.AXIOM:
|
|
155
|
+
case CstType.STATEMENT: return true;
|
|
156
|
+
case CstType.NOMINAL:
|
|
157
|
+
case CstType.BASE:
|
|
158
|
+
case CstType.CONSTANT:
|
|
159
|
+
case CstType.STRUCTURED:
|
|
160
|
+
case CstType.TERM:
|
|
161
|
+
case CstType.FUNCTION:
|
|
162
|
+
case CstType.PREDICATE: return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Evaluate if {@link Constituenta} can be used produce structure. */
|
|
166
|
+
function canProduceStructure(cst) {
|
|
167
|
+
switch (cst.cst_type) {
|
|
168
|
+
case CstType.NOMINAL:
|
|
169
|
+
case CstType.BASE:
|
|
170
|
+
case CstType.CONSTANT:
|
|
171
|
+
case CstType.AXIOM:
|
|
172
|
+
case CstType.STATEMENT:
|
|
173
|
+
case CstType.PREDICATE: return false;
|
|
174
|
+
}
|
|
175
|
+
if (!cst.effectiveType) return false;
|
|
176
|
+
if (cst.cst_type === CstType.FUNCTION) {
|
|
177
|
+
const result = cst.effectiveType.result;
|
|
178
|
+
return typeCanProduceStructure(result);
|
|
179
|
+
}
|
|
180
|
+
if (!isTypification(cst.effectiveType)) return false;
|
|
181
|
+
return typeCanProduceStructure(cst.effectiveType);
|
|
182
|
+
}
|
|
183
|
+
/** Evaluate if {@link CstType} can have manual typification. */
|
|
184
|
+
function canHaveManualTypification(type) {
|
|
185
|
+
switch (type) {
|
|
186
|
+
case CstType.STRUCTURED:
|
|
187
|
+
case CstType.TERM:
|
|
188
|
+
case CstType.FUNCTION:
|
|
189
|
+
case CstType.PREDICATE: return true;
|
|
190
|
+
case CstType.NOMINAL:
|
|
191
|
+
case CstType.BASE:
|
|
192
|
+
case CstType.CONSTANT:
|
|
193
|
+
case CstType.AXIOM:
|
|
194
|
+
case CstType.STATEMENT: return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */
|
|
198
|
+
function validateAliasFormat(alias, type) {
|
|
199
|
+
if (alias.length < 2) return false;
|
|
200
|
+
const prefix = getCstTypePrefix(type);
|
|
201
|
+
if (!alias.startsWith(prefix)) return false;
|
|
202
|
+
if (!/^\d+$/.exec(alias.substring(prefix.length))) return false;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
/** Validate new alias against {@link CstType} and {@link RSForm}. */
|
|
206
|
+
function validateNewAlias(alias, type, schema) {
|
|
207
|
+
if (!validateAliasFormat(alias, type)) return false;
|
|
208
|
+
if (schema.cstByAlias.has(alias)) return false;
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
/** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */
|
|
212
|
+
function generateAlias(type, schema, takenAliases = []) {
|
|
213
|
+
const prefix = getCstTypePrefix(type);
|
|
214
|
+
if (schema.items.length <= 0) return `${prefix}1`;
|
|
215
|
+
let index = schema.items.reduce((prev, cst, index) => {
|
|
216
|
+
if (cst.cst_type !== type) return prev;
|
|
217
|
+
index = Number(cst.alias.slice(1 - cst.alias.length)) + 1;
|
|
218
|
+
return Math.max(prev, index);
|
|
219
|
+
}, 1);
|
|
220
|
+
let alias = `${prefix}${index}`;
|
|
221
|
+
while (takenAliases.includes(alias)) {
|
|
222
|
+
index = index + 1;
|
|
223
|
+
alias = `${prefix}${index}`;
|
|
224
|
+
}
|
|
225
|
+
return alias;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:
|
|
229
|
+
* after the last existing child of that spawner, or after the spawner itself if none.
|
|
230
|
+
*/
|
|
231
|
+
function inferNewSpawnPosition(schema, targetId) {
|
|
232
|
+
let last = null;
|
|
233
|
+
for (const cst of schema.items) if (cst.spawner === targetId) last = cst.id;
|
|
234
|
+
return last ?? targetId;
|
|
235
|
+
}
|
|
236
|
+
/** Sorts library items relevant for InlineSynthesis with specified {@link RSForm}. */
|
|
237
|
+
function sortItemsForInlineSynthesis(receiver, items) {
|
|
238
|
+
const result = items.filter((item) => item.location === receiver.location);
|
|
239
|
+
for (const item of items) if (item.visible && item.owner === item.owner && !result.includes(item)) result.push(item);
|
|
240
|
+
for (const item of items) if (item.visible && !result.includes(item)) result.push(item);
|
|
241
|
+
for (const item of items) if (!result.includes(item)) result.push(item);
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Remap formal expressions and terminological entity references in constituent fields.
|
|
246
|
+
* Mutates each element of `items` in place; pass owned or cloned data only.
|
|
247
|
+
*/
|
|
248
|
+
function applyMappingToConstituents(items, mapping, changeAliases) {
|
|
249
|
+
for (const cst of items) {
|
|
250
|
+
if (changeAliases && cst.alias in mapping) cst.alias = mapping[cst.alias];
|
|
251
|
+
cst.definition_formal = applyAliasMapping(cst.definition_formal, mapping);
|
|
252
|
+
cst.typification_manual = applyTypificationMapping(cst.typification_manual, mapping);
|
|
253
|
+
cst.term_raw = applyEntityReferenceMapping(cst.term_raw, mapping);
|
|
254
|
+
cst.definition_raw = applyEntityReferenceMapping(cst.definition_raw, mapping);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/** Remove alias from expression. */
|
|
258
|
+
function removeAliasReference(expression, alias) {
|
|
259
|
+
const result = expression.replaceAll(new RegExp(`\\b${alias}\\b`, "g"), "DEL");
|
|
260
|
+
return result === "DEL" ? "" : result;
|
|
261
|
+
}
|
|
262
|
+
/** Add alias to expression. */
|
|
263
|
+
function addAliasReference(expression, alias) {
|
|
264
|
+
return expression + " " + alias;
|
|
265
|
+
}
|
|
266
|
+
/** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */
|
|
267
|
+
function typeClassForCstType(cstType) {
|
|
268
|
+
switch (cstType) {
|
|
269
|
+
case CstType.NOMINAL:
|
|
270
|
+
case CstType.BASE:
|
|
271
|
+
case CstType.CONSTANT:
|
|
272
|
+
case CstType.STRUCTURED:
|
|
273
|
+
case CstType.TERM: return TypeClass.typification;
|
|
274
|
+
case CstType.FUNCTION: return TypeClass.function;
|
|
275
|
+
case CstType.PREDICATE: return TypeClass.predicate;
|
|
276
|
+
case CstType.AXIOM:
|
|
277
|
+
case CstType.STATEMENT: return TypeClass.logic;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/** Checks whether a constituenta type supports formal definitions. */
|
|
281
|
+
function canHaveFormalDefinition(cstType) {
|
|
282
|
+
return cstType !== CstType.BASE && cstType !== CstType.CONSTANT;
|
|
283
|
+
}
|
|
284
|
+
/** Analyze expression for {@link RSForm}. */
|
|
285
|
+
function getAnalysisFor(expression, cstType, schema, alias) {
|
|
286
|
+
if (!canHaveFormalDefinition(cstType)) {
|
|
287
|
+
if (expression.trim().length === 0) {
|
|
288
|
+
const fallbackAlias = alias && alias.length > 0 ? alias : "X0";
|
|
289
|
+
return {
|
|
290
|
+
success: true,
|
|
291
|
+
type: cstType === CstType.BASE ? bool(basic(fallbackAlias)) : bool(constant(fallbackAlias)),
|
|
292
|
+
valueClass: ValueClass.VALUE,
|
|
293
|
+
errors: [],
|
|
294
|
+
ast: null
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
success: false,
|
|
299
|
+
type: null,
|
|
300
|
+
valueClass: null,
|
|
301
|
+
errors: [{
|
|
302
|
+
code: RSErrorCode.definitionNotAllowed,
|
|
303
|
+
from: 0,
|
|
304
|
+
to: Math.max(expression.length, 1),
|
|
305
|
+
params: [cstType, alias ?? ""]
|
|
306
|
+
}],
|
|
307
|
+
ast: null
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return schema.analyzer.checkFull(expression, {
|
|
311
|
+
expected: typeClassForCstType(cstType),
|
|
312
|
+
isDomain: cstType === CstType.STRUCTURED
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
/** Calculate statistics for {@link RSForm}. */
|
|
316
|
+
function calculateSchemaStats(target) {
|
|
317
|
+
const items = target.items;
|
|
318
|
+
return {
|
|
319
|
+
count_all: items.length,
|
|
320
|
+
count_crucial: items.reduce((sum, cst) => sum + (cst.crucial ? 1 : 0), 0),
|
|
321
|
+
step_complexity: items.reduce((sum, cst) => sum + calculateStepComplexity(cst), 0),
|
|
322
|
+
count_problematic: items.reduce((sum, cst) => sum + (isSchemaIssue(cst) ? 1 : 0), 0),
|
|
323
|
+
count_homonyms: items.reduce((sum, cst) => sum + (hasCstDiagnostic(cst, RSDiagnosticCode.schemaHomonym) ? 1 : 0), 0),
|
|
324
|
+
count_formal_duplicates: items.reduce((sum, cst) => sum + (hasCstDiagnostic(cst, RSDiagnosticCode.schemaFormalDuplicate) ? 1 : 0), 0),
|
|
325
|
+
count_missing_convention: items.reduce((sum, cst) => sum + (isMissingConvention(cst) ? 1 : 0), 0),
|
|
326
|
+
count_type_mismatch: items.reduce((sum, cst) => sum + (cst.is_type_mismatch ? 1 : 0), 0),
|
|
327
|
+
count_incorrect: items.reduce((sum, cst) => sum + (cst.status === CstStatus.INCORRECT ? 1 : 0), 0),
|
|
328
|
+
count_property: items.reduce((sum, cst) => sum + (cst.analysis?.valueClass === ValueClass.PROPERTY ? 1 : 0), 0),
|
|
329
|
+
count_incalculable: items.reduce((sum, cst) => sum + (cst.analysis?.success && cst.analysis.valueClass === null ? 1 : 0), 0),
|
|
330
|
+
count_inherited: items.reduce((sum, cst) => sum + (cst.is_inherited ? 1 : 0), 0),
|
|
331
|
+
count_text_term: items.reduce((sum, cst) => sum + (cst.term_raw ? 1 : 0), 0),
|
|
332
|
+
count_definition: items.reduce((sum, cst) => sum + (cst.definition_raw ? 1 : 0), 0),
|
|
333
|
+
count_convention: items.reduce((sum, cst) => sum + (isBasicConcept(cst.cst_type) && cst.convention ? 1 : 0), 0),
|
|
334
|
+
count_comment: items.reduce((sum, cst) => sum + (!isBasicConcept(cst.cst_type) && !cst.convention ? 1 : 0), 0),
|
|
335
|
+
count_base: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.BASE ? 1 : 0), 0),
|
|
336
|
+
count_constant: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.CONSTANT ? 1 : 0), 0),
|
|
337
|
+
count_structured: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STRUCTURED ? 1 : 0), 0),
|
|
338
|
+
count_axiom: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.AXIOM ? 1 : 0), 0),
|
|
339
|
+
count_term: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.TERM ? 1 : 0), 0),
|
|
340
|
+
count_function: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.FUNCTION ? 1 : 0), 0),
|
|
341
|
+
count_predicate: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.PREDICATE ? 1 : 0), 0),
|
|
342
|
+
count_statement: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STATEMENT ? 1 : 0), 0),
|
|
343
|
+
count_nominal: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.NOMINAL ? 1 : 0), 0)
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/** Finds {@link Constituenta} by structure path. */
|
|
347
|
+
function findCstByStructure(schema, target, path) {
|
|
348
|
+
for (const cst of schema.items) if (cst.spawner === target.id && cst.spawner_path) {
|
|
349
|
+
if (cst.spawner_path.length === path.length && cst.spawner_path.every((v, i) => v === path[i])) return cst;
|
|
350
|
+
}
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
/** Retrieves name for piece of target {@link Constituenta} structure. */
|
|
354
|
+
function getStructureName(schema, target, path) {
|
|
355
|
+
const representation = findCstByStructure(schema, target, path);
|
|
356
|
+
if (representation) return `${representation.alias}: ${representation.term_resolved}`;
|
|
357
|
+
if (!isTypification(target.effectiveType)) return "";
|
|
358
|
+
const type = applyPath(target.effectiveType, path);
|
|
359
|
+
if (type?.typeID === TypeID.basic) {
|
|
360
|
+
const cst = schema.cstByAlias.get(type.baseID);
|
|
361
|
+
if (cst?.term_resolved) return `${cst.alias}: ${cst.term_resolved}`;
|
|
362
|
+
}
|
|
363
|
+
return "";
|
|
364
|
+
}
|
|
365
|
+
function calculateStepComplexity(cst) {
|
|
366
|
+
if (cst.cst_type === CstType.AXIOM || cst.cst_type === CstType.NOMINAL || !isBasicConcept(cst.cst_type)) return 0;
|
|
367
|
+
if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT || !cst.effectiveType) return 1;
|
|
368
|
+
const type = cst.effectiveType;
|
|
369
|
+
return calculateTypificationComplexity(type) + 1;
|
|
370
|
+
}
|
|
371
|
+
function calculateTypificationComplexity(type) {
|
|
372
|
+
switch (type.typeID) {
|
|
373
|
+
case TypeID.basic:
|
|
374
|
+
case TypeID.integer:
|
|
375
|
+
case TypeID.anyTypification: return 0;
|
|
376
|
+
case TypeID.tuple: return type.factors.length + type.factors.reduce((sum, factor) => sum + calculateTypificationComplexity(factor), 0);
|
|
377
|
+
case TypeID.collection:
|
|
378
|
+
if (type.base.typeID === TypeID.tuple) {
|
|
379
|
+
let sum = 0;
|
|
380
|
+
type.base.factors.forEach((factor) => {
|
|
381
|
+
sum += calculateTypificationComplexity(factor);
|
|
382
|
+
});
|
|
383
|
+
return sum + type.base.factors.length;
|
|
384
|
+
} else if (type.base.typeID === TypeID.collection) return calculateTypificationComplexity(type.base) + 1;
|
|
385
|
+
return 0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function isMissingConvention(cst) {
|
|
389
|
+
if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {
|
|
390
|
+
if (!cst.convention || !cst.term_resolved) return true;
|
|
391
|
+
}
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
/** Evaluate if {@link Typification} can be used to produce structure. */
|
|
395
|
+
function typeCanProduceStructure(type) {
|
|
396
|
+
if (type.typeID === TypeID.basic || type.typeID === TypeID.integer || type.typeID === TypeID.anyTypification) return false;
|
|
397
|
+
else if (type.typeID === TypeID.tuple) return true;
|
|
398
|
+
else return type.base.typeID !== TypeID.basic && type.base.typeID !== TypeID.integer && type.base.typeID !== TypeID.anyTypification;
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/library/diagnostics.ts
|
|
402
|
+
/**
|
|
403
|
+
* Module: Compact diagnostics for constituents (schema and model issue codes).
|
|
404
|
+
*/
|
|
405
|
+
/** Origin of a diagnostic. */
|
|
406
|
+
const DiagnosticKind = {
|
|
407
|
+
EXPRESSION: "expression",
|
|
408
|
+
SCHEMA: "schema",
|
|
409
|
+
MODEL: "model"
|
|
410
|
+
};
|
|
411
|
+
/** Schema and model diagnostic codes (same numeric format as {@link RSErrorCode}). */
|
|
412
|
+
const RSDiagnosticCode = {
|
|
413
|
+
schemaHomonym: 35073,
|
|
414
|
+
schemaFormalDuplicate: 35074,
|
|
415
|
+
schemaMissingConvention: 35075,
|
|
416
|
+
schemaMissingTerm: 35076,
|
|
417
|
+
schemaTypeMismatch: 35077,
|
|
418
|
+
modelEmpty: 35088,
|
|
419
|
+
modelAxiomFalse: 35089,
|
|
420
|
+
modelInvalidData: 35090,
|
|
421
|
+
modelEvalFail: 35091
|
|
422
|
+
};
|
|
423
|
+
/** Whether a constituent has a schema/model diagnostic with the given code. */
|
|
424
|
+
function hasCstDiagnostic(cst, code) {
|
|
425
|
+
return cst.diagnostics?.some((item) => item.code === code) ?? false;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Populate `diagnostics` on each constituent (homonyms, duplicates, metadata, type mismatch).
|
|
429
|
+
*
|
|
430
|
+
* Requires normalized formal definitions for duplicate detection (same as Portal loader).
|
|
431
|
+
*/
|
|
432
|
+
function assignSchemaDiagnostics(items, resolveAlias, normalizedDefinitions) {
|
|
433
|
+
const homonymById = detectHomonymDiagnostics(items, resolveAlias);
|
|
434
|
+
const duplicateById = detectFormalDuplicateDiagnostics(items, resolveAlias, normalizedDefinitions);
|
|
435
|
+
for (const cst of items) {
|
|
436
|
+
const diagnostics = [];
|
|
437
|
+
const homonym = homonymById.get(cst.id);
|
|
438
|
+
if (homonym) diagnostics.push(homonym);
|
|
439
|
+
const duplicate = duplicateById.get(cst.id);
|
|
440
|
+
if (duplicate) diagnostics.push(duplicate);
|
|
441
|
+
diagnostics.push(...collectLocalSchemaDiagnostics(cst));
|
|
442
|
+
cst.diagnostics = diagnostics;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/** Map a model evaluation status to a compact diagnostic, or `null` when not an issue. */
|
|
446
|
+
function modelStatusCstDiagnostic(status, cstType) {
|
|
447
|
+
const code = modelStatusToCode(status, cstType);
|
|
448
|
+
if (code === null) return null;
|
|
449
|
+
return {
|
|
450
|
+
kind: DiagnosticKind.MODEL,
|
|
451
|
+
code,
|
|
452
|
+
params: [String(status)]
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
function collectLocalSchemaDiagnostics(cst) {
|
|
456
|
+
const result = [];
|
|
457
|
+
if (cst.is_type_mismatch) result.push({
|
|
458
|
+
kind: DiagnosticKind.SCHEMA,
|
|
459
|
+
code: RSDiagnosticCode.schemaTypeMismatch,
|
|
460
|
+
params: [cst.typification_manual, labelType(cst.analysis.type)]
|
|
461
|
+
});
|
|
462
|
+
if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {
|
|
463
|
+
if (!cst.convention.trim()) result.push({
|
|
464
|
+
kind: DiagnosticKind.SCHEMA,
|
|
465
|
+
code: RSDiagnosticCode.schemaMissingConvention
|
|
466
|
+
});
|
|
467
|
+
if (!cst.term_resolved.trim()) result.push({
|
|
468
|
+
kind: DiagnosticKind.SCHEMA,
|
|
469
|
+
code: RSDiagnosticCode.schemaMissingTerm
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return result;
|
|
473
|
+
}
|
|
474
|
+
function detectHomonymDiagnostics(items, resolveAlias) {
|
|
475
|
+
const byTerm = /* @__PURE__ */ new Map();
|
|
476
|
+
for (const cst of items) {
|
|
477
|
+
const key = cst.term_resolved.trim().toLocaleLowerCase();
|
|
478
|
+
if (key === "") continue;
|
|
479
|
+
const group = byTerm.get(key) ?? [];
|
|
480
|
+
group.push(cst);
|
|
481
|
+
byTerm.set(key, group);
|
|
482
|
+
}
|
|
483
|
+
const result = /* @__PURE__ */ new Map();
|
|
484
|
+
for (const group of byTerm.values()) {
|
|
485
|
+
if (group.length <= 1) continue;
|
|
486
|
+
for (const cst of group) {
|
|
487
|
+
const aliases = group.filter((other) => other.id !== cst.id).map((other) => resolveAlias(other.id)).join(", ");
|
|
488
|
+
result.set(cst.id, {
|
|
489
|
+
kind: DiagnosticKind.SCHEMA,
|
|
490
|
+
code: RSDiagnosticCode.schemaHomonym,
|
|
491
|
+
params: [aliases]
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return result;
|
|
496
|
+
}
|
|
497
|
+
function detectFormalDuplicateDiagnostics(items, resolveAlias, normalizedDefinitions) {
|
|
498
|
+
const byDefinition = /* @__PURE__ */ new Map();
|
|
499
|
+
for (const cst of items) {
|
|
500
|
+
const key = normalizedDefinitions.get(cst.id);
|
|
501
|
+
if (!key) continue;
|
|
502
|
+
const group = byDefinition.get(key) ?? [];
|
|
503
|
+
group.push(cst);
|
|
504
|
+
byDefinition.set(key, group);
|
|
505
|
+
}
|
|
506
|
+
const result = /* @__PURE__ */ new Map();
|
|
507
|
+
for (const group of byDefinition.values()) {
|
|
508
|
+
if (group.length <= 1) continue;
|
|
509
|
+
for (const cst of group) {
|
|
510
|
+
const aliases = group.filter((other) => other.id !== cst.id).map((other) => resolveAlias(other.id)).join(", ");
|
|
511
|
+
result.set(cst.id, {
|
|
512
|
+
kind: DiagnosticKind.SCHEMA,
|
|
513
|
+
code: RSDiagnosticCode.schemaFormalDuplicate,
|
|
514
|
+
params: [aliases]
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return result;
|
|
519
|
+
}
|
|
520
|
+
function modelStatusToCode(status, cstType) {
|
|
521
|
+
switch (status) {
|
|
522
|
+
case EvalStatus.EMPTY: return isBasicConcept(cstType) ? RSDiagnosticCode.modelEmpty : null;
|
|
523
|
+
case EvalStatus.AXIOM_FALSE: return RSDiagnosticCode.modelAxiomFalse;
|
|
524
|
+
case EvalStatus.INVALID_DATA: return RSDiagnosticCode.modelInvalidData;
|
|
525
|
+
case EvalStatus.EVAL_FAIL: return RSDiagnosticCode.modelEvalFail;
|
|
526
|
+
default: return null;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
//#endregion
|
|
530
|
+
export { isTemplateCst as A, inferTemplate as C, isFunctional as D, isBasicConcept as E, validateAliasFormat as F, validateNewAlias as I, removeAliasReference as M, sortItemsForInlineSynthesis as N, isLogical as O, typeClassForCstType as P, inferStatus as S, isBaseSet as T, getCstTypePrefix as _, modelStatusCstDiagnostic as a, inferClass as b, applyMappingToConstituents as c, canHaveFormalDefinition as d, canHaveManualTypification as f, getAnalysisFor as g, generateAlias as h, hasCstDiagnostic as i, normalizeExpression as j, isSchemaIssue as k, argumentValuesToMapping as l, findCstByStructure as m, RSDiagnosticCode as n, addAliasReference as o, canProduceStructure as p, assignSchemaDiagnostics as r, applyFilterCategory as s, DiagnosticKind as t, calculateSchemaStats as u, getStructureName as v, inferTemplatedType as w, inferNewSpawnPosition as x, guessCstType as y };
|
|
531
|
+
|
|
532
|
+
//# sourceMappingURL=diagnostics-DYMvTSev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics-DYMvTSev.js","names":[],"sources":["../src/library/rsform-api.ts","../src/library/diagnostics.ts"],"sourcesContent":["/**\n * Module: API for formal representation for systems of concepts.\n */\n\nimport { applyEntityReferenceMapping } from '../cctext/language-api';\nimport { type AstNode } from '../parsing';\nimport {\n type AnalysisFull,\n RSErrorCode,\n TypeClass,\n TypeID,\n type TypePath,\n type Typification,\n ValueClass\n} from '../rslang';\nimport {\n type AliasMapping,\n applyAliasMapping,\n applyTypificationMapping,\n generateExpressionFromAst,\n parseRSLangExpression\n} from '../rslang/api';\nimport { basic, bool, constant, type EchelonFunctional, isTypification } from '../rslang/semantic/typification';\nimport { applyPath } from '../rslang/semantic/typification-api';\n\nimport { hasCstDiagnostic, RSDiagnosticCode } from './diagnostics';\nimport { type LibraryItem } from './library';\nimport {\n type ArgumentValue,\n type Constituenta,\n CstClass,\n CstStatus,\n CstType,\n type RSForm,\n type RSFormStats\n} from './rsform';\n\n/** Record of {@link CstType} prefixes. */\nconst CST_TYPE_PREFIX: Record<CstType, string> = {\n [CstType.NOMINAL]: 'N',\n [CstType.BASE]: 'X',\n [CstType.CONSTANT]: 'C',\n [CstType.STRUCTURED]: 'S',\n [CstType.AXIOM]: 'A',\n [CstType.TERM]: 'D',\n [CstType.FUNCTION]: 'F',\n [CstType.PREDICATE]: 'P',\n [CstType.STATEMENT]: 'T'\n};\n\n/** Record of {@link CstType} to {@link CstClass} mapping. */\nconst CST_TYPE_TO_CLASS: Record<CstType, CstClass> = {\n [CstType.NOMINAL]: CstClass.NOMINAL,\n [CstType.BASE]: CstClass.BASIC,\n [CstType.CONSTANT]: CstClass.BASIC,\n [CstType.STRUCTURED]: CstClass.BASIC,\n [CstType.TERM]: CstClass.DERIVED,\n [CstType.FUNCTION]: CstClass.DERIVED,\n [CstType.AXIOM]: CstClass.STATEMENT,\n [CstType.PREDICATE]: CstClass.DERIVED,\n [CstType.STATEMENT]: CstClass.STATEMENT\n};\n\n/** Checks if {@link Constituenta} is a schema issue. */\nexport function isSchemaIssue(cst: Constituenta): boolean {\n return (\n (cst.diagnostics?.length ?? 0) > 0 || cst.status === CstStatus.INCORRECT || cst.status === CstStatus.INCALCULABLE\n );\n}\n\n/** Infers the status of an expression based on parsing and value information. */\nexport function inferStatus(parse: boolean, value?: ValueClass | null): CstStatus {\n if (!parse) {\n return CstStatus.INCORRECT;\n }\n if (value === null) {\n return CstStatus.INCALCULABLE;\n }\n if (value === ValueClass.PROPERTY) {\n return CstStatus.PROPERTY;\n }\n return CstStatus.VERIFIED;\n}\n\n/** Infers type of constituent for a given template and arguments. */\nexport function inferTemplatedType(templateType: CstType, args: ArgumentValue[]): CstType {\n if (args.length === 0 || args.some(arg => !arg.value)) {\n return templateType;\n } else if (templateType === CstType.PREDICATE) {\n return CstType.AXIOM;\n } else {\n return CstType.TERM;\n }\n}\n\n/** Build alias mapping from template argument bindings. */\nexport function argumentValuesToMapping(args: ArgumentValue[]): AliasMapping {\n const mapping: AliasMapping = {};\n for (const arg of args) {\n if (arg.value) {\n mapping[arg.alias] = arg.value;\n }\n }\n return mapping;\n}\n\n/**\n * Normalize a RSLang expression for duplicate comparison.\n *\n * Returns `null` for basic concepts without formal definitions. Pass a pre-parsed `ast`\n * when the expression was already analyzed to avoid re-parsing.\n */\nexport function normalizeExpression(expression: string, cst_type: CstType, ast?: AstNode | null): string | null {\n if (isBasicConcept(cst_type) && cst_type !== CstType.AXIOM) {\n return null;\n }\n const parsed = ast ?? parseRSLangExpression(expression);\n let normalized = '';\n if (parsed && !parsed.hasError) {\n normalized = generateExpressionFromAst(parsed, { normalize: true });\n } else {\n normalized = expression;\n }\n normalized = normalized.replace(/\\s+/g, '');\n return normalized === '' ? null : normalized;\n}\n\n/** Checks if given expression is a template. */\nexport function inferTemplate(expression: string): boolean {\n const match = expression.match(/R\\d+/g);\n return (match && match?.length > 0) ?? false;\n}\n\n/** Infers the {@link CstClass} based on the provided {@link CstType} and template status. */\nexport function inferClass(type: CstType, isTemplate: boolean = false): CstClass {\n if (isTemplate) {\n return CstClass.TEMPLATE;\n }\n return CST_TYPE_TO_CLASS[type];\n}\n\n/** Check if {@link Constituenta} is a template or a category. */\nexport function isTemplateCst(cst: Constituenta): boolean {\n return cst.cst_type === CstType.FUNCTION || cst.cst_type === CstType.PREDICATE || cst.cst_type === CstType.STATEMENT;\n}\n\n/** Apply filter based on start {@link Constituenta} type. */\nexport function applyFilterCategory(start: Constituenta, items: Constituenta[]): Constituenta[] {\n const startIndex = items.indexOf(start);\n if (startIndex === -1) {\n return [];\n }\n const nextCategoryIndex = items.findIndex((cst, index) => index > startIndex && cst.cst_type === CstType.STATEMENT);\n\n return items.filter((_, index) => index >= startIndex && (nextCategoryIndex === -1 || index < nextCategoryIndex));\n}\n\n/** Prefix for alias indicating {@link CstType}. */\nexport function getCstTypePrefix(type: CstType): string {\n return CST_TYPE_PREFIX[type];\n}\n\n/** Guess {@link CstType} from user input hint. */\nexport function guessCstType(hint: string): CstType | null {\n if (hint.length !== 1) {\n return null;\n }\n for (const [type, prefix] of Object.entries(CST_TYPE_PREFIX)) {\n if (hint === prefix) {\n return type as CstType;\n }\n }\n return null;\n}\n\n/** Evaluate if {@link CstType} is basic concept. */\nexport function isBasicConcept(type: CstType): boolean {\n switch (type) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n return true;\n\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is base set or constant set. */\nexport function isBaseSet(type: CstType): boolean {\n switch (type) {\n case CstType.BASE:\n case CstType.CONSTANT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is a function. */\nexport function isFunctional(type: CstType): boolean {\n switch (type) {\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.AXIOM:\n case CstType.TERM:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Evaluate if {@link CstType} is logical. */\nexport function isLogical(type: CstType): boolean {\n switch (type) {\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return false;\n }\n}\n\n/** Evaluate if {@link Constituenta} can be used produce structure. */\nexport function canProduceStructure(cst: Constituenta): boolean {\n switch (cst.cst_type) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.AXIOM:\n case CstType.STATEMENT:\n case CstType.PREDICATE:\n return false;\n }\n if (!cst.effectiveType) {\n return false;\n }\n if (cst.cst_type === CstType.FUNCTION) {\n const result = (cst.effectiveType as EchelonFunctional).result;\n return typeCanProduceStructure(result);\n }\n if (!isTypification(cst.effectiveType)) {\n return false;\n }\n return typeCanProduceStructure(cst.effectiveType as Typification);\n}\n\n/** Evaluate if {@link CstType} can have manual typification. */\nexport function canHaveManualTypification(type: CstType): boolean {\n switch (type) {\n case CstType.STRUCTURED:\n case CstType.TERM:\n case CstType.FUNCTION:\n case CstType.PREDICATE:\n return true;\n\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return false;\n }\n}\n\n/** Validate alias format for a given {@link CstType} (prefix + digits, min length 2). */\nexport function validateAliasFormat(alias: string, type: CstType): boolean {\n if (alias.length < 2) {\n return false;\n }\n const prefix = getCstTypePrefix(type);\n if (!alias.startsWith(prefix)) {\n return false;\n }\n if (!/^\\d+$/.exec(alias.substring(prefix.length))) {\n return false;\n }\n return true;\n}\n\n/** Validate new alias against {@link CstType} and {@link RSForm}. */\nexport function validateNewAlias(alias: string, type: CstType, schema: RSForm): boolean {\n if (!validateAliasFormat(alias, type)) {\n return false;\n }\n if (schema.cstByAlias.has(alias)) {\n return false;\n }\n return true;\n}\n\n/** Generate alias for new {@link Constituenta} of a given {@link CstType} for current {@link RSForm}. */\nexport function generateAlias(type: CstType, schema: RSForm, takenAliases: string[] = []): string {\n const prefix = getCstTypePrefix(type);\n if (schema.items.length <= 0) {\n return `${prefix}1`;\n }\n let index = schema.items.reduce((prev, cst, index) => {\n if (cst.cst_type !== type) {\n return prev;\n }\n index = Number(cst.alias.slice(1 - cst.alias.length)) + 1;\n return Math.max(prev, index);\n }, 1);\n let alias = `${prefix}${index}`;\n while (takenAliases.includes(alias)) {\n index = index + 1;\n alias = `${prefix}${index}`;\n }\n return alias;\n}\n\n/**\n * Id to pass as `insert_after` when creating a new {@link Constituenta} spawned by `targetId`:\n * after the last existing child of that spawner, or after the spawner itself if none.\n */\nexport function inferNewSpawnPosition(schema: RSForm, targetId: number): number {\n let last: number | null = null;\n for (const cst of schema.items) {\n if (cst.spawner === targetId) {\n last = cst.id;\n }\n }\n return last ?? targetId;\n}\n\n/** Sorts library items relevant for InlineSynthesis with specified {@link RSForm}. */\nexport function sortItemsForInlineSynthesis(receiver: RSForm, items: readonly LibraryItem[]): LibraryItem[] {\n const result = items.filter(item => item.location === receiver.location);\n for (const item of items) {\n if (item.visible && item.owner === item.owner && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (item.visible && !result.includes(item)) {\n result.push(item);\n }\n }\n for (const item of items) {\n if (!result.includes(item)) {\n result.push(item);\n }\n }\n return result;\n}\n\n/** Fields of {@link Constituenta} updated in place by alias mapping. */\nexport interface ConstituentaMappableFields {\n alias: string;\n definition_formal: string;\n typification_manual: string;\n term_raw: string;\n definition_raw: string;\n}\n\n/**\n * Remap formal expressions and terminological entity references in constituent fields.\n * Mutates each element of `items` in place; pass owned or cloned data only.\n */\nexport function applyMappingToConstituents<T extends ConstituentaMappableFields>(\n items: T[],\n mapping: AliasMapping,\n changeAliases: boolean\n): void {\n for (const cst of items) {\n if (changeAliases && cst.alias in mapping) {\n cst.alias = mapping[cst.alias];\n }\n cst.definition_formal = applyAliasMapping(cst.definition_formal, mapping);\n cst.typification_manual = applyTypificationMapping(cst.typification_manual, mapping);\n cst.term_raw = applyEntityReferenceMapping(cst.term_raw, mapping);\n cst.definition_raw = applyEntityReferenceMapping(cst.definition_raw, mapping);\n }\n}\n\n/** Remove alias from expression. */\nexport function removeAliasReference(expression: string, alias: string): string {\n const result = expression.replaceAll(new RegExp(`\\\\b${alias}\\\\b`, 'g'), 'DEL');\n return result === 'DEL' ? '' : result;\n}\n\n/** Add alias to expression. */\nexport function addAliasReference(expression: string, alias: string): string {\n return expression + ' ' + alias;\n}\n\n/** Returns expected {@link TypeClass} of formal definition for {@link CstType}. */\nexport function typeClassForCstType(cstType: CstType): TypeClass {\n switch (cstType) {\n case CstType.NOMINAL:\n case CstType.BASE:\n case CstType.CONSTANT:\n case CstType.STRUCTURED:\n case CstType.TERM:\n return TypeClass.typification;\n case CstType.FUNCTION:\n return TypeClass.function;\n case CstType.PREDICATE:\n return TypeClass.predicate;\n case CstType.AXIOM:\n case CstType.STATEMENT:\n return TypeClass.logic;\n }\n}\n\n/** Checks whether a constituenta type supports formal definitions. */\nexport function canHaveFormalDefinition(cstType: CstType): boolean {\n return cstType !== CstType.BASE && cstType !== CstType.CONSTANT;\n}\n\n/** Analyze expression for {@link RSForm}. */\nexport function getAnalysisFor(expression: string, cstType: CstType, schema: RSForm, alias?: string): AnalysisFull {\n if (!canHaveFormalDefinition(cstType)) {\n if (expression.trim().length === 0) {\n const fallbackAlias = alias && alias.length > 0 ? alias : 'X0';\n const type = cstType === CstType.BASE ? bool(basic(fallbackAlias)) : bool(constant(fallbackAlias));\n return {\n success: true,\n type,\n valueClass: ValueClass.VALUE,\n errors: [],\n ast: null\n };\n }\n return {\n success: false,\n type: null,\n valueClass: null,\n errors: [\n {\n code: RSErrorCode.definitionNotAllowed,\n from: 0,\n to: Math.max(expression.length, 1),\n params: [cstType, alias ?? '']\n }\n ],\n ast: null\n };\n }\n return schema.analyzer.checkFull(expression, {\n expected: typeClassForCstType(cstType),\n isDomain: cstType === CstType.STRUCTURED\n });\n}\n\n/** Calculate statistics for {@link RSForm}. */\nexport function calculateSchemaStats(target: RSForm): RSFormStats {\n const items = target.items;\n return {\n count_all: items.length,\n count_crucial: items.reduce((sum, cst) => sum + (cst.crucial ? 1 : 0), 0),\n\n step_complexity: items.reduce((sum, cst) => sum + calculateStepComplexity(cst), 0),\n\n count_problematic: items.reduce((sum, cst) => sum + (isSchemaIssue(cst) ? 1 : 0), 0),\n count_homonyms: items.reduce(\n (sum, cst) => sum + (hasCstDiagnostic(cst, RSDiagnosticCode.schemaHomonym) ? 1 : 0),\n 0\n ),\n count_formal_duplicates: items.reduce(\n (sum, cst) => sum + (hasCstDiagnostic(cst, RSDiagnosticCode.schemaFormalDuplicate) ? 1 : 0),\n 0\n ),\n count_missing_convention: items.reduce((sum, cst) => sum + (isMissingConvention(cst) ? 1 : 0), 0),\n count_type_mismatch: items.reduce((sum, cst) => sum + (cst.is_type_mismatch ? 1 : 0), 0),\n\n count_incorrect: items.reduce((sum, cst) => sum + (cst.status === CstStatus.INCORRECT ? 1 : 0), 0),\n count_property: items.reduce((sum, cst) => sum + (cst.analysis?.valueClass === ValueClass.PROPERTY ? 1 : 0), 0),\n count_incalculable: items.reduce(\n (sum, cst) => sum + (cst.analysis?.success && cst.analysis.valueClass === null ? 1 : 0),\n 0\n ),\n count_inherited: items.reduce((sum, cst) => sum + (cst.is_inherited ? 1 : 0), 0),\n\n count_text_term: items.reduce((sum, cst) => sum + (cst.term_raw ? 1 : 0), 0),\n count_definition: items.reduce((sum, cst) => sum + (cst.definition_raw ? 1 : 0), 0),\n count_convention: items.reduce((sum, cst) => sum + (isBasicConcept(cst.cst_type) && cst.convention ? 1 : 0), 0),\n count_comment: items.reduce((sum, cst) => sum + (!isBasicConcept(cst.cst_type) && !cst.convention ? 1 : 0), 0),\n\n count_base: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.BASE ? 1 : 0), 0),\n count_constant: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.CONSTANT ? 1 : 0), 0),\n count_structured: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STRUCTURED ? 1 : 0), 0),\n count_axiom: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.AXIOM ? 1 : 0), 0),\n count_term: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.TERM ? 1 : 0), 0),\n count_function: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.FUNCTION ? 1 : 0), 0),\n count_predicate: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.PREDICATE ? 1 : 0), 0),\n count_statement: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.STATEMENT ? 1 : 0), 0),\n count_nominal: items.reduce((sum, cst) => sum + (cst.cst_type === CstType.NOMINAL ? 1 : 0), 0)\n };\n}\n\n/** Finds {@link Constituenta} by structure path. */\nexport function findCstByStructure(schema: RSForm, target: Constituenta, path: TypePath): Constituenta | null {\n for (const cst of schema.items) {\n if (cst.spawner === target.id && cst.spawner_path) {\n if (cst.spawner_path.length === path.length && cst.spawner_path.every((v, i) => v === path[i])) {\n return cst;\n }\n }\n }\n return null;\n}\n\n/** Retrieves name for piece of target {@link Constituenta} structure. */\nexport function getStructureName(schema: RSForm, target: Constituenta, path: TypePath): string {\n const representation = findCstByStructure(schema, target, path);\n if (representation) {\n return `${representation.alias}: ${representation.term_resolved}`;\n }\n if (!isTypification(target.effectiveType)) {\n return '';\n }\n const type = applyPath(target.effectiveType as Typification, path);\n if (type?.typeID === TypeID.basic) {\n const cst = schema.cstByAlias.get(type.baseID);\n if (cst?.term_resolved) {\n return `${cst.alias}: ${cst.term_resolved}`;\n }\n }\n return '';\n}\n\n// ========= Internals =====\nfunction calculateStepComplexity(cst: Constituenta): number {\n if (cst.cst_type === CstType.AXIOM || cst.cst_type === CstType.NOMINAL || !isBasicConcept(cst.cst_type)) {\n return 0;\n }\n if (cst.cst_type === CstType.BASE || cst.cst_type === CstType.CONSTANT || !cst.effectiveType) {\n return 1;\n }\n\n const type = cst.effectiveType as Typification;\n return calculateTypificationComplexity(type) + 1;\n}\n\nfunction calculateTypificationComplexity(type: Typification): number {\n switch (type.typeID) {\n case TypeID.basic:\n case TypeID.integer:\n case TypeID.anyTypification:\n return 0;\n case TypeID.tuple:\n return (\n type.factors.length + type.factors.reduce((sum, factor) => sum + calculateTypificationComplexity(factor), 0)\n );\n case TypeID.collection:\n if (type.base.typeID === TypeID.tuple) {\n let sum = 0;\n type.base.factors.forEach(factor => {\n sum += calculateTypificationComplexity(factor);\n });\n return sum + type.base.factors.length;\n } else if (type.base.typeID === TypeID.collection) {\n return calculateTypificationComplexity(type.base) + 1;\n }\n return 0;\n }\n}\n\nfunction isMissingConvention(cst: Constituenta): boolean {\n if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {\n if (!cst.convention || !cst.term_resolved) {\n return true;\n }\n }\n return false;\n}\n\n/** Evaluate if {@link Typification} can be used to produce structure. */\nfunction typeCanProduceStructure(type: Typification): boolean {\n if (type.typeID === TypeID.basic || type.typeID === TypeID.integer || type.typeID === TypeID.anyTypification) {\n return false;\n } else if (type.typeID === TypeID.tuple) {\n return true;\n } else {\n return (\n type.base.typeID !== TypeID.basic &&\n type.base.typeID !== TypeID.integer &&\n type.base.typeID !== TypeID.anyTypification\n );\n }\n}\n","/**\n * Module: Compact diagnostics for constituents (schema and model issue codes).\n */\n\nimport { labelType } from '../rslang/labels';\n\nimport { type Constituenta, type CstType } from './rsform';\nimport { isBasicConcept, isLogical } from './rsform-api';\nimport { EvalStatus } from './rsmodel';\n\n/** Origin of a diagnostic. */\nexport const DiagnosticKind = {\n EXPRESSION: 'expression',\n SCHEMA: 'schema',\n MODEL: 'model'\n} as const;\nexport type DiagnosticKind = (typeof DiagnosticKind)[keyof typeof DiagnosticKind];\n\n/** Schema and model diagnostic codes (same numeric format as {@link RSErrorCode}). */\nexport const RSDiagnosticCode = {\n schemaHomonym: 0x8901,\n schemaFormalDuplicate: 0x8902,\n schemaMissingConvention: 0x8903,\n schemaMissingTerm: 0x8904,\n schemaTypeMismatch: 0x8905,\n\n modelEmpty: 0x8910,\n modelAxiomFalse: 0x8911,\n modelInvalidData: 0x8912,\n modelEvalFail: 0x8913\n} as const;\nexport type RSDiagnosticCode = (typeof RSDiagnosticCode)[keyof typeof RSDiagnosticCode];\n\n/** Compact diagnostic stored on {@link Constituenta} after schema loading. */\nexport interface CstDiagnostic {\n kind: DiagnosticKind;\n code: number;\n /** Positional message arguments (per-code; homonyms/duplicates use `[aliases]`). */\n params?: readonly string[];\n}\n\n/** Whether a constituent has a schema/model diagnostic with the given code. */\nexport function hasCstDiagnostic(cst: Constituenta, code: RSDiagnosticCode): boolean {\n return cst.diagnostics?.some(item => item.code === code) ?? false;\n}\n\n/**\n * Populate `diagnostics` on each constituent (homonyms, duplicates, metadata, type mismatch).\n *\n * Requires normalized formal definitions for duplicate detection (same as Portal loader).\n */\nexport function assignSchemaDiagnostics(\n items: Constituenta[],\n resolveAlias: (id: number) => string,\n normalizedDefinitions: ReadonlyMap<number, string>\n): void {\n const homonymById = detectHomonymDiagnostics(items, resolveAlias);\n const duplicateById = detectFormalDuplicateDiagnostics(items, resolveAlias, normalizedDefinitions);\n\n for (const cst of items) {\n const diagnostics: CstDiagnostic[] = [];\n const homonym = homonymById.get(cst.id);\n if (homonym) {\n diagnostics.push(homonym);\n }\n const duplicate = duplicateById.get(cst.id);\n if (duplicate) {\n diagnostics.push(duplicate);\n }\n diagnostics.push(...collectLocalSchemaDiagnostics(cst));\n cst.diagnostics = diagnostics;\n }\n}\n\n/** Map a model evaluation status to a compact diagnostic, or `null` when not an issue. */\nexport function modelStatusCstDiagnostic(status: EvalStatus, cstType: CstType): CstDiagnostic | null {\n const code = modelStatusToCode(status, cstType);\n if (code === null) {\n return null;\n }\n return { kind: DiagnosticKind.MODEL, code, params: [String(status)] };\n}\n\nfunction collectLocalSchemaDiagnostics(cst: Constituenta): CstDiagnostic[] {\n const result: CstDiagnostic[] = [];\n if (cst.is_type_mismatch) {\n result.push({\n kind: DiagnosticKind.SCHEMA,\n code: RSDiagnosticCode.schemaTypeMismatch,\n params: [cst.typification_manual, labelType(cst.analysis.type)]\n });\n }\n if (isBasicConcept(cst.cst_type) && !isLogical(cst.cst_type)) {\n if (!cst.convention.trim()) {\n result.push({ kind: DiagnosticKind.SCHEMA, code: RSDiagnosticCode.schemaMissingConvention });\n }\n if (!cst.term_resolved.trim()) {\n result.push({ kind: DiagnosticKind.SCHEMA, code: RSDiagnosticCode.schemaMissingTerm });\n }\n }\n return result;\n}\n\nfunction detectHomonymDiagnostics(\n items: Constituenta[],\n resolveAlias: (id: number) => string\n): Map<number, CstDiagnostic> {\n const byTerm = new Map<string, Constituenta[]>();\n for (const cst of items) {\n const key = cst.term_resolved.trim().toLocaleLowerCase();\n if (key === '') {\n continue;\n }\n const group = byTerm.get(key) ?? [];\n group.push(cst);\n byTerm.set(key, group);\n }\n\n const result = new Map<number, CstDiagnostic>();\n for (const group of byTerm.values()) {\n if (group.length <= 1) {\n continue;\n }\n for (const cst of group) {\n const aliases = group\n .filter(other => other.id !== cst.id)\n .map(other => resolveAlias(other.id))\n .join(', ');\n result.set(cst.id, {\n kind: DiagnosticKind.SCHEMA,\n code: RSDiagnosticCode.schemaHomonym,\n params: [aliases]\n });\n }\n }\n return result;\n}\n\nfunction detectFormalDuplicateDiagnostics(\n items: Constituenta[],\n resolveAlias: (id: number) => string,\n normalizedDefinitions: ReadonlyMap<number, string>\n): Map<number, CstDiagnostic> {\n const byDefinition = new Map<string, Constituenta[]>();\n for (const cst of items) {\n const key = normalizedDefinitions.get(cst.id);\n if (!key) {\n continue;\n }\n const group = byDefinition.get(key) ?? [];\n group.push(cst);\n byDefinition.set(key, group);\n }\n\n const result = new Map<number, CstDiagnostic>();\n for (const group of byDefinition.values()) {\n if (group.length <= 1) {\n continue;\n }\n for (const cst of group) {\n const aliases = group\n .filter(other => other.id !== cst.id)\n .map(other => resolveAlias(other.id))\n .join(', ');\n result.set(cst.id, {\n kind: DiagnosticKind.SCHEMA,\n code: RSDiagnosticCode.schemaFormalDuplicate,\n params: [aliases]\n });\n }\n }\n return result;\n}\n\nfunction modelStatusToCode(status: EvalStatus, cstType: CstType): RSDiagnosticCode | null {\n switch (status) {\n case EvalStatus.EMPTY:\n return isBasicConcept(cstType) ? RSDiagnosticCode.modelEmpty : null;\n case EvalStatus.AXIOM_FALSE:\n return RSDiagnosticCode.modelAxiomFalse;\n case EvalStatus.INVALID_DATA:\n return RSDiagnosticCode.modelInvalidData;\n case EvalStatus.EVAL_FAIL:\n return RSDiagnosticCode.modelEvalFail;\n default:\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsCA,MAAM,kBAA2C;EAC9C,QAAQ,UAAU;EAClB,QAAQ,OAAO;EACf,QAAQ,WAAW;EACnB,QAAQ,aAAa;EACrB,QAAQ,QAAQ;EAChB,QAAQ,OAAO;EACf,QAAQ,WAAW;EACnB,QAAQ,YAAY;EACpB,QAAQ,YAAY;AACvB;;AAGA,MAAM,oBAA+C;EAClD,QAAQ,UAAU,SAAS;EAC3B,QAAQ,OAAO,SAAS;EACxB,QAAQ,WAAW,SAAS;EAC5B,QAAQ,aAAa,SAAS;EAC9B,QAAQ,OAAO,SAAS;EACxB,QAAQ,WAAW,SAAS;EAC5B,QAAQ,QAAQ,SAAS;EACzB,QAAQ,YAAY,SAAS;EAC7B,QAAQ,YAAY,SAAS;AAChC;;AAGA,SAAgB,cAAc,KAA4B;CACxD,QACG,IAAI,aAAa,UAAU,KAAK,KAAK,IAAI,WAAW,UAAU,aAAa,IAAI,WAAW,UAAU;AAEzG;;AAGA,SAAgB,YAAY,OAAgB,OAAsC;CAChF,IAAI,CAAC,OACH,OAAO,UAAU;CAEnB,IAAI,UAAU,MACZ,OAAO,UAAU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