@lokascript/framework 4.6.0 → 4.7.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 +87 -1
- package/dist/api/create-dsl.d.ts +13 -0
- package/dist/api/create-dsl.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1756 -710
- package/dist/api/index.js.map +1 -1
- package/dist/api/translation-loss.d.ts +84 -0
- package/dist/api/translation-loss.d.ts.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1047 -684
- package/dist/core/index.js.map +1 -1
- package/dist/core/matching/confidence-model.d.ts +54 -0
- package/dist/core/matching/confidence-model.d.ts.map +1 -0
- package/dist/core/matching/index.d.ts +12 -0
- package/dist/core/matching/index.d.ts.map +1 -0
- package/dist/core/matching/match-skeleton.d.ts +114 -0
- package/dist/core/matching/match-skeleton.d.ts.map +1 -0
- package/dist/core/matching/stock-confidence.d.ts +15 -0
- package/dist/core/matching/stock-confidence.d.ts.map +1 -0
- package/dist/core/matching/stock-reader.d.ts +56 -0
- package/dist/core/matching/stock-reader.d.ts.map +1 -0
- package/dist/core/matching/stock-reading.d.ts +44 -0
- package/dist/core/matching/stock-reading.d.ts.map +1 -0
- package/dist/core/matching/value-reader.d.ts +62 -0
- package/dist/core/matching/value-reader.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.js +561 -660
- package/dist/core/pattern-matching/index.js.map +1 -1
- package/dist/core/pattern-matching/pattern-matcher.d.ts +0 -117
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -1
- package/dist/core/types.d.ts +48 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/generation/index.d.ts +2 -0
- package/dist/generation/index.d.ts.map +1 -1
- package/dist/generation/index.js +583 -1
- package/dist/generation/index.js.map +1 -1
- package/dist/generation/pattern-render.d.ts +72 -0
- package/dist/generation/pattern-render.d.ts.map +1 -0
- package/dist/generation/schema-patterns.d.ts +152 -0
- package/dist/generation/schema-patterns.d.ts.map +1 -0
- package/dist/index.cjs +1979 -907
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1961 -906
- package/dist/index.js.map +1 -1
- package/dist/ir/index.js.map +1 -1
- package/dist/parsing/index.js +561 -660
- package/dist/parsing/index.js.map +1 -1
- package/dist/testing/gate/index.d.ts +8 -0
- package/dist/testing/gate/index.d.ts.map +1 -0
- package/dist/testing/gate/index.js +632 -0
- package/dist/testing/gate/index.js.map +1 -0
- package/dist/testing/gate/lint/format.d.ts +7 -0
- package/dist/testing/gate/lint/format.d.ts.map +1 -0
- package/dist/testing/gate/lint/index.d.ts +30 -0
- package/dist/testing/gate/lint/index.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/extractor-coverage.d.ts +18 -0
- package/dist/testing/gate/lint/rules/extractor-coverage.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/index.d.ts +14 -0
- package/dist/testing/gate/lint/rules/index.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/keyword-classification.d.ts +19 -0
- package/dist/testing/gate/lint/rules/keyword-classification.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/keyword-coverage.d.ts +13 -0
- package/dist/testing/gate/lint/rules/keyword-coverage.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/marker-tokenization.d.ts +20 -0
- package/dist/testing/gate/lint/rules/marker-tokenization.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/position-ordering.d.ts +25 -0
- package/dist/testing/gate/lint/rules/position-ordering.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/renderer-coherence.d.ts +24 -0
- package/dist/testing/gate/lint/rules/renderer-coherence.d.ts.map +1 -0
- package/dist/testing/gate/lint/rules/schema-rules.d.ts +10 -0
- package/dist/testing/gate/lint/rules/schema-rules.d.ts.map +1 -0
- package/dist/testing/gate/lint/types.d.ts +74 -0
- package/dist/testing/gate/lint/types.d.ts.map +1 -0
- package/dist/testing/gate/round-trip.d.ts +163 -0
- package/dist/testing/gate/round-trip.d.ts.map +1 -0
- package/package.json +6 -2
- package/src/__test__/fixtures/sql-dsl.ts +8 -2
- package/src/api/create-dsl-engine.test.ts +86 -0
- package/src/api/create-dsl.ts +141 -18
- package/src/api/index.ts +1 -0
- package/src/api/translation-loss.test.ts +89 -0
- package/src/api/translation-loss.ts +128 -0
- package/src/core/index.ts +1 -0
- package/src/core/matching/confidence-model.ts +58 -0
- package/src/core/matching/index.ts +12 -0
- package/src/core/matching/match-skeleton.test.ts +179 -0
- package/src/core/matching/match-skeleton.ts +621 -0
- package/src/core/matching/stock-confidence.ts +238 -0
- package/src/core/matching/stock-reader.test.ts +181 -0
- package/src/core/matching/stock-reader.ts +186 -0
- package/src/core/matching/stock-reading.ts +681 -0
- package/src/core/matching/value-reader.ts +85 -0
- package/src/core/pattern-matching/pattern-matcher.ts +11 -876
- package/src/core/types.ts +48 -0
- package/src/generation/index.ts +2 -0
- package/src/generation/pattern-render.ts +378 -0
- package/src/generation/schema-patterns.test.ts +99 -0
- package/src/generation/schema-patterns.ts +962 -0
- package/src/testing/gate/index.ts +8 -0
- package/src/testing/gate/lint/format.ts +23 -0
- package/src/testing/gate/lint/index.ts +73 -0
- package/src/testing/gate/lint/lint.test.ts +131 -0
- package/src/testing/gate/lint/rules/extractor-coverage.ts +63 -0
- package/src/testing/gate/lint/rules/index.ts +37 -0
- package/src/testing/gate/lint/rules/keyword-classification.ts +52 -0
- package/src/testing/gate/lint/rules/keyword-coverage.ts +38 -0
- package/src/testing/gate/lint/rules/marker-tokenization.ts +129 -0
- package/src/testing/gate/lint/rules/position-ordering.ts +87 -0
- package/src/testing/gate/lint/rules/renderer-coherence.ts +100 -0
- package/src/testing/gate/lint/rules/schema-rules.ts +35 -0
- package/src/testing/gate/lint/types.ts +83 -0
- package/src/testing/gate/round-trip.test.ts +118 -0
- package/src/testing/gate/round-trip.ts +438 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The matcher's confidence model: an injectable score for a pattern's match
|
|
3
|
+
* (domains rethink Phase 4.3). The interface moved here with the skeleton
|
|
4
|
+
* (`match-skeleton.ts`), which calls `calculate` once per matched pattern;
|
|
5
|
+
* hyperscript's model is `@lokascript/semantic`'s `DefaultConfidenceModel`.
|
|
6
|
+
*/
|
|
7
|
+
import type { LanguagePattern, SemanticRole, SemanticValue } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Context passed to confidence model methods.
|
|
10
|
+
*/
|
|
11
|
+
export interface ConfidenceContext {
|
|
12
|
+
/** The pattern being matched */
|
|
13
|
+
readonly pattern: LanguagePattern;
|
|
14
|
+
/** Captured semantic roles */
|
|
15
|
+
readonly captured: ReadonlyMap<SemanticRole, SemanticValue>;
|
|
16
|
+
/** Number of stem (morphological) keyword matches */
|
|
17
|
+
readonly stemMatchCount: number;
|
|
18
|
+
/** Total keyword matches attempted */
|
|
19
|
+
readonly totalKeywordMatches: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Breakdown of confidence scoring factors (for diagnostics/debugging).
|
|
23
|
+
*/
|
|
24
|
+
export interface ConfidenceBreakdown {
|
|
25
|
+
/** Role coverage score (0-1) */
|
|
26
|
+
readonly roleCoverage: number;
|
|
27
|
+
/** Stem match penalty applied (0 to -0.15) */
|
|
28
|
+
readonly stemPenalty: number;
|
|
29
|
+
/** Language-specific boost (e.g., VSO verb-first) */
|
|
30
|
+
readonly languageBoost: number;
|
|
31
|
+
/** Language-specific adjustment (e.g., preposition disambiguation) */
|
|
32
|
+
readonly languageAdjustment: number;
|
|
33
|
+
/** Final clamped confidence (0-1) */
|
|
34
|
+
readonly final: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Injectable confidence scoring model.
|
|
38
|
+
*
|
|
39
|
+
* Each method computes one factor of the confidence score.
|
|
40
|
+
* Override individual methods to customize scoring without rewriting the pipeline.
|
|
41
|
+
*/
|
|
42
|
+
export interface ConfidenceModel {
|
|
43
|
+
/**
|
|
44
|
+
* Calculate the full confidence score.
|
|
45
|
+
* Default implementation calls each factor method and combines them.
|
|
46
|
+
*/
|
|
47
|
+
calculate(ctx: ConfidenceContext): number;
|
|
48
|
+
/**
|
|
49
|
+
* Calculate confidence with a detailed breakdown.
|
|
50
|
+
* Useful for diagnostics and debugging.
|
|
51
|
+
*/
|
|
52
|
+
calculateWithBreakdown(ctx: ConfidenceContext): ConfidenceBreakdown;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=confidence-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence-model.d.ts","sourceRoot":"","sources":["../../../src/core/matching/confidence-model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gCAAgC;IAChC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;IAC5D,qDAAqD;IACrD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,sCAAsC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gCAAgC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAE1C;;;OAGG;IACH,sBAAsB,CAAC,GAAG,EAAE,iBAAiB,GAAG,mBAAmB,CAAC;CACrE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pattern matcher's skeleton and its value-reader seam (domains rethink
|
|
3
|
+
* Phase 4.3): the matcher semantic's hyperscript parser runs, with
|
|
4
|
+
* hyperscript's reading behind `ValueReader`.
|
|
5
|
+
*/
|
|
6
|
+
export { MatchSkeleton } from './match-skeleton';
|
|
7
|
+
export type { MatchView, RoleSlot, ValueReader } from './value-reader';
|
|
8
|
+
export type { ConfidenceBreakdown, ConfidenceContext, ConfidenceModel } from './confidence-model';
|
|
9
|
+
export { StockValueReader, createStockReader, greedyStopMarkers, readGreedy } from './stock-reader';
|
|
10
|
+
export { readRoleValue, type ReadingProfile } from './stock-reading';
|
|
11
|
+
export { stockConfidenceModel } from './stock-confidence';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pattern matcher's skeleton: the grammar-neutral half of semantic's matcher
|
|
3
|
+
* (domains rethink Phase 4.2-4.3, `docs-internal/DOMAINS_RETHINK.md`).
|
|
4
|
+
*
|
|
5
|
+
* It walks a pattern's literals, groups and role slots against the token
|
|
6
|
+
* stream: literal matching (exact, normalized, stem, case- and
|
|
7
|
+
* diacritic-insensitive, shattered compounds), optional groups with exact
|
|
8
|
+
* rollback and the marker discipline of a postpositional group, the
|
|
9
|
+
* speculative skip of an optional slot, role spans, memoized ranking by
|
|
10
|
+
* priority then confidence, the confidence model, and the extraction rules.
|
|
11
|
+
* Every value is read by the grammar's `ValueReader` (`value-reader.ts`);
|
|
12
|
+
* hyperscript's is `@lokascript/semantic`'s `HyperscriptValueReader`, and its
|
|
13
|
+
* confidence model semantic's `DefaultConfidenceModel`.
|
|
14
|
+
*/
|
|
15
|
+
import type { LanguagePattern, PatternMatchResult, TokenStream } from '../types';
|
|
16
|
+
import type { ConfidenceModel } from './confidence-model';
|
|
17
|
+
import type { MatchView, ValueReader } from './value-reader';
|
|
18
|
+
export declare class MatchSkeleton {
|
|
19
|
+
/**
|
|
20
|
+
* The pattern tokens still to match after the one being matched, through
|
|
21
|
+
* every enclosing group: a value stops at any marker the pattern still owes.
|
|
22
|
+
*/
|
|
23
|
+
private patternRest;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the role slot being matched directly follows a literal the pattern
|
|
26
|
+
* matched: its marker (`[por {quantity}]`), or the command's verb.
|
|
27
|
+
*/
|
|
28
|
+
private slotAfterLiteral;
|
|
29
|
+
/** Injectable confidence scoring model (Phase 3.3) */
|
|
30
|
+
private readonly confidenceModel;
|
|
31
|
+
/**
|
|
32
|
+
* Selective memoization cache (Phase 6.1).
|
|
33
|
+
* Caches pattern match results keyed by `tokenPosition:patternId`.
|
|
34
|
+
* Cleared before each top-level matchBest() call.
|
|
35
|
+
*/
|
|
36
|
+
private matchCache;
|
|
37
|
+
/**
|
|
38
|
+
* Stream index where each role's capture began, for the current
|
|
39
|
+
* `matchPattern` call. Rebuilt per call, written on the same success path as
|
|
40
|
+
* `captured` — see `PatternMatchResult.roleStarts`.
|
|
41
|
+
*/
|
|
42
|
+
private roleStarts;
|
|
43
|
+
/** The grammar's value reading: every role slot, and the grammar's hooks. */
|
|
44
|
+
private readonly reader;
|
|
45
|
+
/**
|
|
46
|
+
* @param makeReader - builds the grammar's reader, handed this matcher's view
|
|
47
|
+
* of the match in progress (one reader per matcher).
|
|
48
|
+
*/
|
|
49
|
+
constructor(makeReader: (view: MatchView) => ValueReader, confidenceModel: ConfidenceModel);
|
|
50
|
+
/**
|
|
51
|
+
* Try to match a single pattern against the token stream.
|
|
52
|
+
* Returns the match result or null if no match.
|
|
53
|
+
*/
|
|
54
|
+
matchPattern(tokens: TokenStream, pattern: LanguagePattern): PatternMatchResult | null;
|
|
55
|
+
/**
|
|
56
|
+
* Try to match multiple patterns, return the best match.
|
|
57
|
+
*/
|
|
58
|
+
matchBest(tokens: TokenStream, patterns: LanguagePattern[]): PatternMatchResult | null;
|
|
59
|
+
/**
|
|
60
|
+
* Match a sequence of pattern tokens against the token stream.
|
|
61
|
+
*/
|
|
62
|
+
private matchTokenSequence;
|
|
63
|
+
/**
|
|
64
|
+
* Match a single pattern token against the current position in the stream.
|
|
65
|
+
*/
|
|
66
|
+
private matchPatternToken;
|
|
67
|
+
/**
|
|
68
|
+
* Match a literal pattern token (keyword or particle).
|
|
69
|
+
*/
|
|
70
|
+
private matchLiteralToken;
|
|
71
|
+
/**
|
|
72
|
+
* Match a compound keyword (`titik-henti`, `по_умолчанию`) against a
|
|
73
|
+
* shattered token run (`titik` `-` `henti` / `по` `_` `умолчанию`): word
|
|
74
|
+
* segments must be identifier/keyword/particle tokens equal to the expected
|
|
75
|
+
* segments (case-insensitive; particle because prepositions like ru `по` /
|
|
76
|
+
* uk `за` lead some underscore compounds), separators lone `sep` tokens.
|
|
77
|
+
* Consumes the run on success, resets the stream on failure.
|
|
78
|
+
*/
|
|
79
|
+
private tryMatchShatteredCompound;
|
|
80
|
+
/**
|
|
81
|
+
* Match a group pattern token (optional sequence).
|
|
82
|
+
*/
|
|
83
|
+
private matchGroupToken;
|
|
84
|
+
/**
|
|
85
|
+
* Whether a pattern token (literal, or a group starting with a literal) would
|
|
86
|
+
* match the given stream token. Used to keep the event-head source-clause
|
|
87
|
+
* consumption from stealing a marker the pattern explicitly expects.
|
|
88
|
+
*/
|
|
89
|
+
private patternTokenWouldMatch;
|
|
90
|
+
/**
|
|
91
|
+
* Get the type of match for a token against a value.
|
|
92
|
+
* Used for confidence calculation.
|
|
93
|
+
*/
|
|
94
|
+
private getMatchType;
|
|
95
|
+
/**
|
|
96
|
+
* Track stem matches for confidence calculation.
|
|
97
|
+
* This is set during matching and read during confidence calculation.
|
|
98
|
+
*/
|
|
99
|
+
private stemMatchCount;
|
|
100
|
+
private totalKeywordMatches;
|
|
101
|
+
/**
|
|
102
|
+
* Apply extraction rules to fill in static values and defaults for missing
|
|
103
|
+
* roles, and re-shape captured roles that declare a `transform` (the
|
|
104
|
+
* ExtractionRule field was documented but unwired — go-qu-url-dest is the
|
|
105
|
+
* first consumer: it re-types the marker-bound capture to the expression
|
|
106
|
+
* shape the en reference produces).
|
|
107
|
+
*/
|
|
108
|
+
private applyExtractionRules;
|
|
109
|
+
/**
|
|
110
|
+
* Check if a pattern token is optional.
|
|
111
|
+
*/
|
|
112
|
+
private isOptional;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=match-skeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-skeleton.d.ts","sourceRoot":"","sources":["../../../src/core/matching/match-skeleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,eAAe,EAEf,kBAAkB,EAGlB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7D,qBAAa,aAAa;IACxB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAsB;IAEzC;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAS;IAEjC,sDAAsD;IACtD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAElD;;;;OAIG;IACH,OAAO,CAAC,UAAU,CAAgD;IAElE;;;;OAIG;IACH,OAAO,CAAC,UAAU,CAAmC;IAErD,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC;;;OAGG;gBACS,UAAU,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,WAAW,EAAE,eAAe,EAAE,eAAe;IAS1F;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,GAAG,kBAAkB,GAAG,IAAI;IAyCtF;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,kBAAkB,GAAG,IAAI;IAiDtF;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA+F1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA8BzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoDzB;;;;;;;OAOG;IACH,OAAO,CAAC,yBAAyB;IA+BjC;;OAEG;IACH,OAAO,CAAC,eAAe;IAmGvB;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAuCpB;;;OAGG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC,OAAO,CAAC,mBAAmB,CAAa;IAExC;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAoC5B;;OAEG;IACH,OAAO,CAAC,UAAU;CAGnB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stock confidence model: how framework's old matcher scored a domain
|
|
3
|
+
* pattern's match (`core/pattern-matching/`), moved here as a `ConfidenceModel`
|
|
4
|
+
* for the matcher's skeleton (domains rethink Phase 4.7); the old matcher calls
|
|
5
|
+
* it too until Phase 6.
|
|
6
|
+
*
|
|
7
|
+
* Role coverage (a required slot 1, an optional one 0.8, an absent optional one
|
|
8
|
+
* with a default 60% of that), a stem-match penalty (up to 15%, floor 0.5), and
|
|
9
|
+
* two Arabic adjustments: a VSO verb-first boost and the preposition each role
|
|
10
|
+
* takes most naturally.
|
|
11
|
+
*/
|
|
12
|
+
import type { ConfidenceModel } from './confidence-model';
|
|
13
|
+
/** The stock confidence model (stateless: one instance serves every matcher). */
|
|
14
|
+
export declare const stockConfidenceModel: ConfidenceModel;
|
|
15
|
+
//# sourceMappingURL=stock-confidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-confidence.d.ts","sourceRoot":"","sources":["../../../src/core/matching/stock-confidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAA0C,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA4NlG,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stock value reader: what a domain grammar's matcher reads at each role
|
|
3
|
+
* slot, on the matcher's skeleton (domains rethink Phase 4.7,
|
|
4
|
+
* `docs-internal/DOMAINS_RETHINK.md`). Hyperscript's reader is semantic's
|
|
5
|
+
* `HyperscriptValueReader`; a domain takes this one.
|
|
6
|
+
*
|
|
7
|
+
* - A **greedy** slot (`RoleSpec.greedy`: a SQL condition, a column list) reads
|
|
8
|
+
* every token up to the next marker the pattern still owes, or the end, as
|
|
9
|
+
* one expression (`readGreedy`).
|
|
10
|
+
* - Any other slot reads one value (`readRoleValue`, the old matcher's reading):
|
|
11
|
+
* a selector, a quoted string, a number, a boolean, a duration, a URL, an
|
|
12
|
+
* identifier, or one of the multi-token forms it knows (`user.name`,
|
|
13
|
+
* `#dialog.showModal()`), checked against the slot's expected types.
|
|
14
|
+
* - A **required** slot reads nothing where the stream is at the marker the
|
|
15
|
+
* pattern wants next (the old matcher's guard against an SOV marker taken as
|
|
16
|
+
* a value). Where a required slot finds nothing to read, and the optional,
|
|
17
|
+
* marker-less slot just before it read a value with nothing read since, that
|
|
18
|
+
* value is given back and the required slot reads again (the old matcher's
|
|
19
|
+
* backtrack: behaviorspec `when clicks`, where the optional actor took
|
|
20
|
+
* `clicks`; flow `orders として 取得変数`, where the optional patient took
|
|
21
|
+
* `orders`).
|
|
22
|
+
* - An **optional** slot may be skipped for a token the pattern wants next, the
|
|
23
|
+
* skip kept only when the rest of the pattern then reads to the end.
|
|
24
|
+
*/
|
|
25
|
+
import type { LanguagePattern, LanguageToken, PatternToken, SemanticRole, SemanticValue, TokenStream } from '../types';
|
|
26
|
+
import type { MatchView, RoleSlot, ValueReader } from './value-reader';
|
|
27
|
+
import { type ReadingProfile } from './stock-reading';
|
|
28
|
+
/**
|
|
29
|
+
* The markers a greedy value stops at, from the pattern tokens still owed after
|
|
30
|
+
* it: the next literal (with its alternatives), and each optional group's
|
|
31
|
+
* leading literal up to and including the first required token.
|
|
32
|
+
*/
|
|
33
|
+
export declare function greedyStopMarkers(rest: readonly PatternToken[]): Set<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Read every token up to a stop marker (or the end) as one expression value,
|
|
36
|
+
* advancing past them; null (consuming nothing) when the first token stops it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function readGreedy(tokens: TokenStream, stopMarkers: ReadonlySet<string>): SemanticValue | null;
|
|
39
|
+
/** The stock reader, for a matcher whose profiles it may consult (possessive words). */
|
|
40
|
+
export declare class StockValueReader implements ValueReader {
|
|
41
|
+
private readonly view;
|
|
42
|
+
private readonly profiles;
|
|
43
|
+
private profile;
|
|
44
|
+
/** The last optional, marker-less slot that read a value: what a failing required slot may take back. */
|
|
45
|
+
private lastOptional;
|
|
46
|
+
constructor(view: MatchView, profiles?: Readonly<Record<string, ReadingProfile>>);
|
|
47
|
+
beginPattern(pattern: LanguagePattern): void;
|
|
48
|
+
readRole(tokens: TokenStream, slot: RoleSlot, captured: Map<SemanticRole, SemanticValue>, next: PatternToken | undefined): boolean;
|
|
49
|
+
/** One read of `slot`; `guard` refuses a required slot the marker the pattern wants next. */
|
|
50
|
+
private readOnce;
|
|
51
|
+
maySkipSlot(patternToken: PatternToken, token: LanguageToken | null, next: PatternToken | undefined): boolean;
|
|
52
|
+
atClauseEnd(tokens: TokenStream): boolean;
|
|
53
|
+
}
|
|
54
|
+
/** A reader factory for `MatchSkeleton`, reading with the given profiles. */
|
|
55
|
+
export declare function createStockReader(profiles?: Readonly<Record<string, ReadingProfile>>): (view: MatchView) => ValueReader;
|
|
56
|
+
//# sourceMappingURL=stock-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-reader.d.ts","sourceRoot":"","sources":["../../../src/core/matching/stock-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAEV,eAAe,EACf,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAqB5E;AASD;;;GAGG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,aAAa,GAAG,IAAI,CAStB;AAED,wFAAwF;AACxF,qBAAa,gBAAiB,YAAW,WAAW;IAMhD,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAN3B,OAAO,CAAC,OAAO,CAA6B;IAC5C,yGAAyG;IACzG,OAAO,CAAC,YAAY,CAAqE;gBAGtE,IAAI,EAAE,SAAS,EACf,QAAQ,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAM;IAG1E,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAK5C,QAAQ,CACN,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,EAC1C,IAAI,EAAE,YAAY,GAAG,SAAS,GAC7B,OAAO;IAwBV,6FAA6F;IAC7F,OAAO,CAAC,QAAQ;IAwBhB,WAAW,CACT,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,aAAa,GAAG,IAAI,EAC3B,IAAI,EAAE,YAAY,GAAG,SAAS,GAC7B,OAAO;IAWV,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO;CAG1C;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAC/B,QAAQ,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAM,GACtD,CAAC,IAAI,EAAE,SAAS,KAAK,WAAW,CAElC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a domain value at a role slot: the value reading framework's old
|
|
3
|
+
* matcher (`core/pattern-matching/`) did, moved here so the stock reader on the
|
|
4
|
+
* matcher's skeleton (`stock-reader.ts`, domains rethink Phase 4.7) and the old
|
|
5
|
+
* matcher run the same code until Phase 6 deletes the old one.
|
|
6
|
+
*
|
|
7
|
+
* In order: an English noise word before a selector (`the`), then the
|
|
8
|
+
* multi-token forms (a possessive, `my value`; a method call,
|
|
9
|
+
* `#dialog.showModal()`; a possessive selector, `#el's *opacity`; a property
|
|
10
|
+
* access, `user.name`; a selector and its property, `#out.innerText`), then one
|
|
11
|
+
* token by its kind (a selector, a quoted string, a number, a boolean, a
|
|
12
|
+
* duration, a URL, an identifier). Each is checked against the slot's
|
|
13
|
+
* expected types.
|
|
14
|
+
*/
|
|
15
|
+
import type { PatternToken, SemanticRole, SemanticValue, TokenStream } from '../types';
|
|
16
|
+
/** What value reading needs of a language profile: its code, and its possessive words. */
|
|
17
|
+
export interface ReadingProfile {
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly possessive?: {
|
|
20
|
+
readonly keywords?: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Safely convert a value to lowercase string.
|
|
25
|
+
* Provides protection against non-string values at runtime.
|
|
26
|
+
*/
|
|
27
|
+
/** `value` lower-cased, whatever it is (the old matcher's keyword compare uses it too). */
|
|
28
|
+
export declare function safeToLowerCase(value: unknown): string;
|
|
29
|
+
/**
|
|
30
|
+
* Match a role pattern token (captures a semantic value).
|
|
31
|
+
* Handles multi-token expressions like:
|
|
32
|
+
* - 'my value' (possessive keyword + property)
|
|
33
|
+
* - '#dialog.showModal()' (method call)
|
|
34
|
+
* - "#element's *opacity" (possessive selector + property)
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Read a value for `patternToken`'s role at the stream's position into
|
|
38
|
+
* `captured`, and advance past it. False when the slot does not match; an
|
|
39
|
+
* optional slot whose value does not fit returns true and captures nothing.
|
|
40
|
+
*/
|
|
41
|
+
export declare function readRoleValue(tokens: TokenStream, patternToken: PatternToken & {
|
|
42
|
+
type: 'role';
|
|
43
|
+
}, captured: Map<SemanticRole, SemanticValue>, profile?: ReadingProfile): boolean;
|
|
44
|
+
//# sourceMappingURL=stock-reading.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stock-reading.d.ts","sourceRoot":"","sources":["../../../src/core/matching/stock-reading.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,YAAY,EAEZ,YAAY,EACZ,aAAa,EACb,WAAW,EAEZ,MAAM,UAAU,CAAC;AAKlB,0FAA0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE;QACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC5C,CAAC;CACH;AAQD;;;GAGG;AACH,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQtD;AAED;;;;;;GAMG;AACH;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAC7C,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,EAC1C,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAwFT"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam between the pattern matcher's skeleton and a grammar's value
|
|
3
|
+
* reading (domains rethink Phase 4.2-4.3, `docs-internal/DOMAINS_RETHINK.md`).
|
|
4
|
+
*
|
|
5
|
+
* The skeleton (`match-skeleton.ts`) walks a pattern: its literals, groups and
|
|
6
|
+
* role slots, with rollback, ranking, spans, memoization and the confidence
|
|
7
|
+
* model. It knows nothing of what a VALUE is in the grammar, nor of the
|
|
8
|
+
* grammar's language profiles: each role slot is read through `readRole`, and
|
|
9
|
+
* the few places the walk needs a grammar fact go through the hooks below.
|
|
10
|
+
* Hyperscript's reader is `@lokascript/semantic`'s `HyperscriptValueReader`.
|
|
11
|
+
*/
|
|
12
|
+
import type { LanguagePattern, LanguageToken, PatternMatchResult, PatternToken, SemanticRole, SemanticValue, TokenStream } from '../types';
|
|
13
|
+
/** A role slot of a pattern. */
|
|
14
|
+
export type RoleSlot = PatternToken & {
|
|
15
|
+
type: 'role';
|
|
16
|
+
};
|
|
17
|
+
/** What the skeleton tells its reader about the match in progress. */
|
|
18
|
+
export interface MatchView {
|
|
19
|
+
/**
|
|
20
|
+
* The pattern tokens still to match after the slot being read, through every
|
|
21
|
+
* enclosing group: a value stops at any marker the pattern still owes.
|
|
22
|
+
*/
|
|
23
|
+
patternRest(): readonly PatternToken[];
|
|
24
|
+
/**
|
|
25
|
+
* Whether the slot being read directly follows a literal the pattern
|
|
26
|
+
* matched: its marker (`[por {quantity}]`), or the command's verb.
|
|
27
|
+
*/
|
|
28
|
+
slotAfterLiteral(): boolean;
|
|
29
|
+
/** Whether a pattern token (a literal, or a group starting with one) would match the token. */
|
|
30
|
+
wouldMatch(pt: PatternToken | undefined, token: LanguageToken): boolean;
|
|
31
|
+
}
|
|
32
|
+
/** A grammar's value reading, as the matcher's skeleton calls it. */
|
|
33
|
+
export interface ValueReader {
|
|
34
|
+
/** A pattern is about to be matched: reset what the reader keeps per pattern. */
|
|
35
|
+
beginPattern(pattern: LanguagePattern): void;
|
|
36
|
+
/**
|
|
37
|
+
* Read a value for `slot` at the stream's position into `captured`, and
|
|
38
|
+
* advance past it. False when the slot does not match; an optional slot that
|
|
39
|
+
* reads nothing returns true, captures nothing and consumes nothing.
|
|
40
|
+
*
|
|
41
|
+
* @param next - the pattern token after the slot (through an enclosing
|
|
42
|
+
* group's end), undefined where the pattern truly ends.
|
|
43
|
+
*/
|
|
44
|
+
readRole(tokens: TokenStream, slot: RoleSlot, captured: Map<SemanticRole, SemanticValue>, next: PatternToken | undefined): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Slot discipline: may the skeleton try skipping this optional pattern token
|
|
47
|
+
* (a slot, or an optional group of slots) for the token at the stream's head?
|
|
48
|
+
* The skeleton then matches the rest of the pattern without it, and keeps the
|
|
49
|
+
* skip only when that reaches a clause end (`atClauseEnd`). For a marker-less
|
|
50
|
+
* optional slot facing a verb it must not eat.
|
|
51
|
+
*/
|
|
52
|
+
maySkipSlot(patternToken: PatternToken, token: LanguageToken | null, next: PatternToken | undefined): boolean;
|
|
53
|
+
/** Does a clause end at the stream's position (its end, or the next clause's first word)? */
|
|
54
|
+
atClauseEnd(tokens: TokenStream): boolean;
|
|
55
|
+
/** Skip what the grammar reads as nothing before a sequence (Arabic proclitics). */
|
|
56
|
+
skipLeading?(tokens: TokenStream, sequence: readonly PatternToken[]): void;
|
|
57
|
+
/** Before `sequence[index]` is matched (hyperscript: an event head's source clause). */
|
|
58
|
+
beforePatternToken?(tokens: TokenStream, sequence: readonly PatternToken[], index: number, captured: Map<SemanticRole, SemanticValue>): void;
|
|
59
|
+
/** Fields the reader adds to the pattern's match result (hyperscript: `eventSource`). */
|
|
60
|
+
resultFields?(): Partial<PatternMatchResult>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=value-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-reader.d.ts","sourceRoot":"","sources":["../../../src/core/matching/value-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,gCAAgC;AAChC,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,sEAAsE;AACtE,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,WAAW,IAAI,SAAS,YAAY,EAAE,CAAC;IACvC;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC;IAC5B,+FAA+F;IAC/F,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC;CACzE;AAED,qEAAqE;AACrE,MAAM,WAAW,WAAW;IAC1B,iFAAiF;IACjF,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7C;;;;;;;OAOG;IACH,QAAQ,CACN,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,EAC1C,IAAI,EAAE,YAAY,GAAG,SAAS,GAC7B,OAAO,CAAC;IACX;;;;;;OAMG;IACH,WAAW,CACT,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,aAAa,GAAG,IAAI,EAC3B,IAAI,EAAE,YAAY,GAAG,SAAS,GAC7B,OAAO,CAAC;IACX,6FAA6F;IAC7F,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC;IAC1C,oFAAoF;IACpF,WAAW,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,CAAC;IAC3E,wFAAwF;IACxF,kBAAkB,CAAC,CACjB,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,GACzC,IAAI,CAAC;IACR,yFAAyF;IACzF,YAAY,CAAC,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC9C"}
|