@lokascript/framework 2.6.0 → 2.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/dist/index.cjs +121 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +117 -16
- package/dist/index.js.map +1 -1
- package/dist/multilingual/builders.d.ts +88 -0
- package/dist/multilingual/builders.d.ts.map +1 -0
- package/dist/multilingual/index.d.ts +7 -3
- package/dist/multilingual/index.d.ts.map +1 -1
- package/dist/multilingual/index.js +1549 -0
- package/dist/multilingual/index.js.map +1 -1
- package/dist/multilingual/types.d.ts +117 -0
- package/dist/multilingual/types.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +20 -0
- package/src/multilingual/bridge.test.ts +441 -0
- package/src/multilingual/builders.ts +224 -0
- package/src/multilingual/index.ts +23 -4
- package/src/multilingual/types.ts +121 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework ↔ Semantic bridge builders.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions that combine an injected {@link GrammarProfileSlice} (the
|
|
5
|
+
* per-language grammar facts, typically a `@lokascript/semantic`
|
|
6
|
+
* `LanguageProfile`) with a {@link DomainVocabulary} (the only thing a domain
|
|
7
|
+
* authors per language) into the shapes `createMultilingualDSL` consumes:
|
|
8
|
+
* a `PatternGenLanguageProfile`, a `LanguageTokenizer`, or a complete
|
|
9
|
+
* `LanguageConfig`.
|
|
10
|
+
*/
|
|
11
|
+
import type { LanguageTokenizer } from '../core/types';
|
|
12
|
+
import type { PatternGenLanguageProfile } from '../generation/pattern-generator';
|
|
13
|
+
import type { LanguageConfig } from '../api/create-dsl';
|
|
14
|
+
import type { LanguageProfile as GrammarProfile } from '../grammar';
|
|
15
|
+
import { type ValueExtractor } from '../interfaces/value-extractor';
|
|
16
|
+
import type { DomainVocabulary, GrammarProfileSlice } from './types';
|
|
17
|
+
/**
|
|
18
|
+
* Build a pattern-generation profile: domain keywords + slice grammar
|
|
19
|
+
* (word order, role markers). The result feeds `generatePattern` /
|
|
20
|
+
* `generatePatternVariants` and `LanguageConfig.patternProfile`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildPatternProfile(slice: GrammarProfileSlice, vocab: DomainVocabulary): PatternGenLanguageProfile;
|
|
23
|
+
/** Options for {@link buildDomainTokenizer}, overriding the slice-derived defaults. */
|
|
24
|
+
export interface DomainTokenizerOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Recognize operator tokens (default: false, matching `createSimpleTokenizer`).
|
|
27
|
+
* Domains whose grammar contains operators (e.g. SQL's `WHERE age > 18`) pass
|
|
28
|
+
* `true`; most natural-language DSLs leave it off.
|
|
29
|
+
*/
|
|
30
|
+
readonly includeOperators?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Case-insensitive keyword matching. Defaults to true for bicameral scripts
|
|
33
|
+
* (`latin`, `cyrillic`, or when the slice omits `script`), false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
readonly caseInsensitive?: boolean;
|
|
36
|
+
/** Extra extractors, registered before the slice-derived ones */
|
|
37
|
+
readonly customExtractors?: readonly ValueExtractor[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build a domain tokenizer from a grammar slice + domain vocabulary, wrapping
|
|
41
|
+
* `createSimpleTokenizer`. Derived from the slice:
|
|
42
|
+
*
|
|
43
|
+
* - `direction` (rtl for e.g. Arabic/Hebrew slices)
|
|
44
|
+
* - keyword set: vocabulary verbs (primary + alternatives), role markers
|
|
45
|
+
* (slice defaults merged with `vocab.roleMarkerOverrides`), tokenization
|
|
46
|
+
* particles, and `vocab.tokenizerKeywords`
|
|
47
|
+
* - keyword-normalization profile (native verb → action name, marker → role)
|
|
48
|
+
* - a `LatinExtendedIdentifierExtractor` when `slice.script === 'latin'`, so
|
|
49
|
+
* diacritics (ñ, é, ş, …) never split identifiers
|
|
50
|
+
* - case-insensitivity for bicameral scripts
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildDomainTokenizer(slice: GrammarProfileSlice, vocab: DomainVocabulary, options?: DomainTokenizerOptions): LanguageTokenizer;
|
|
53
|
+
/** Metadata / overrides for {@link buildLanguageConfig}. */
|
|
54
|
+
export interface LanguageConfigMeta {
|
|
55
|
+
/** English name (default: `slice.name`, falling back to `slice.code`) */
|
|
56
|
+
readonly name?: string;
|
|
57
|
+
/** Native name (default: `slice.nativeName`, falling back to the English name) */
|
|
58
|
+
readonly nativeName?: string;
|
|
59
|
+
/** Grammar-transformation profile to attach (optional, as on `LanguageConfig`) */
|
|
60
|
+
readonly grammarProfile?: GrammarProfile;
|
|
61
|
+
/** Use this tokenizer instead of the slice-derived one */
|
|
62
|
+
readonly tokenizer?: LanguageTokenizer;
|
|
63
|
+
/** Options for the slice-derived tokenizer (ignored when `tokenizer` is given) */
|
|
64
|
+
readonly tokenizerOptions?: DomainTokenizerOptions;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The one-call path into `createMultilingualDSL`: build a complete
|
|
68
|
+
* `LanguageConfig` (tokenizer + pattern profile + names) from a grammar slice
|
|
69
|
+
* and a domain vocabulary.
|
|
70
|
+
*/
|
|
71
|
+
export declare function buildLanguageConfig(slice: GrammarProfileSlice, vocab: DomainVocabulary, meta?: LanguageConfigMeta): LanguageConfig;
|
|
72
|
+
/**
|
|
73
|
+
* Derive schema `markerOverride` defaults for ONE language from the slice's
|
|
74
|
+
* role markers, given a domain-role → semantic-role mapping. Returns
|
|
75
|
+
* `{ domainRole: primaryMarker }` with entries only where the slice has a
|
|
76
|
+
* marker for the mapped semantic role.
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* deriveRoleMarkers(jaSlice, { table: 'source', target: 'destination' });
|
|
80
|
+
* // → { table: 'から', target: 'に' }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* Explicitly authored `markerOverride` entries stay authoritative — when
|
|
84
|
+
* assembling a per-language marker map for a schema role, spread the explicit
|
|
85
|
+
* entries after the derived defaults.
|
|
86
|
+
*/
|
|
87
|
+
export declare function deriveRoleMarkers(slice: GrammarProfileSlice, roleMapping: Readonly<Record<string, string>>): Record<string, string>;
|
|
88
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/multilingual/builders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,IAAI,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAmB,MAAM,SAAS,CAAC;AA+BtF;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,gBAAgB,GACtB,yBAAyB,CAiB3B;AAED,uFAAuF;AACvF,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC,iEAAiE;IACjE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;CACvD;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,gBAAgB,EACvB,OAAO,GAAE,sBAA2B,GACnC,iBAAiB,CA6CnB;AAED,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;IACvC,kFAAkF;IAClF,QAAQ,CAAC,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CACpD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,gBAAgB,EACvB,IAAI,GAAE,kBAAuB,GAC5B,cAAc,CAUhB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,mBAAmB,EAC1B,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC5C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Multilingual support
|
|
2
|
+
* Multilingual support — the framework ↔ semantic bridge.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Injection-based: domains import per-language grammar data (e.g. semantic's
|
|
5
|
+
* `KNOWN_PROFILES`) and inject it into these builders; framework itself never
|
|
6
|
+
* imports the semantic package. See `docs-internal/FRAMEWORK_SEMANTIC_BRIDGE_PLAN.md`.
|
|
6
7
|
*/
|
|
8
|
+
export type { GrammarProfileSlice, DomainVocabulary, DomainKeywordTranslation, DomainKeywordEntry, RoleMarkerSlice, TokenizationSlice, VerbSlice, } from './types';
|
|
9
|
+
export { buildPatternProfile, buildDomainTokenizer, buildLanguageConfig, deriveRoleMarkers, } from './builders';
|
|
10
|
+
export type { DomainTokenizerOptions, LanguageConfigMeta } from './builders';
|
|
7
11
|
export type { LanguageProfile, WordOrder, AdpositionType, MorphologyType } from '../grammar';
|
|
8
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/multilingual/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/multilingual/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,SAAS,GACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAG7E,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|