@lokascript/framework 4.8.0 → 5.1.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/CHANGELOG.md +70 -1
- package/dist/api/create-dsl.d.ts +9 -10
- package/dist/api/create-dsl.d.ts.map +1 -1
- package/dist/api/index.js +835 -1670
- package/dist/api/index.js.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +549 -1132
- package/dist/core/index.js.map +1 -1
- package/dist/core/matching/index.d.ts +2 -0
- package/dist/core/matching/index.d.ts.map +1 -1
- package/dist/core/matching/possessive-keywords.d.ts.map +1 -0
- package/dist/core/matching/stock-confidence.d.ts +3 -4
- package/dist/core/matching/stock-confidence.d.ts.map +1 -1
- package/dist/core/matching/stock-reading.d.ts +4 -4
- package/dist/core/{pattern-matching/utils → matching}/type-validation.d.ts +1 -1
- package/dist/core/matching/type-validation.d.ts.map +1 -0
- package/dist/generation/index.d.ts +1 -1
- package/dist/generation/index.d.ts.map +1 -1
- package/dist/generation/index.js +20 -169
- package/dist/generation/index.js.map +1 -1
- package/dist/generation/profile.d.ts +30 -0
- package/dist/generation/profile.d.ts.map +1 -0
- package/dist/generation/renderer.d.ts +1 -1
- package/dist/generation/renderer.d.ts.map +1 -1
- package/dist/generation/schema-patterns.d.ts +3 -3
- package/dist/index.cjs +929 -1674
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +929 -1668
- package/dist/index.js.map +1 -1
- package/dist/multilingual/builders.d.ts +3 -3
- package/dist/multilingual/builders.d.ts.map +1 -1
- package/dist/multilingual/index.js.map +1 -1
- package/dist/parsing/index.d.ts +0 -1
- package/dist/parsing/index.d.ts.map +1 -1
- package/dist/parsing/index.js +0 -1145
- package/dist/parsing/index.js.map +1 -1
- package/dist/testing/gate/lint/types.d.ts +1 -1
- package/dist/testing/gate/lint/types.d.ts.map +1 -1
- package/package.json +3 -8
- package/src/__test__/test-utils.ts +1 -1
- package/src/api/create-dsl-engine.test.ts +60 -35
- package/src/api/create-dsl.ts +24 -35
- package/src/core/index.ts +0 -1
- package/src/core/matching/index.ts +2 -0
- package/src/core/matching/stock-confidence.ts +3 -4
- package/src/core/matching/stock-reading.ts +6 -6
- package/src/core/{pattern-matching/utils → matching}/type-validation.test.ts +2 -2
- package/src/core/{pattern-matching/utils → matching}/type-validation.ts +1 -1
- package/src/generation/domain-renderer.test.ts +1 -1
- package/src/generation/index.ts +1 -1
- package/src/generation/profile.ts +41 -0
- package/src/generation/renderer.test.ts +1 -1
- package/src/generation/renderer.ts +1 -1
- package/src/generation/schema-patterns.ts +3 -3
- package/src/multilingual/bridge.test.ts +31 -23
- package/src/multilingual/builders.ts +3 -3
- package/src/parsing/index.ts +0 -1
- package/src/testing/gate/lint/types.ts +1 -1
- package/dist/core/pattern-matching/index.d.ts +0 -6
- package/dist/core/pattern-matching/index.d.ts.map +0 -1
- package/dist/core/pattern-matching/index.js +0 -1211
- package/dist/core/pattern-matching/index.js.map +0 -1
- package/dist/core/pattern-matching/pattern-matcher.d.ts +0 -122
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +0 -1
- package/dist/core/pattern-matching/utils/index.d.ts +0 -6
- package/dist/core/pattern-matching/utils/index.d.ts.map +0 -1
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts.map +0 -1
- package/dist/core/pattern-matching/utils/type-validation.d.ts.map +0 -1
- package/dist/generation/pattern-generator.d.ts +0 -55
- package/dist/generation/pattern-generator.d.ts.map +0 -1
- package/src/core/pattern-matching/index.ts +0 -6
- package/src/core/pattern-matching/pattern-matcher.test.ts +0 -1031
- package/src/core/pattern-matching/pattern-matcher.ts +0 -765
- package/src/core/pattern-matching/utils/index.ts +0 -6
- package/src/generation/pattern-generator.test.ts +0 -532
- package/src/generation/pattern-generator.ts +0 -327
- /package/dist/core/{pattern-matching/utils → matching}/possessive-keywords.d.ts +0 -0
- /package/src/core/{pattern-matching/utils → matching}/possessive-keywords.ts +0 -0
|
@@ -9,4 +9,6 @@ export type { ConfidenceBreakdown, ConfidenceContext, ConfidenceModel } from './
|
|
|
9
9
|
export { StockValueReader, createStockReader, greedyStopMarkers, readGreedy } from './stock-reader';
|
|
10
10
|
export { readRoleValue, type ReadingProfile } from './stock-reading';
|
|
11
11
|
export { stockConfidenceModel } from './stock-confidence';
|
|
12
|
+
export * from './type-validation';
|
|
13
|
+
export * from './possessive-keywords';
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/matching/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/matching/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"possessive-keywords.d.ts","sourceRoot":"","sources":["../../../src/core/matching/possessive-keywords.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC5C,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,OAAO,EAAE,MAAM,GACd,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExB"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The stock confidence model: how framework's
|
|
3
|
-
* pattern's match
|
|
4
|
-
*
|
|
5
|
-
* it too until Phase 6.
|
|
2
|
+
* The stock confidence model: how framework's first matcher scored a domain
|
|
3
|
+
* pattern's match, moved here as a `ConfidenceModel` for the matcher's
|
|
4
|
+
* skeleton (domains rethink Phase 4.7).
|
|
6
5
|
*
|
|
7
6
|
* Role coverage (a required slot 1, an optional one 0.8, an absent optional one
|
|
8
7
|
* with a default 60% of that), a stem-match penalty (up to 15%, floor 0.5), and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stock-confidence.d.ts","sourceRoot":"","sources":["../../../src/core/matching/stock-confidence.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stock-confidence.d.ts","sourceRoot":"","sources":["../../../src/core/matching/stock-confidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAA0C,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA4NlG,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reading a domain value at a role slot: the value reading framework's
|
|
3
|
-
* matcher
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Reading a domain value at a role slot: the value reading framework's first
|
|
3
|
+
* matcher did, moved here for the stock reader on the matcher's skeleton
|
|
4
|
+
* (`stock-reader.ts`, domains rethink Phase 4.7). The first matcher was
|
|
5
|
+
* deleted in 5.0 (Phase 6).
|
|
6
6
|
*
|
|
7
7
|
* In order: an English noise word before a selector (`the`), then the
|
|
8
8
|
* multi-token forms (a possessive, `my value`; a method call,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Shared utilities for validating semantic value types against expected types.
|
|
5
5
|
* Used by pattern-matcher to validate captured role values.
|
|
6
6
|
*/
|
|
7
|
-
import type { SemanticValue } from '
|
|
7
|
+
import type { SemanticValue } from '../types';
|
|
8
8
|
/**
|
|
9
9
|
* Semantic value type strings.
|
|
10
10
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-validation.d.ts","sourceRoot":"","sources":["../../../src/core/matching/type-validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;AAEtD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,iBAAiB,GAAG,MAAM,EACtC,aAAa,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,GAC5C,OAAO,CAsBT;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,aAAa,EACpB,aAAa,CAAC,EAAE,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,GAC7C,OAAO,CAMT;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAUrD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGrD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generation/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generation/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
package/dist/generation/index.js
CHANGED
|
@@ -1,110 +1,4 @@
|
|
|
1
|
-
// src/generation/
|
|
2
|
-
var defaultConfig = {
|
|
3
|
-
basePriority: 100,
|
|
4
|
-
includeOptionalVariants: true
|
|
5
|
-
};
|
|
6
|
-
function generatePattern(schema, profile, config = defaultConfig) {
|
|
7
|
-
const id = `${schema.action}-${profile.code}-generated`;
|
|
8
|
-
const priority = config.basePriority ?? 100;
|
|
9
|
-
const keyword = profile.keywords[schema.action];
|
|
10
|
-
if (!keyword) {
|
|
11
|
-
throw new Error(`No keyword translation for '${schema.action}' in ${profile.code}`);
|
|
12
|
-
}
|
|
13
|
-
const tokens = buildTokens(schema, profile, keyword.primary, keyword.alternatives);
|
|
14
|
-
const extraction = buildExtractionRules(schema, profile);
|
|
15
|
-
const format = buildFormatString(schema, profile, keyword.primary);
|
|
16
|
-
return {
|
|
17
|
-
id,
|
|
18
|
-
language: profile.code,
|
|
19
|
-
command: schema.action,
|
|
20
|
-
priority,
|
|
21
|
-
template: {
|
|
22
|
-
format,
|
|
23
|
-
tokens
|
|
24
|
-
},
|
|
25
|
-
extraction
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function buildTokens(schema, profile, keyword, alternatives) {
|
|
29
|
-
const tokens = [];
|
|
30
|
-
const keywordToken = {
|
|
31
|
-
type: "literal",
|
|
32
|
-
value: keyword,
|
|
33
|
-
...alternatives?.length && { alternatives }
|
|
34
|
-
};
|
|
35
|
-
const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);
|
|
36
|
-
if (profile.wordOrder === "SVO") {
|
|
37
|
-
tokens.push(keywordToken);
|
|
38
|
-
for (const role of sortedRoles) {
|
|
39
|
-
addRoleWithMarker(tokens, role, profile);
|
|
40
|
-
}
|
|
41
|
-
} else if (profile.wordOrder === "SOV") {
|
|
42
|
-
const preVerb = [];
|
|
43
|
-
const postVerb = [];
|
|
44
|
-
for (const role of sortedRoles) {
|
|
45
|
-
addRoleWithMarker(role.sovSlot === "postVerb" ? postVerb : preVerb, role, profile);
|
|
46
|
-
}
|
|
47
|
-
tokens.push(...preVerb, keywordToken, ...postVerb);
|
|
48
|
-
} else if (profile.wordOrder === "VSO") {
|
|
49
|
-
tokens.push(keywordToken);
|
|
50
|
-
for (const role of sortedRoles) {
|
|
51
|
-
addRoleWithMarker(tokens, role, profile);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
tokens.push(keywordToken);
|
|
55
|
-
for (const role of sortedRoles) {
|
|
56
|
-
addRoleWithMarker(tokens, role, profile);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return tokens;
|
|
60
|
-
}
|
|
61
|
-
function addRoleWithMarker(tokens, roleSpec, profile) {
|
|
62
|
-
const marker = getMarkerForRole(roleSpec, profile);
|
|
63
|
-
const isOptional = !roleSpec.required;
|
|
64
|
-
const roleToken = {
|
|
65
|
-
type: "role",
|
|
66
|
-
role: roleSpec.role,
|
|
67
|
-
optional: isOptional,
|
|
68
|
-
expectedTypes: roleSpec.expectedTypes,
|
|
69
|
-
...roleSpec.greedy && { greedy: true }
|
|
70
|
-
};
|
|
71
|
-
if (marker) {
|
|
72
|
-
const markerInfo = profile.roleMarkers?.[roleSpec.role];
|
|
73
|
-
const defaultPosition = profile.wordOrder === "SOV" ? "after" : "before";
|
|
74
|
-
const position = roleSpec.markerPosition ?? markerInfo?.position ?? defaultPosition;
|
|
75
|
-
if (isOptional) {
|
|
76
|
-
if (position === "before") {
|
|
77
|
-
tokens.push({
|
|
78
|
-
type: "group",
|
|
79
|
-
optional: true,
|
|
80
|
-
tokens: [{ type: "literal", value: marker }, roleToken]
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
tokens.push({
|
|
84
|
-
type: "group",
|
|
85
|
-
optional: true,
|
|
86
|
-
tokens: [roleToken, { type: "literal", value: marker }]
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
if (position === "before") {
|
|
91
|
-
tokens.push({ type: "literal", value: marker });
|
|
92
|
-
tokens.push(roleToken);
|
|
93
|
-
} else {
|
|
94
|
-
tokens.push(roleToken);
|
|
95
|
-
tokens.push({ type: "literal", value: marker });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
tokens.push(roleToken);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function getMarkerForRole(roleSpec, profile) {
|
|
103
|
-
if (roleSpec.markerOverride?.[profile.code]) {
|
|
104
|
-
return roleSpec.markerOverride[profile.code];
|
|
105
|
-
}
|
|
106
|
-
return profile.roleMarkers?.[roleSpec.role]?.primary;
|
|
107
|
-
}
|
|
1
|
+
// src/generation/profile.ts
|
|
108
2
|
function sortRolesByWordOrder(roles, wordOrder) {
|
|
109
3
|
const sorted = [...roles];
|
|
110
4
|
if (wordOrder === "SVO") {
|
|
@@ -114,47 +8,6 @@ function sortRolesByWordOrder(roles, wordOrder) {
|
|
|
114
8
|
}
|
|
115
9
|
return sorted;
|
|
116
10
|
}
|
|
117
|
-
function buildExtractionRules(schema, profile) {
|
|
118
|
-
const rules = {};
|
|
119
|
-
for (const roleSpec of schema.roles) {
|
|
120
|
-
const marker = getMarkerForRole(roleSpec, profile);
|
|
121
|
-
const rule = {
|
|
122
|
-
...roleSpec.default !== void 0 && { default: roleSpec.default },
|
|
123
|
-
...marker && { marker }
|
|
124
|
-
};
|
|
125
|
-
rules[roleSpec.role] = rule;
|
|
126
|
-
}
|
|
127
|
-
return rules;
|
|
128
|
-
}
|
|
129
|
-
function buildFormatString(schema, profile, keyword) {
|
|
130
|
-
const isSOV = profile.wordOrder === "SOV";
|
|
131
|
-
const preVerb = [];
|
|
132
|
-
const postVerb = [];
|
|
133
|
-
const sortedRoles = sortRolesByWordOrder(schema.roles, profile.wordOrder);
|
|
134
|
-
for (const role of sortedRoles) {
|
|
135
|
-
const marker = getMarkerForRole(role, profile);
|
|
136
|
-
const roleName = `{${role.role}}`;
|
|
137
|
-
const bucket = isSOV && role.sovSlot === "postVerb" ? postVerb : preVerb;
|
|
138
|
-
if (marker) {
|
|
139
|
-
const markerInfo = profile.roleMarkers?.[role.role];
|
|
140
|
-
if (markerInfo?.position === "after") {
|
|
141
|
-
bucket.push(`${roleName} ${marker}`);
|
|
142
|
-
} else {
|
|
143
|
-
bucket.push(`${marker} ${roleName}`);
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
bucket.push(roleName);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return (isSOV ? [...preVerb, keyword, ...postVerb] : [keyword, ...preVerb, ...postVerb]).join(
|
|
150
|
-
" "
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
function generatePatternVariants(schema, profile, config = defaultConfig) {
|
|
154
|
-
const patterns = [];
|
|
155
|
-
patterns.push(generatePattern(schema, profile, config));
|
|
156
|
-
return patterns;
|
|
157
|
-
}
|
|
158
11
|
|
|
159
12
|
// src/core/types.ts
|
|
160
13
|
import {
|
|
@@ -296,10 +149,10 @@ import { createDiagnosticCollector, fromError, filterBySeverity } from "@lokascr
|
|
|
296
149
|
// src/generation/schema-patterns.ts
|
|
297
150
|
function createSchemaPatternGenerator(grammar) {
|
|
298
151
|
return {
|
|
299
|
-
generatePattern: (schema, profile, config) =>
|
|
152
|
+
generatePattern: (schema, profile, config) => generatePattern(grammar, schema, profile, config),
|
|
300
153
|
generateSimplePattern: (schema, profile, config) => generateSimplePattern(grammar, schema, profile, config),
|
|
301
154
|
generateVerbFirstPattern: (schema, profile, config) => generateVerbFirstPattern(schema, profile, config),
|
|
302
|
-
generatePatternVariants: (schema, profile, config) =>
|
|
155
|
+
generatePatternVariants: (schema, profile, config) => generatePatternVariants(grammar, schema, profile, config),
|
|
303
156
|
buildRoleToken
|
|
304
157
|
};
|
|
305
158
|
}
|
|
@@ -349,21 +202,21 @@ function schemaMarkerAlternatives(roleSpec, languageCode, marker) {
|
|
|
349
202
|
const alternatives = [.../* @__PURE__ */ new Set([...legacy, ...variants])].filter((a) => a && a !== marker);
|
|
350
203
|
return alternatives.length ? alternatives : void 0;
|
|
351
204
|
}
|
|
352
|
-
var
|
|
205
|
+
var defaultConfig = {
|
|
353
206
|
basePriority: 100,
|
|
354
207
|
generateSimpleVariants: true,
|
|
355
208
|
generateAlternatives: true
|
|
356
209
|
};
|
|
357
|
-
function
|
|
210
|
+
function generatePattern(grammar, schema, profile, config = defaultConfig) {
|
|
358
211
|
const id = `${schema.action}-${profile.code}-generated`;
|
|
359
212
|
const priority = config.basePriority ?? 100;
|
|
360
213
|
const keyword = profile.keywords[schema.action];
|
|
361
214
|
if (!keyword) {
|
|
362
215
|
throw new Error(`No keyword translation for '${schema.action}' in ${profile.code}`);
|
|
363
216
|
}
|
|
364
|
-
const tokens =
|
|
217
|
+
const tokens = buildTokens(grammar, schema, profile, keyword);
|
|
365
218
|
const extraction = buildExtractionRulesWithDefaults(schema, profile);
|
|
366
|
-
const format =
|
|
219
|
+
const format = buildFormatString(grammar, schema, profile, keyword);
|
|
367
220
|
return {
|
|
368
221
|
id,
|
|
369
222
|
language: profile.code,
|
|
@@ -376,7 +229,7 @@ function generatePattern2(grammar, schema, profile, config = defaultConfig2) {
|
|
|
376
229
|
extraction
|
|
377
230
|
};
|
|
378
231
|
}
|
|
379
|
-
function generateSimplePattern(grammar, schema, profile, config =
|
|
232
|
+
function generateSimplePattern(grammar, schema, profile, config = defaultConfig) {
|
|
380
233
|
const optionalRoles = schema.roles.filter((r) => !r.required);
|
|
381
234
|
if (optionalRoles.length === 0) {
|
|
382
235
|
return null;
|
|
@@ -386,7 +239,7 @@ function generateSimplePattern(grammar, schema, profile, config = defaultConfig2
|
|
|
386
239
|
...schema,
|
|
387
240
|
roles: requiredRoles
|
|
388
241
|
};
|
|
389
|
-
const pattern =
|
|
242
|
+
const pattern = generatePattern(grammar, simpleSchema, profile, config);
|
|
390
243
|
return {
|
|
391
244
|
...pattern,
|
|
392
245
|
id: `${schema.action}-${profile.code}-generated-simple`,
|
|
@@ -395,7 +248,7 @@ function generateSimplePattern(grammar, schema, profile, config = defaultConfig2
|
|
|
395
248
|
extraction: buildExtractionRulesWithDefaults(schema, profile)
|
|
396
249
|
};
|
|
397
250
|
}
|
|
398
|
-
function generateVerbFirstPattern(schema, profile, config =
|
|
251
|
+
function generateVerbFirstPattern(schema, profile, config = defaultConfig) {
|
|
399
252
|
if (profile.wordOrder !== "SOV") return null;
|
|
400
253
|
const requiredRoles = schema.roles.filter((r) => r.required);
|
|
401
254
|
if (requiredRoles.length !== 1) return null;
|
|
@@ -428,11 +281,11 @@ function generateVerbFirstPattern(schema, profile, config = defaultConfig2) {
|
|
|
428
281
|
extraction: buildExtractionRulesWithDefaults(schema, profile)
|
|
429
282
|
};
|
|
430
283
|
}
|
|
431
|
-
function
|
|
284
|
+
function generatePatternVariants(grammar, schema, profile, config = defaultConfig) {
|
|
432
285
|
const patterns = [];
|
|
433
286
|
const full = schema;
|
|
434
287
|
schema = withoutVariantOnlyRoles(schema);
|
|
435
|
-
patterns.push(
|
|
288
|
+
patterns.push(generatePattern(grammar, schema, profile, config));
|
|
436
289
|
if (config.generateSimpleVariants) {
|
|
437
290
|
const simple = generateSimplePattern(grammar, schema, profile, config);
|
|
438
291
|
if (simple) {
|
|
@@ -444,7 +297,7 @@ function generatePatternVariants2(grammar, schema, profile, config = defaultConf
|
|
|
444
297
|
...schema,
|
|
445
298
|
roles: schema.roles.filter((r) => r.role !== omitted)
|
|
446
299
|
};
|
|
447
|
-
const variant =
|
|
300
|
+
const variant = generatePattern(grammar, variantSchema, profile, config);
|
|
448
301
|
patterns.push({
|
|
449
302
|
...variant,
|
|
450
303
|
id: `${schema.action}-${profile.code}-generated-no-${omitted}`,
|
|
@@ -459,7 +312,7 @@ function generatePatternVariants2(grammar, schema, profile, config = defaultConf
|
|
|
459
312
|
(r) => r.role === widen.role ? { ...r, expectedTypes: [...widen.types] } : r
|
|
460
313
|
)
|
|
461
314
|
};
|
|
462
|
-
const main =
|
|
315
|
+
const main = generatePattern(grammar, cloneSchema, profile, config);
|
|
463
316
|
patterns.push({
|
|
464
317
|
...main,
|
|
465
318
|
id: `${schema.action}-${profile.code}-generated-${widen.idSuffix}`,
|
|
@@ -474,7 +327,7 @@ function generatePatternVariants2(grammar, schema, profile, config = defaultConf
|
|
|
474
327
|
return r.role === v.widen?.role ? { ...required, expectedTypes: [...v.widen.types] } : required;
|
|
475
328
|
})
|
|
476
329
|
};
|
|
477
|
-
const variant =
|
|
330
|
+
const variant = generatePattern(grammar, variantSchema, profile, config);
|
|
478
331
|
patterns.push({
|
|
479
332
|
...variant,
|
|
480
333
|
id: `${schema.action}-${profile.code}-generated-${v.idSuffix}`,
|
|
@@ -499,7 +352,7 @@ function generatePatternVariants2(grammar, schema, profile, config = defaultConf
|
|
|
499
352
|
};
|
|
500
353
|
const delta = v.priorityDelta ?? 5;
|
|
501
354
|
const carrier = v.methodCarrier ? { [v.methodCarrier]: { value: literal } } : {};
|
|
502
|
-
const main =
|
|
355
|
+
const main = generatePattern(grammar, cloneSchema, profile, config);
|
|
503
356
|
patterns.push({
|
|
504
357
|
...main,
|
|
505
358
|
id: `${schema.action}-${profile.code}-generated-${v.idSuffix}`,
|
|
@@ -520,7 +373,7 @@ function generatePatternVariants2(grammar, schema, profile, config = defaultConf
|
|
|
520
373
|
}
|
|
521
374
|
return patterns;
|
|
522
375
|
}
|
|
523
|
-
function
|
|
376
|
+
function buildTokens(grammar, schema, profile, keyword) {
|
|
524
377
|
const tokens = [];
|
|
525
378
|
const verbToken = keyword.alternatives ? { type: "literal", value: keyword.primary, alternatives: keyword.alternatives } : { type: "literal", value: keyword.primary };
|
|
526
379
|
const postVerbRoles = profile.wordOrder === "SOV" ? schema.roles.filter((r) => r.sovSlot === "postVerb") : [];
|
|
@@ -674,7 +527,7 @@ function buildRoleToken(roleSpec, profile) {
|
|
|
674
527
|
}
|
|
675
528
|
return tokens;
|
|
676
529
|
}
|
|
677
|
-
function
|
|
530
|
+
function buildExtractionRules(schema, profile) {
|
|
678
531
|
const rules = {};
|
|
679
532
|
for (const roleSpec of schema.roles) {
|
|
680
533
|
const overrideMarker = roleSpec.markerOverride?.[profile.code];
|
|
@@ -704,7 +557,7 @@ function buildExtractionRules2(schema, profile) {
|
|
|
704
557
|
return rules;
|
|
705
558
|
}
|
|
706
559
|
function buildExtractionRulesWithDefaults(schema, profile) {
|
|
707
|
-
const baseRules =
|
|
560
|
+
const baseRules = buildExtractionRules(schema, profile);
|
|
708
561
|
const rules = {};
|
|
709
562
|
for (const roleSpec of schema.roles) {
|
|
710
563
|
const baseRule = baseRules[roleSpec.role] || {};
|
|
@@ -716,7 +569,7 @@ function buildExtractionRulesWithDefaults(schema, profile) {
|
|
|
716
569
|
}
|
|
717
570
|
return rules;
|
|
718
571
|
}
|
|
719
|
-
function
|
|
572
|
+
function buildFormatString(grammar, schema, profile, keyword) {
|
|
720
573
|
const parts = [];
|
|
721
574
|
const sortedRoles = sortRolesByPosition(schema.roles, profile.wordOrder, grammar.positionOrder);
|
|
722
575
|
const roleParts = sortedRoles.map((roleSpec) => {
|
|
@@ -887,8 +740,6 @@ export {
|
|
|
887
740
|
detectWordOrders,
|
|
888
741
|
filterBySeverity,
|
|
889
742
|
fromError,
|
|
890
|
-
generatePattern,
|
|
891
|
-
generatePatternVariants,
|
|
892
743
|
legacyMarkerAlternatives,
|
|
893
744
|
lookupKeyword,
|
|
894
745
|
lookupMarker,
|