@rsconcept/domain 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/analyzer-DlSq3Y3r.d.ts +39 -0
- package/dist/arguments-extractor-1acwjQNc.d.ts +38 -0
- package/dist/ast-C8sIpKdL.d.ts +51 -0
- package/dist/ast-annotations-BiMjkKvz.d.ts +16 -0
- package/dist/branded-ZlzIcxzu.d.ts +9 -0
- package/dist/calculator-C9W2jkSx.d.ts +39 -0
- package/dist/cctext/index.d.ts +2 -1
- package/dist/cctext/index.js +2 -42
- package/dist/cctext/language-api.d.ts +10 -12
- package/dist/cctext/language-api.js +157 -227
- package/dist/cctext/language-api.js.map +1 -1
- package/dist/cctext/language.d.ts +24 -22
- package/dist/cctext/language.js +43 -39
- package/dist/cctext/language.js.map +1 -1
- package/dist/error-E1LVq_3w.d.ts +87 -0
- package/dist/graph/graph.d.ts +2 -62
- package/dist/graph/graph.js +339 -382
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +2 -1
- package/dist/graph/index.js +2 -384
- package/dist/graph-DR8rL2o3.d.ts +64 -0
- package/dist/hash-Y8I4c6Al.d.ts +8 -0
- package/dist/index-BKZ67WMa.d.ts +1 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-DmtQKWjk.d.ts +1 -0
- package/dist/index-_6s0AX1B.d.ts +1 -0
- package/dist/index.d.ts +27 -28
- package/dist/index.js +23 -5851
- package/dist/lezer-tree-iS7LpLBJ.d.ts +14 -0
- package/dist/library/folder-tree.d.ts +22 -20
- package/dist/library/folder-tree.js +108 -130
- package/dist/library/folder-tree.js.map +1 -1
- package/dist/library/index.d.ts +8 -17
- package/dist/library/index.js +7 -2800
- package/dist/library/library-api.d.ts +3 -1
- package/dist/library/library-api.js +9 -8
- package/dist/library/library-api.js.map +1 -1
- package/dist/library/library.d.ts +2 -56
- package/dist/library/library.js +23 -19
- package/dist/library/library.js.map +1 -1
- package/dist/library/oss-api.d.ts +26 -37
- package/dist/library/oss-api.js +258 -1096
- package/dist/library/oss-api.js.map +1 -1
- package/dist/library/oss-layout-api.d.ts +28 -28
- package/dist/library/oss-layout-api.js +239 -316
- package/dist/library/oss-layout-api.js.map +1 -1
- package/dist/library/oss-layout.d.ts +2 -25
- package/dist/library/oss-layout.js +1 -1
- package/dist/library/oss.d.ts +87 -89
- package/dist/library/oss.js +27 -26
- package/dist/library/oss.js.map +1 -1
- package/dist/library/rsengine.d.ts +100 -106
- package/dist/library/rsengine.js +439 -2599
- package/dist/library/rsengine.js.map +1 -1
- package/dist/library/rsform-api.d.ts +11 -16
- package/dist/library/rsform-api.js +313 -825
- package/dist/library/rsform-api.js.map +1 -1
- package/dist/library/rsform.d.ts +159 -167
- package/dist/library/rsform.js +29 -28
- package/dist/library/rsform.js.map +1 -1
- package/dist/library/rsmodel-api.d.ts +8 -15
- package/dist/library/rsmodel-api.js +172 -813
- package/dist/library/rsmodel-api.js.map +1 -1
- package/dist/library/rsmodel.d.ts +27 -33
- package/dist/library/rsmodel.js +16 -23
- package/dist/library/rsmodel.js.map +1 -1
- package/dist/library/structure-planner.d.ts +20 -26
- package/dist/library/structure-planner.js +106 -474
- package/dist/library/structure-planner.js.map +1 -1
- package/dist/library-CYun28Xz.d.ts +58 -0
- package/dist/oss-layout-3glgAqfn.d.ts +27 -0
- package/dist/parser-Bwd8LxJ1.d.ts +7 -0
- package/dist/parsing/ast.d.ts +2 -49
- package/dist/parsing/ast.js +68 -76
- package/dist/parsing/ast.js.map +1 -1
- package/dist/parsing/index.d.ts +3 -3
- package/dist/parsing/index.js +3 -141
- package/dist/parsing/lezer-tree.d.ts +2 -13
- package/dist/parsing/lezer-tree.js +50 -43
- package/dist/parsing/lezer-tree.js.map +1 -1
- package/dist/rslang/api.d.ts +9 -14
- package/dist/rslang/api.js +114 -827
- package/dist/rslang/api.js.map +1 -1
- package/dist/rslang/ast-annotations.d.ts +2 -18
- package/dist/rslang/ast-annotations.js +34 -45
- package/dist/rslang/ast-annotations.js.map +1 -1
- package/dist/rslang/error.d.ts +2 -85
- package/dist/rslang/error.js +88 -150
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +2 -43
- package/dist/rslang/eval/calculator.js +81 -1636
- package/dist/rslang/eval/calculator.js.map +1 -1
- package/dist/rslang/eval/evaluation-cache.d.ts +22 -26
- package/dist/rslang/eval/evaluation-cache.js +168 -287
- package/dist/rslang/eval/evaluation-cache.js.map +1 -1
- package/dist/rslang/eval/evaluator.d.ts +59 -63
- package/dist/rslang/eval/evaluator.js +602 -1509
- package/dist/rslang/eval/evaluator.js.map +1 -1
- package/dist/rslang/eval/value-api.d.ts +2 -48
- package/dist/rslang/eval/value-api.js +2 -490
- package/dist/rslang/eval/value.d.ts +2 -36
- package/dist/rslang/eval/value.js +2 -118
- package/dist/rslang/index.d.ts +14 -17
- package/dist/rslang/index.js +12 -4314
- package/dist/rslang/labels.d.ts +6 -6
- package/dist/rslang/labels.js +139 -305
- package/dist/rslang/labels.js.map +1 -1
- package/dist/rslang/parser/expression-generator.d.ts +5 -5
- package/dist/rslang/parser/expression-generator.js +248 -446
- package/dist/rslang/parser/expression-generator.js.map +1 -1
- package/dist/rslang/parser/normalize.d.ts +4 -8
- package/dist/rslang/parser/normalize.js +286 -481
- package/dist/rslang/parser/normalize.js.map +1 -1
- package/dist/rslang/parser/parser.d.ts +2 -5
- package/dist/rslang/parser/parser.js +30 -21
- package/dist/rslang/parser/parser.js.map +1 -1
- package/dist/rslang/parser/parser.terms.d.ts +43 -41
- package/dist/rslang/parser/parser.terms.js +44 -83
- package/dist/rslang/parser/parser.terms.js.map +1 -1
- package/dist/rslang/parser/syntax-errors.d.ts +5 -8
- package/dist/rslang/parser/syntax-errors.js +113 -382
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/parser/token.d.ts +2 -79
- package/dist/rslang/parser/token.js +81 -93
- package/dist/rslang/parser/token.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +2 -39
- package/dist/rslang/semantic/analyzer.js +186 -2600
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/arguments-extractor.d.ts +2 -42
- package/dist/rslang/semantic/arguments-extractor.js +202 -361
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +64 -68
- package/dist/rslang/semantic/type-auditor.js +594 -1564
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/typification-api.d.ts +4 -7
- package/dist/rslang/semantic/typification-api.js +162 -303
- package/dist/rslang/semantic/typification-api.js.map +1 -1
- package/dist/rslang/semantic/typification-parser.d.ts +2 -12
- package/dist/rslang/semantic/typification-parser.js +165 -219
- package/dist/rslang/semantic/typification-parser.js.map +1 -1
- package/dist/rslang/semantic/typification.d.ts +2 -119
- package/dist/rslang/semantic/typification.js +66 -52
- package/dist/rslang/semantic/typification.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +32 -38
- package/dist/rslang/semantic/value-auditor.js +206 -518
- package/dist/rslang/semantic/value-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-class.d.ts +2 -10
- package/dist/rslang/semantic/value-class.js +8 -7
- package/dist/rslang/semantic/value-class.js.map +1 -1
- package/dist/rslang/typification-graph.d.ts +2 -33
- package/dist/rslang/typification-graph.js +94 -306
- package/dist/rslang/typification-graph.js.map +1 -1
- package/dist/shared/branded.d.ts +2 -7
- package/dist/shared/branded.js +1 -1
- package/dist/shared/hash.d.ts +2 -6
- package/dist/shared/hash.js +13 -13
- package/dist/shared/hash.js.map +1 -1
- package/dist/shared/index.d.ts +3 -2
- package/dist/shared/index.js +2 -18
- package/dist/token-DeXAmzwr.d.ts +81 -0
- package/dist/typification-Dk-fisgO.d.ts +120 -0
- package/dist/typification-graph-6HcZ-rKH.d.ts +30 -0
- package/dist/typification-parser-BBVx1RxP.d.ts +13 -0
- package/dist/value-B8UtCqaK.js +366 -0
- package/dist/value-B8UtCqaK.js.map +1 -0
- package/dist/value-CTjX6825.d.ts +33 -0
- package/dist/value-api-Bw-SgaYY.d.ts +49 -0
- package/dist/value-class-CNI-lqXJ.d.ts +12 -0
- package/package.json +8 -8
- package/src/library/oss-api.test.ts +76 -0
- package/src/library/oss-api.ts +4 -1
- package/src/library/rsform-api.test.ts +24 -0
- package/src/library/rsform-api.ts +12 -4
- package/dist/cctext/index.js.map +0 -1
- package/dist/graph/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/library/index.js.map +0 -1
- package/dist/library/oss-layout.js.map +0 -1
- package/dist/parsing/index.js.map +0 -1
- package/dist/rslang/eval/value-api.js.map +0 -1
- package/dist/rslang/eval/value.js.map +0 -1
- package/dist/rslang/index.js.map +0 -1
- package/dist/shared/branded.js.map +0 -1
- package/dist/shared/index.js.map +0 -1
|
@@ -1,252 +1,182 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
datv: "datv",
|
|
10
|
-
accs: "accs",
|
|
11
|
-
ablt: "ablt",
|
|
12
|
-
loct: "loct"
|
|
13
|
-
};
|
|
14
|
-
var Case = [
|
|
15
|
-
Grammeme.nomn,
|
|
16
|
-
Grammeme.gent,
|
|
17
|
-
Grammeme.datv,
|
|
18
|
-
Grammeme.accs,
|
|
19
|
-
Grammeme.ablt,
|
|
20
|
-
Grammeme.loct
|
|
21
|
-
];
|
|
22
|
-
var Plurality = [Grammeme.sing, Grammeme.plur];
|
|
23
|
-
var supportedGrammemes = [
|
|
24
|
-
Grammeme.sing,
|
|
25
|
-
Grammeme.plur,
|
|
26
|
-
Grammeme.nomn,
|
|
27
|
-
Grammeme.gent,
|
|
28
|
-
Grammeme.datv,
|
|
29
|
-
Grammeme.accs,
|
|
30
|
-
Grammeme.ablt,
|
|
31
|
-
Grammeme.loct
|
|
32
|
-
];
|
|
33
|
-
var ReferenceType = {
|
|
34
|
-
ENTITY: "entity",
|
|
35
|
-
SYNTACTIC: "syntax"
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/cctext/language-api.ts
|
|
39
|
-
var REFERENCE_PATTERN = /@{[^{}]*?}/g;
|
|
40
|
-
var ENTITY_REFERENCE_PATTERN = /@{([^0-9\-][^}|{]*?)\|([^}|{]*?)}/g;
|
|
1
|
+
import { Case, Grammeme, Plurality, ReferenceType } from "./language.js";
|
|
2
|
+
//#region src/cctext/language-api.ts
|
|
3
|
+
/**
|
|
4
|
+
* Module: Natural language model API.
|
|
5
|
+
*/
|
|
6
|
+
const REFERENCE_PATTERN = /@{[^{}]*?}/g;
|
|
7
|
+
const ENTITY_REFERENCE_PATTERN = /@{([^0-9\-][^}|{]*?)\|([^}|{]*?)}/g;
|
|
8
|
+
/** Equality comparator for {@link WordForm}. Compares a set of Grammemes attached to wordforms. */
|
|
41
9
|
function wordFormEquals(left, right) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (let index = 0; index < left.grams.length; ++index) {
|
|
46
|
-
if (left.grams[index] !== right.grams[index]) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
10
|
+
if (left.grams.length !== right.grams.length) return false;
|
|
11
|
+
for (let index = 0; index < left.grams.length; ++index) if (left.grams[index] !== right.grams[index]) return false;
|
|
12
|
+
return true;
|
|
51
13
|
}
|
|
14
|
+
/** Transforms {@link Grammeme} enumeration to {@link Grammeme}. */
|
|
52
15
|
function parseGrammemes(termForm) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
16
|
+
const result = [];
|
|
17
|
+
for (const chunk of termForm.split(",")) {
|
|
18
|
+
const gram = chunk.trim();
|
|
19
|
+
if (gram !== "") result.push(gram);
|
|
20
|
+
}
|
|
21
|
+
return result.sort(grammemeCompare);
|
|
22
|
+
}
|
|
23
|
+
/** Generates all supported noun forms using nominal text for every form. */
|
|
62
24
|
function generateNominalLexeme(data) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
25
|
+
return { items: Plurality.flatMap((plurality) => Case.map((gramCase) => ({
|
|
26
|
+
text: data.text,
|
|
27
|
+
grams: `${plurality},${gramCase}`
|
|
28
|
+
}))) };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extracts {@link EntityReference} from string representation.
|
|
32
|
+
*
|
|
33
|
+
* @param text - Reference text in a valid pattern. Must fit format '\@\{GLOBAL_ID|GRAMMEMES\}'
|
|
34
|
+
*/
|
|
72
35
|
function parseEntityReference(text) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
36
|
+
const ref = parseReference(text);
|
|
37
|
+
if (ref?.type !== ReferenceType.ENTITY) throw new Error(`Invalid entity reference: ${text}`);
|
|
38
|
+
return ref.data;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extracts {@link SyntacticReference} from string representation.
|
|
42
|
+
*
|
|
43
|
+
* @param text - Reference text in a valid pattern. Must fit format '\@\{OFFSET|NOMINAL_FORM\}'
|
|
44
|
+
*/
|
|
79
45
|
function parseSyntacticReference(text) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
return ref.data;
|
|
46
|
+
const ref = parseReference(text);
|
|
47
|
+
if (ref?.type !== ReferenceType.SYNTACTIC) throw new Error(`Invalid syntactic reference: ${text}`);
|
|
48
|
+
return ref.data;
|
|
85
49
|
}
|
|
50
|
+
/** Extracts a validated reference from string representation. */
|
|
86
51
|
function parseReference(text) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
52
|
+
if (text.length < 4 || !text.startsWith("@{") || !text.endsWith("}")) return null;
|
|
53
|
+
const blocks = text.slice(2, text.length - 1).split("|").map((block) => block.trim());
|
|
54
|
+
if (blocks.length !== 2 || blocks[0] === "" || blocks[0].startsWith("0")) return null;
|
|
55
|
+
if (blocks[0].startsWith("-") || /^[1-9]/.test(blocks[0])) {
|
|
56
|
+
const offset = Number(blocks[0]);
|
|
57
|
+
if (!Number.isInteger(offset) || offset === 0 || blocks[1] === "") return null;
|
|
58
|
+
return {
|
|
59
|
+
type: ReferenceType.SYNTACTIC,
|
|
60
|
+
data: {
|
|
61
|
+
offset,
|
|
62
|
+
nominal: blocks[1]
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
type: ReferenceType.ENTITY,
|
|
68
|
+
data: {
|
|
69
|
+
entity: blocks[0],
|
|
70
|
+
tags: parseGrammemes(blocks[1].replaceAll(" ", ""))
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Extracts unique entity aliases referenced by text. */
|
|
109
75
|
function extractEntities(text) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const segment of text.matchAll(ENTITY_REFERENCE_PATTERN)) {
|
|
78
|
+
const entity = segment[1].trim();
|
|
79
|
+
if (!result.includes(entity)) result.push(entity);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
/** Resolves text references using nominal terms and optional manually edited forms. */
|
|
119
84
|
function resolveTextReferences(text, context) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
output += text.substring(posInput, ref.posInput.from);
|
|
138
|
-
output += ref.resolved;
|
|
139
|
-
posInput = ref.posInput.to;
|
|
140
|
-
}
|
|
141
|
-
output += text.substring(posInput);
|
|
142
|
-
return output;
|
|
143
|
-
}
|
|
85
|
+
const references = parseReferences(text);
|
|
86
|
+
if (references.length === 0) return text;
|
|
87
|
+
for (const ref of references) if (ref.ref.type === ReferenceType.ENTITY) ref.resolved = resolveEntity(ref.ref.data, context);
|
|
88
|
+
references.forEach((ref, index) => {
|
|
89
|
+
if (ref.ref.type === ReferenceType.SYNTACTIC) ref.resolved = resolveSyntactic(ref.ref.data, index, references);
|
|
90
|
+
});
|
|
91
|
+
let posInput = 0;
|
|
92
|
+
let output = "";
|
|
93
|
+
for (const ref of references) {
|
|
94
|
+
output += text.substring(posInput, ref.posInput.from);
|
|
95
|
+
output += ref.resolved;
|
|
96
|
+
posInput = ref.posInput.to;
|
|
97
|
+
}
|
|
98
|
+
output += text.substring(posInput);
|
|
99
|
+
return output;
|
|
100
|
+
}
|
|
101
|
+
/** Transforms {@link IReference} to string representation. */
|
|
144
102
|
function referenceToString(ref) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
103
|
+
switch (ref.type) {
|
|
104
|
+
case ReferenceType.ENTITY: {
|
|
105
|
+
const entity = ref.data;
|
|
106
|
+
return `@{${entity.entity}|${entity.tags.join(",")}}`;
|
|
107
|
+
}
|
|
108
|
+
case ReferenceType.SYNTACTIC: {
|
|
109
|
+
const syntactic = ref.data;
|
|
110
|
+
return `@{${syntactic.offset}|${syntactic.nominal}}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** Compares {@link Grammeme} based on Grammeme enum and alpha order for strings. */
|
|
156
115
|
function grammemeCompare(left, right) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
} else if (indexLeft !== -1 && indexRight === -1) {
|
|
164
|
-
return -1;
|
|
165
|
-
} else {
|
|
166
|
-
return indexLeft - indexRight;
|
|
167
|
-
}
|
|
116
|
+
const indexLeft = Object.values(Grammeme).findIndex((gram) => gram === left);
|
|
117
|
+
const indexRight = Object.values(Grammeme).findIndex((gram) => gram === right);
|
|
118
|
+
if (indexLeft === -1 && indexRight === -1) return left.localeCompare(right);
|
|
119
|
+
else if (indexLeft === -1 && indexRight !== -1) return 1;
|
|
120
|
+
else if (indexLeft !== -1 && indexRight === -1) return -1;
|
|
121
|
+
else return indexLeft - indexRight;
|
|
168
122
|
}
|
|
169
123
|
function parseReferences(text) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
124
|
+
const result = [];
|
|
125
|
+
for (const segment of text.matchAll(REFERENCE_PATTERN)) {
|
|
126
|
+
const ref = parseReference(segment[0]);
|
|
127
|
+
if (ref) result.push({
|
|
128
|
+
ref,
|
|
129
|
+
resolved: "",
|
|
130
|
+
posInput: {
|
|
131
|
+
from: segment.index ?? 0,
|
|
132
|
+
to: (segment.index ?? 0) + segment[0].length
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
182
137
|
}
|
|
183
138
|
function resolveEntity(ref, context) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const resolved = getEntityForm(entity, ref.tags);
|
|
189
|
-
return resolved === "" ? `!\u041E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0435\u0440\u043C\u0438\u043D: ${ref.entity}!` : resolved;
|
|
139
|
+
const entity = context[ref.entity];
|
|
140
|
+
if (!entity) return `!Неизвестная сущность: ${ref.entity}!`;
|
|
141
|
+
const resolved = getEntityForm(entity, ref.tags);
|
|
142
|
+
return resolved === "" ? `!Отсутствует термин: ${ref.entity}!` : resolved;
|
|
190
143
|
}
|
|
191
144
|
function getEntityForm(entity, grams) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
const manual = entity.forms?.find((form) => matchGrams(grams, form.grams));
|
|
196
|
-
return manual?.text ?? entity.nominal;
|
|
145
|
+
if (grams.length === 0) return entity.nominal;
|
|
146
|
+
return (entity.forms?.find((form) => matchGrams(grams, form.grams)))?.text ?? entity.nominal;
|
|
197
147
|
}
|
|
198
148
|
function matchGrams(query, candidate) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return true;
|
|
149
|
+
for (const gram of candidate) if (!query.includes(gram)) return false;
|
|
150
|
+
return true;
|
|
205
151
|
}
|
|
206
152
|
function resolveSyntactic(ref, index, references) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return `!\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u043E\u0435 \u0441\u043C\u0435\u0449\u0435\u043D\u0438\u0435: ${ref.offset}!`;
|
|
210
|
-
}
|
|
211
|
-
return ref.nominal;
|
|
153
|
+
if (!findSyntacticMaster(ref.offset, index, references)) return `!Некорректное смещение: ${ref.offset}!`;
|
|
154
|
+
return ref.nominal;
|
|
212
155
|
}
|
|
213
156
|
function findSyntacticMaster(offset, index, references) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return void 0;
|
|
240
|
-
}
|
|
241
|
-
export {
|
|
242
|
-
extractEntities,
|
|
243
|
-
generateNominalLexeme,
|
|
244
|
-
parseEntityReference,
|
|
245
|
-
parseGrammemes,
|
|
246
|
-
parseReference,
|
|
247
|
-
parseSyntacticReference,
|
|
248
|
-
referenceToString,
|
|
249
|
-
resolveTextReferences,
|
|
250
|
-
wordFormEquals
|
|
251
|
-
};
|
|
157
|
+
if (offset > 0) {
|
|
158
|
+
let position = index + 1;
|
|
159
|
+
let left = offset;
|
|
160
|
+
while (position < references.length) {
|
|
161
|
+
if (references[position].ref.type === ReferenceType.ENTITY) {
|
|
162
|
+
if (left === 1) return references[position];
|
|
163
|
+
left -= 1;
|
|
164
|
+
}
|
|
165
|
+
position += 1;
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
let position = index - 1;
|
|
169
|
+
let left = offset;
|
|
170
|
+
while (position >= 0) {
|
|
171
|
+
if (references[position].ref.type === ReferenceType.ENTITY) {
|
|
172
|
+
if (left === -1) return references[position];
|
|
173
|
+
left += 1;
|
|
174
|
+
}
|
|
175
|
+
position -= 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
export { extractEntities, generateNominalLexeme, parseEntityReference, parseGrammemes, parseReference, parseSyntacticReference, referenceToString, resolveTextReferences, wordFormEquals };
|
|
181
|
+
|
|
252
182
|
//# sourceMappingURL=language-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cctext/language.ts","../../src/cctext/language-api.ts"],"sourcesContent":["/**\n * Module: Natural language model declarations.\n */\n\n/** Represents single unit of language Morphology. */\n// prettier-ignore\nexport const Grammeme = {\n // Число\n sing: 'sing', plur: 'plur',\n\n // Падеж\n nomn: 'nomn', gent: 'gent', datv: 'datv',\n accs: 'accs', ablt: 'ablt', loct: 'loct',\n} as const;\nexport type Grammeme = (typeof Grammeme)[keyof typeof Grammeme];\n\n/** Represents case language concept. */\nexport const Case: Grammeme[] = [\n Grammeme.nomn,\n Grammeme.gent,\n Grammeme.datv,\n Grammeme.accs,\n Grammeme.ablt,\n Grammeme.loct\n] as const;\n\n/** Represents plurality language concept. */\nexport const Plurality: Grammeme[] = [Grammeme.sing, Grammeme.plur] as const;\n\n/** Represents specific wordform attached to {@link Grammeme}s. */\nexport interface WordForm {\n text: string;\n grams: Grammeme[];\n}\n\n/** Represents a term available for text reference resolution. */\nexport interface TermContextItem {\n nominal: string;\n forms?: WordForm[];\n}\n\n/** Represents term lookup context keyed by entity alias. */\nexport type TermContext = Record<string, TermContextItem>;\n\n/**\n * Represents list of {@link Grammeme}s available in reference construction.\n */\n// prettier-ignore\nexport const supportedGrammemes = [\n Grammeme.sing, Grammeme.plur,\n Grammeme.nomn, Grammeme.gent, Grammeme.datv,\n Grammeme.accs, Grammeme.ablt, Grammeme.loct,\n] as const;\n\n// ====== Reference resolution =====\n\n/** Represents text reference type. */\nexport const ReferenceType = {\n ENTITY: 'entity',\n SYNTACTIC: 'syntax'\n} as const;\nexport type ReferenceType = (typeof ReferenceType)[keyof typeof ReferenceType];\n\n/** Represents entity reference payload. */\nexport interface EntityReference {\n entity: string;\n tags: Grammeme[];\n}\n\n/** Represents syntactic reference payload. */\nexport interface SyntacticReference {\n offset: number;\n nominal: string;\n}\n\n/** Represents abstract reference data. */\nexport interface IReference {\n type: ReferenceType;\n data: EntityReference | SyntacticReference;\n}\n","/**\n * Module: Natural language model API.\n */\n\nimport {\n Case,\n type EntityReference,\n Grammeme,\n type IReference,\n Plurality,\n ReferenceType,\n type SyntacticReference,\n type TermContext,\n type TermContextItem,\n type WordForm\n} from './language';\n\ninterface Position {\n from: number;\n to: number;\n}\n\ninterface ResolvedReference {\n ref: IReference;\n resolved: string;\n posInput: Position;\n}\n\nconst REFERENCE_PATTERN = /@{[^{}]*?}/g;\nconst ENTITY_REFERENCE_PATTERN = /@{([^0-9\\-][^}|{]*?)\\|([^}|{]*?)}/g;\n\n/** Represents generated lexeme forms. */\nexport interface Lexeme {\n items: { text: string; grams: string }[];\n}\n\n/** Equality comparator for {@link WordForm}. Compares a set of Grammemes attached to wordforms. */\nexport function wordFormEquals(left: WordForm, right: WordForm): boolean {\n if (left.grams.length !== right.grams.length) {\n return false;\n }\n for (let index = 0; index < left.grams.length; ++index) {\n if (left.grams[index] !== right.grams[index]) {\n return false;\n }\n }\n return true;\n}\n\n/** Transforms {@link Grammeme} enumeration to {@link Grammeme}. */\nexport function parseGrammemes(termForm: string): Grammeme[] {\n const result: Grammeme[] = [];\n for (const chunk of termForm.split(',')) {\n const gram = chunk.trim();\n if (gram !== '') {\n result.push(gram as Grammeme);\n }\n }\n return result.sort(grammemeCompare);\n}\n\n/** Generates all supported noun forms using nominal text for every form. */\nexport function generateNominalLexeme(data: { text: string }): Lexeme {\n return {\n items: Plurality.flatMap(plurality =>\n Case.map(gramCase => ({\n text: data.text,\n grams: `${plurality},${gramCase}`\n }))\n )\n };\n}\n\n/**\n * Extracts {@link EntityReference} from string representation.\n *\n * @param text - Reference text in a valid pattern. Must fit format '\\@\\{GLOBAL_ID|GRAMMEMES\\}'\n */\nexport function parseEntityReference(text: string): EntityReference {\n const ref = parseReference(text);\n if (ref?.type !== ReferenceType.ENTITY) {\n throw new Error(`Invalid entity reference: ${text}`);\n }\n return ref.data as EntityReference;\n}\n\n/**\n * Extracts {@link SyntacticReference} from string representation.\n *\n * @param text - Reference text in a valid pattern. Must fit format '\\@\\{OFFSET|NOMINAL_FORM\\}'\n */\nexport function parseSyntacticReference(text: string): SyntacticReference {\n const ref = parseReference(text);\n if (ref?.type !== ReferenceType.SYNTACTIC) {\n throw new Error(`Invalid syntactic reference: ${text}`);\n }\n return ref.data as SyntacticReference;\n}\n\n/** Extracts a validated reference from string representation. */\nexport function parseReference(text: string): IReference | null {\n if (text.length < 4 || !text.startsWith('@{') || !text.endsWith('}')) {\n return null;\n }\n\n const blocks = text\n .slice(2, text.length - 1)\n .split('|')\n .map(block => block.trim());\n if (blocks.length !== 2 || blocks[0] === '' || blocks[0].startsWith('0')) {\n return null;\n }\n\n if (blocks[0].startsWith('-') || /^[1-9]/.test(blocks[0])) {\n const offset = Number(blocks[0]);\n if (!Number.isInteger(offset) || offset === 0 || blocks[1] === '') {\n return null;\n }\n return {\n type: ReferenceType.SYNTACTIC,\n data: { offset, nominal: blocks[1] }\n };\n }\n\n return {\n type: ReferenceType.ENTITY,\n data: { entity: blocks[0], tags: parseGrammemes(blocks[1].replaceAll(' ', '')) }\n };\n}\n\n/** Extracts unique entity aliases referenced by text. */\nexport function extractEntities(text: string): string[] {\n const result: string[] = [];\n for (const segment of text.matchAll(ENTITY_REFERENCE_PATTERN)) {\n const entity = segment[1].trim();\n if (!result.includes(entity)) {\n result.push(entity);\n }\n }\n return result;\n}\n\n/** Resolves text references using nominal terms and optional manually edited forms. */\nexport function resolveTextReferences(text: string, context: TermContext): string {\n const references = parseReferences(text);\n if (references.length === 0) {\n return text;\n }\n\n for (const ref of references) {\n if (ref.ref.type === ReferenceType.ENTITY) {\n ref.resolved = resolveEntity(ref.ref.data as EntityReference, context);\n }\n }\n references.forEach((ref, index) => {\n if (ref.ref.type === ReferenceType.SYNTACTIC) {\n ref.resolved = resolveSyntactic(ref.ref.data as SyntacticReference, index, references);\n }\n });\n\n let posInput = 0;\n let output = '';\n for (const ref of references) {\n output += text.substring(posInput, ref.posInput.from);\n output += ref.resolved;\n posInput = ref.posInput.to;\n }\n output += text.substring(posInput);\n return output;\n}\n\n/** Transforms {@link IReference} to string representation. */\nexport function referenceToString(ref: IReference): string {\n switch (ref.type) {\n case ReferenceType.ENTITY: {\n const entity = ref.data as EntityReference;\n return `@{${entity.entity}|${entity.tags.join(',')}}`;\n }\n case ReferenceType.SYNTACTIC: {\n const syntactic = ref.data as SyntacticReference;\n return `@{${syntactic.offset}|${syntactic.nominal}}`;\n }\n }\n}\n\n// ===== Internals =======\n\n/** Compares {@link Grammeme} based on Grammeme enum and alpha order for strings. */\nfunction grammemeCompare(left: Grammeme, right: Grammeme): number {\n const indexLeft = Object.values(Grammeme).findIndex(gram => gram === left);\n const indexRight = Object.values(Grammeme).findIndex(gram => gram === right);\n if (indexLeft === -1 && indexRight === -1) {\n return left.localeCompare(right);\n } else if (indexLeft === -1 && indexRight !== -1) {\n return 1;\n } else if (indexLeft !== -1 && indexRight === -1) {\n return -1;\n } else {\n return indexLeft - indexRight;\n }\n}\n\nfunction parseReferences(text: string): ResolvedReference[] {\n const result: ResolvedReference[] = [];\n for (const segment of text.matchAll(REFERENCE_PATTERN)) {\n const ref = parseReference(segment[0]);\n if (ref) {\n result.push({\n ref,\n resolved: '',\n posInput: { from: segment.index ?? 0, to: (segment.index ?? 0) + segment[0].length }\n });\n }\n }\n return result;\n}\n\nfunction resolveEntity(ref: EntityReference, context: TermContext): string {\n const entity = context[ref.entity];\n if (!entity) {\n return `!Неизвестная сущность: ${ref.entity}!`;\n }\n\n const resolved = getEntityForm(entity, ref.tags);\n return resolved === '' ? `!Отсутствует термин: ${ref.entity}!` : resolved;\n}\n\nfunction getEntityForm(entity: TermContextItem, grams: Grammeme[]): string {\n if (grams.length === 0) {\n return entity.nominal;\n }\n\n const manual = entity.forms?.find(form => matchGrams(grams, form.grams));\n return manual?.text ?? entity.nominal;\n}\n\nfunction matchGrams(query: Grammeme[], candidate: Grammeme[]): boolean {\n for (const gram of candidate) {\n if (!query.includes(gram)) {\n return false;\n }\n }\n return true;\n}\n\nfunction resolveSyntactic(ref: SyntacticReference, index: number, references: ResolvedReference[]): string {\n const master = findSyntacticMaster(ref.offset, index, references);\n if (!master) {\n return `!Некорректное смещение: ${ref.offset}!`;\n }\n return ref.nominal;\n}\n\nfunction findSyntacticMaster(\n offset: number,\n index: number,\n references: ResolvedReference[]\n): ResolvedReference | undefined {\n if (offset > 0) {\n let position = index + 1;\n let left = offset;\n while (position < references.length) {\n if (references[position].ref.type === ReferenceType.ENTITY) {\n if (left === 1) {\n return references[position];\n }\n left -= 1;\n }\n position += 1;\n }\n } else {\n let position = index - 1;\n let left = offset;\n while (position >= 0) {\n if (references[position].ref.type === ReferenceType.ENTITY) {\n if (left === -1) {\n return references[position];\n }\n left += 1;\n }\n position -= 1;\n }\n }\n return undefined;\n}\n"],"mappings":";AAMO,IAAM,WAAW;AAAA;AAAA,EAEtB,MAAM;AAAA,EAAQ,MAAM;AAAA;AAAA,EAGpB,MAAM;AAAA,EAAQ,MAAM;AAAA,EAAQ,MAAM;AAAA,EAClC,MAAM;AAAA,EAAQ,MAAM;AAAA,EAAQ,MAAM;AACpC;AAIO,IAAM,OAAmB;AAAA,EAC9B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AACX;AAGO,IAAM,YAAwB,CAAC,SAAS,MAAM,SAAS,IAAI;AAqB3D,IAAM,qBAAqB;AAAA,EAChC,SAAS;AAAA,EAAM,SAAS;AAAA,EACxB,SAAS;AAAA,EAAM,SAAS;AAAA,EAAM,SAAS;AAAA,EACvC,SAAS;AAAA,EAAM,SAAS;AAAA,EAAM,SAAS;AACzC;AAKO,IAAM,gBAAgB;AAAA,EAC3B,QAAQ;AAAA,EACR,WAAW;AACb;;;AChCA,IAAM,oBAAoB;AAC1B,IAAM,2BAA2B;AAQ1B,SAAS,eAAe,MAAgB,OAA0B;AACvE,MAAI,KAAK,MAAM,WAAW,MAAM,MAAM,QAAQ;AAC5C,WAAO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OAAO;AACX,WAAO,YAAY,GAAG;AACpB,UAAI,WAAW,QAAQ,EAAE,IAAI,SAAS,cAAc,QAAQ;AAC1D,YAAI,SAAS,IAAI;AACf,iBAAO,WAAW,QAAQ;AAAA,QAC5B;AACA,gBAAQ;AAAA,MACV;AACA,kBAAY;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"file":"language-api.js","names":[],"sources":["../../src/cctext/language-api.ts"],"sourcesContent":["/**\n * Module: Natural language model API.\n */\n\nimport {\n Case,\n type EntityReference,\n Grammeme,\n type IReference,\n Plurality,\n ReferenceType,\n type SyntacticReference,\n type TermContext,\n type TermContextItem,\n type WordForm\n} from './language';\n\ninterface Position {\n from: number;\n to: number;\n}\n\ninterface ResolvedReference {\n ref: IReference;\n resolved: string;\n posInput: Position;\n}\n\nconst REFERENCE_PATTERN = /@{[^{}]*?}/g;\nconst ENTITY_REFERENCE_PATTERN = /@{([^0-9\\-][^}|{]*?)\\|([^}|{]*?)}/g;\n\n/** Represents generated lexeme forms. */\nexport interface Lexeme {\n items: { text: string; grams: string }[];\n}\n\n/** Equality comparator for {@link WordForm}. Compares a set of Grammemes attached to wordforms. */\nexport function wordFormEquals(left: WordForm, right: WordForm): boolean {\n if (left.grams.length !== right.grams.length) {\n return false;\n }\n for (let index = 0; index < left.grams.length; ++index) {\n if (left.grams[index] !== right.grams[index]) {\n return false;\n }\n }\n return true;\n}\n\n/** Transforms {@link Grammeme} enumeration to {@link Grammeme}. */\nexport function parseGrammemes(termForm: string): Grammeme[] {\n const result: Grammeme[] = [];\n for (const chunk of termForm.split(',')) {\n const gram = chunk.trim();\n if (gram !== '') {\n result.push(gram as Grammeme);\n }\n }\n return result.sort(grammemeCompare);\n}\n\n/** Generates all supported noun forms using nominal text for every form. */\nexport function generateNominalLexeme(data: { text: string }): Lexeme {\n return {\n items: Plurality.flatMap(plurality =>\n Case.map(gramCase => ({\n text: data.text,\n grams: `${plurality},${gramCase}`\n }))\n )\n };\n}\n\n/**\n * Extracts {@link EntityReference} from string representation.\n *\n * @param text - Reference text in a valid pattern. Must fit format '\\@\\{GLOBAL_ID|GRAMMEMES\\}'\n */\nexport function parseEntityReference(text: string): EntityReference {\n const ref = parseReference(text);\n if (ref?.type !== ReferenceType.ENTITY) {\n throw new Error(`Invalid entity reference: ${text}`);\n }\n return ref.data as EntityReference;\n}\n\n/**\n * Extracts {@link SyntacticReference} from string representation.\n *\n * @param text - Reference text in a valid pattern. Must fit format '\\@\\{OFFSET|NOMINAL_FORM\\}'\n */\nexport function parseSyntacticReference(text: string): SyntacticReference {\n const ref = parseReference(text);\n if (ref?.type !== ReferenceType.SYNTACTIC) {\n throw new Error(`Invalid syntactic reference: ${text}`);\n }\n return ref.data as SyntacticReference;\n}\n\n/** Extracts a validated reference from string representation. */\nexport function parseReference(text: string): IReference | null {\n if (text.length < 4 || !text.startsWith('@{') || !text.endsWith('}')) {\n return null;\n }\n\n const blocks = text\n .slice(2, text.length - 1)\n .split('|')\n .map(block => block.trim());\n if (blocks.length !== 2 || blocks[0] === '' || blocks[0].startsWith('0')) {\n return null;\n }\n\n if (blocks[0].startsWith('-') || /^[1-9]/.test(blocks[0])) {\n const offset = Number(blocks[0]);\n if (!Number.isInteger(offset) || offset === 0 || blocks[1] === '') {\n return null;\n }\n return {\n type: ReferenceType.SYNTACTIC,\n data: { offset, nominal: blocks[1] }\n };\n }\n\n return {\n type: ReferenceType.ENTITY,\n data: { entity: blocks[0], tags: parseGrammemes(blocks[1].replaceAll(' ', '')) }\n };\n}\n\n/** Extracts unique entity aliases referenced by text. */\nexport function extractEntities(text: string): string[] {\n const result: string[] = [];\n for (const segment of text.matchAll(ENTITY_REFERENCE_PATTERN)) {\n const entity = segment[1].trim();\n if (!result.includes(entity)) {\n result.push(entity);\n }\n }\n return result;\n}\n\n/** Resolves text references using nominal terms and optional manually edited forms. */\nexport function resolveTextReferences(text: string, context: TermContext): string {\n const references = parseReferences(text);\n if (references.length === 0) {\n return text;\n }\n\n for (const ref of references) {\n if (ref.ref.type === ReferenceType.ENTITY) {\n ref.resolved = resolveEntity(ref.ref.data as EntityReference, context);\n }\n }\n references.forEach((ref, index) => {\n if (ref.ref.type === ReferenceType.SYNTACTIC) {\n ref.resolved = resolveSyntactic(ref.ref.data as SyntacticReference, index, references);\n }\n });\n\n let posInput = 0;\n let output = '';\n for (const ref of references) {\n output += text.substring(posInput, ref.posInput.from);\n output += ref.resolved;\n posInput = ref.posInput.to;\n }\n output += text.substring(posInput);\n return output;\n}\n\n/** Transforms {@link IReference} to string representation. */\nexport function referenceToString(ref: IReference): string {\n switch (ref.type) {\n case ReferenceType.ENTITY: {\n const entity = ref.data as EntityReference;\n return `@{${entity.entity}|${entity.tags.join(',')}}`;\n }\n case ReferenceType.SYNTACTIC: {\n const syntactic = ref.data as SyntacticReference;\n return `@{${syntactic.offset}|${syntactic.nominal}}`;\n }\n }\n}\n\n// ===== Internals =======\n\n/** Compares {@link Grammeme} based on Grammeme enum and alpha order for strings. */\nfunction grammemeCompare(left: Grammeme, right: Grammeme): number {\n const indexLeft = Object.values(Grammeme).findIndex(gram => gram === left);\n const indexRight = Object.values(Grammeme).findIndex(gram => gram === right);\n if (indexLeft === -1 && indexRight === -1) {\n return left.localeCompare(right);\n } else if (indexLeft === -1 && indexRight !== -1) {\n return 1;\n } else if (indexLeft !== -1 && indexRight === -1) {\n return -1;\n } else {\n return indexLeft - indexRight;\n }\n}\n\nfunction parseReferences(text: string): ResolvedReference[] {\n const result: ResolvedReference[] = [];\n for (const segment of text.matchAll(REFERENCE_PATTERN)) {\n const ref = parseReference(segment[0]);\n if (ref) {\n result.push({\n ref,\n resolved: '',\n posInput: { from: segment.index ?? 0, to: (segment.index ?? 0) + segment[0].length }\n });\n }\n }\n return result;\n}\n\nfunction resolveEntity(ref: EntityReference, context: TermContext): string {\n const entity = context[ref.entity];\n if (!entity) {\n return `!Неизвестная сущность: ${ref.entity}!`;\n }\n\n const resolved = getEntityForm(entity, ref.tags);\n return resolved === '' ? `!Отсутствует термин: ${ref.entity}!` : resolved;\n}\n\nfunction getEntityForm(entity: TermContextItem, grams: Grammeme[]): string {\n if (grams.length === 0) {\n return entity.nominal;\n }\n\n const manual = entity.forms?.find(form => matchGrams(grams, form.grams));\n return manual?.text ?? entity.nominal;\n}\n\nfunction matchGrams(query: Grammeme[], candidate: Grammeme[]): boolean {\n for (const gram of candidate) {\n if (!query.includes(gram)) {\n return false;\n }\n }\n return true;\n}\n\nfunction resolveSyntactic(ref: SyntacticReference, index: number, references: ResolvedReference[]): string {\n const master = findSyntacticMaster(ref.offset, index, references);\n if (!master) {\n return `!Некорректное смещение: ${ref.offset}!`;\n }\n return ref.nominal;\n}\n\nfunction findSyntacticMaster(\n offset: number,\n index: number,\n references: ResolvedReference[]\n): ResolvedReference | undefined {\n if (offset > 0) {\n let position = index + 1;\n let left = offset;\n while (position < references.length) {\n if (references[position].ref.type === ReferenceType.ENTITY) {\n if (left === 1) {\n return references[position];\n }\n left -= 1;\n }\n position += 1;\n }\n } else {\n let position = index - 1;\n let left = offset;\n while (position >= 0) {\n if (references[position].ref.type === ReferenceType.ENTITY) {\n if (left === -1) {\n return references[position];\n }\n left += 1;\n }\n position -= 1;\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;AA4BA,MAAM,oBAAoB;AAC1B,MAAM,2BAA2B;;AAQjC,SAAgB,eAAe,MAAgB,OAA0B;CACvE,IAAI,KAAK,MAAM,WAAW,MAAM,MAAM,QACpC,OAAO;CAET,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,MAAM,QAAQ,EAAE,OAC/C,IAAI,KAAK,MAAM,WAAW,MAAM,MAAM,QACpC,OAAO;CAGX,OAAO;AACT;;AAGA,SAAgB,eAAe,UAA8B;CAC3D,MAAM,SAAqB,CAAC;CAC5B,KAAK,MAAM,SAAS,SAAS,MAAM,GAAG,GAAG;EACvC,MAAM,OAAO,MAAM,KAAK;EACxB,IAAI,SAAS,IACX,OAAO,KAAK,IAA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AAEA,SAAS,oBACP,QACA,OACA,YAC+B;CAC/B,IAAI,SAAS,GAAG;EACd,IAAI,WAAW,QAAQ;EACvB,IAAI,OAAO;EACX,OAAO,WAAW,WAAW,QAAQ;GACnC,IAAI,WAAW,SAAS,CAAC,IAAI,SAAS,cAAc,QAAQ;IAC1D,IAAI,SAAS,GACX,OAAO,WAAW;IAEpB,QAAQ;GACV;GACA,YAAY;EACd;CACF,OAAO;EACL,IAAI,WAAW,QAAQ;EACvB,IAAI,OAAO;EACX,OAAO,YAAY,GAAG;GACpB,IAAI,WAAW,SAAS,CAAC,IAAI,SAAS,cAAc,QAAQ;IAC1D,IAAI,SAAS,IACX,OAAO,WAAW;IAEpB,QAAQ;GACV;GACA,YAAY;EACd;CACF;AAEF"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
//#region src/cctext/language.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Module: Natural language model declarations.
|
|
3
4
|
*/
|
|
4
5
|
/** Represents single unit of language Morphology. */
|
|
5
6
|
declare const Grammeme: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
readonly sing: "sing";
|
|
8
|
+
readonly plur: "plur";
|
|
9
|
+
readonly nomn: "nomn";
|
|
10
|
+
readonly gent: "gent";
|
|
11
|
+
readonly datv: "datv";
|
|
12
|
+
readonly accs: "accs";
|
|
13
|
+
readonly ablt: "ablt";
|
|
14
|
+
readonly loct: "loct";
|
|
14
15
|
};
|
|
15
16
|
type Grammeme = (typeof Grammeme)[keyof typeof Grammeme];
|
|
16
17
|
/** Represents case language concept. */
|
|
@@ -19,13 +20,13 @@ declare const Case: Grammeme[];
|
|
|
19
20
|
declare const Plurality: Grammeme[];
|
|
20
21
|
/** Represents specific wordform attached to {@link Grammeme}s. */
|
|
21
22
|
interface WordForm {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
text: string;
|
|
24
|
+
grams: Grammeme[];
|
|
24
25
|
}
|
|
25
26
|
/** Represents a term available for text reference resolution. */
|
|
26
27
|
interface TermContextItem {
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
nominal: string;
|
|
29
|
+
forms?: WordForm[];
|
|
29
30
|
}
|
|
30
31
|
/** Represents term lookup context keyed by entity alias. */
|
|
31
32
|
type TermContext = Record<string, TermContextItem>;
|
|
@@ -35,24 +36,25 @@ type TermContext = Record<string, TermContextItem>;
|
|
|
35
36
|
declare const supportedGrammemes: readonly ["sing", "plur", "nomn", "gent", "datv", "accs", "ablt", "loct"];
|
|
36
37
|
/** Represents text reference type. */
|
|
37
38
|
declare const ReferenceType: {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
readonly ENTITY: "entity";
|
|
40
|
+
readonly SYNTACTIC: "syntax";
|
|
40
41
|
};
|
|
41
42
|
type ReferenceType = (typeof ReferenceType)[keyof typeof ReferenceType];
|
|
42
43
|
/** Represents entity reference payload. */
|
|
43
44
|
interface EntityReference {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
entity: string;
|
|
46
|
+
tags: Grammeme[];
|
|
46
47
|
}
|
|
47
48
|
/** Represents syntactic reference payload. */
|
|
48
49
|
interface SyntacticReference {
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
offset: number;
|
|
51
|
+
nominal: string;
|
|
51
52
|
}
|
|
52
53
|
/** Represents abstract reference data. */
|
|
53
54
|
interface IReference {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
type: ReferenceType;
|
|
56
|
+
data: EntityReference | SyntacticReference;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
export { Case,
|
|
58
|
+
//#endregion
|
|
59
|
+
export { Case, EntityReference, Grammeme, IReference, Plurality, ReferenceType, SyntacticReference, TermContext, TermContextItem, WordForm, supportedGrammemes };
|
|
60
|
+
//# sourceMappingURL=language.d.ts.map
|
package/dist/cctext/language.js
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//#region src/cctext/language.ts
|
|
2
|
+
/**
|
|
3
|
+
* Module: Natural language model declarations.
|
|
4
|
+
*/
|
|
5
|
+
/** Represents single unit of language Morphology. */
|
|
6
|
+
const Grammeme = {
|
|
7
|
+
sing: "sing",
|
|
8
|
+
plur: "plur",
|
|
9
|
+
nomn: "nomn",
|
|
10
|
+
gent: "gent",
|
|
11
|
+
datv: "datv",
|
|
12
|
+
accs: "accs",
|
|
13
|
+
ablt: "ablt",
|
|
14
|
+
loct: "loct"
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
/** Represents case language concept. */
|
|
17
|
+
const Case = [
|
|
18
|
+
Grammeme.nomn,
|
|
19
|
+
Grammeme.gent,
|
|
20
|
+
Grammeme.datv,
|
|
21
|
+
Grammeme.accs,
|
|
22
|
+
Grammeme.ablt,
|
|
23
|
+
Grammeme.loct
|
|
21
24
|
];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
/** Represents plurality language concept. */
|
|
26
|
+
const Plurality = [Grammeme.sing, Grammeme.plur];
|
|
27
|
+
/**
|
|
28
|
+
* Represents list of {@link Grammeme}s available in reference construction.
|
|
29
|
+
*/
|
|
30
|
+
const supportedGrammemes = [
|
|
31
|
+
Grammeme.sing,
|
|
32
|
+
Grammeme.plur,
|
|
33
|
+
Grammeme.nomn,
|
|
34
|
+
Grammeme.gent,
|
|
35
|
+
Grammeme.datv,
|
|
36
|
+
Grammeme.accs,
|
|
37
|
+
Grammeme.ablt,
|
|
38
|
+
Grammeme.loct
|
|
32
39
|
];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
Case,
|
|
39
|
-
Grammeme,
|
|
40
|
-
Plurality,
|
|
41
|
-
ReferenceType,
|
|
42
|
-
supportedGrammemes
|
|
40
|
+
/** Represents text reference type. */
|
|
41
|
+
const ReferenceType = {
|
|
42
|
+
ENTITY: "entity",
|
|
43
|
+
SYNTACTIC: "syntax"
|
|
43
44
|
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { Case, Grammeme, Plurality, ReferenceType, supportedGrammemes };
|
|
47
|
+
|
|
44
48
|
//# sourceMappingURL=language.js.map
|