@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
|
@@ -1,9 +1,28 @@
|
|
|
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
|
*/
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
export type {
|
|
10
|
+
GrammarProfileSlice,
|
|
11
|
+
DomainVocabulary,
|
|
12
|
+
DomainKeywordTranslation,
|
|
13
|
+
DomainKeywordEntry,
|
|
14
|
+
RoleMarkerSlice,
|
|
15
|
+
TokenizationSlice,
|
|
16
|
+
VerbSlice,
|
|
17
|
+
} from './types';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
buildPatternProfile,
|
|
21
|
+
buildDomainTokenizer,
|
|
22
|
+
buildLanguageConfig,
|
|
23
|
+
deriveRoleMarkers,
|
|
24
|
+
} from './builders';
|
|
25
|
+
export type { DomainTokenizerOptions, LanguageConfigMeta } from './builders';
|
|
26
|
+
|
|
27
|
+
// Re-export grammar types for language profiles (pre-bridge public surface)
|
|
9
28
|
export type { LanguageProfile, WordOrder, AdpositionType, MorphologyType } from '../grammar';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework ↔ Semantic bridge types.
|
|
3
|
+
*
|
|
4
|
+
* The bridge is injection-based: framework never imports the semantic package
|
|
5
|
+
* (semantic depends on framework). Instead, these are *structural* types that
|
|
6
|
+
* any `@lokascript/semantic` `LanguageProfile` satisfies without a cast, so a
|
|
7
|
+
* domain package imports the profile data from semantic and injects it into
|
|
8
|
+
* the builders in `./builders.ts`. Minimal hand-rolled fixtures satisfy them
|
|
9
|
+
* too, so tests (and domains without a semantic dep) need nothing extra.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A grammatical marker (preposition, particle, case suffix) for one role.
|
|
14
|
+
* Structural mirror of semantic's `RoleMarker` (position optional so
|
|
15
|
+
* hand-rolled fixtures can omit it; word-order defaults apply downstream).
|
|
16
|
+
*/
|
|
17
|
+
export interface RoleMarkerSlice {
|
|
18
|
+
readonly primary: string;
|
|
19
|
+
readonly alternatives?: readonly string[];
|
|
20
|
+
readonly position?: 'before' | 'after';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Structural mirror of semantic's `TokenizationConfig`. */
|
|
24
|
+
export interface TokenizationSlice {
|
|
25
|
+
readonly particles?: readonly string[];
|
|
26
|
+
readonly prefixes?: readonly string[];
|
|
27
|
+
readonly boundaryStrategy?: 'space' | 'particle' | 'character';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Structural mirror of semantic's `VerbConfig` (all fields optional). */
|
|
31
|
+
export interface VerbSlice {
|
|
32
|
+
readonly position?: 'start' | 'end' | 'second';
|
|
33
|
+
readonly suffixes?: readonly string[];
|
|
34
|
+
readonly subjectDrop?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The domain-reusable slice of a language profile: grammar and tokenization
|
|
39
|
+
* facts that hold for the language regardless of vocabulary. Everything a
|
|
40
|
+
* domain does NOT have to author when it inherits a language.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately excludes the hyperscript-specific fields of semantic's
|
|
43
|
+
* `LanguageProfile` (`keywords`, `eventHandler`, `possessive`, `references`)
|
|
44
|
+
* — a domain supplies its own vocabulary via {@link DomainVocabulary}.
|
|
45
|
+
*
|
|
46
|
+
* `roleMarkers` values admit `undefined` so semantic's
|
|
47
|
+
* `Partial<Record<SemanticRole, RoleMarker>>` assigns cleanly.
|
|
48
|
+
*/
|
|
49
|
+
export interface GrammarProfileSlice {
|
|
50
|
+
/** ISO 639-1 / BCP 47 language code */
|
|
51
|
+
readonly code: string;
|
|
52
|
+
/** Primary word order */
|
|
53
|
+
readonly wordOrder: 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OSV' | 'OVS';
|
|
54
|
+
/** Default grammatical markers per semantic role */
|
|
55
|
+
readonly roleMarkers?: { readonly [role: string]: RoleMarkerSlice | undefined };
|
|
56
|
+
/** How the language marks grammatical roles */
|
|
57
|
+
readonly markingStrategy?: 'preposition' | 'postposition' | 'particle' | 'case-suffix';
|
|
58
|
+
/** Tokenization facts (particles, word-boundary strategy) */
|
|
59
|
+
readonly tokenization?: TokenizationSlice;
|
|
60
|
+
/** Verb placement/conjugation facts */
|
|
61
|
+
readonly verb?: VerbSlice;
|
|
62
|
+
/** Text direction (default 'ltr') */
|
|
63
|
+
readonly direction?: 'ltr' | 'rtl';
|
|
64
|
+
/** Writing system (semantic's `ScriptType`; 'latin' enables diacritic-safe identifiers) */
|
|
65
|
+
readonly script?: string;
|
|
66
|
+
/** Whether words are space-separated */
|
|
67
|
+
readonly usesSpaces?: boolean;
|
|
68
|
+
/** Human-readable English name */
|
|
69
|
+
readonly name?: string;
|
|
70
|
+
/** Native name */
|
|
71
|
+
readonly nativeName?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** One domain keyword's translations in one language. */
|
|
75
|
+
export interface DomainKeywordTranslation {
|
|
76
|
+
/** Primary translation (used for rendering and as the canonical parse form) */
|
|
77
|
+
readonly primary: string;
|
|
78
|
+
/** Alternative forms accepted when parsing (synonyms, informal variants) */
|
|
79
|
+
readonly alternatives?: readonly string[];
|
|
80
|
+
/** Normalized (English/action) form; defaults to the keyword's action name */
|
|
81
|
+
readonly normalized?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A native→normalized tokenizer keyword mapping, structural mirror of the
|
|
86
|
+
* tokenization layer's `KeywordEntry`.
|
|
87
|
+
*/
|
|
88
|
+
export interface DomainKeywordEntry {
|
|
89
|
+
readonly native: string;
|
|
90
|
+
readonly normalized: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What a domain authors per language — and *only* this. Everything else
|
|
95
|
+
* (word order, markers, particles, script, direction) comes from the injected
|
|
96
|
+
* {@link GrammarProfileSlice}.
|
|
97
|
+
*/
|
|
98
|
+
export interface DomainVocabulary {
|
|
99
|
+
/**
|
|
100
|
+
* Per-action keyword translations for the domain's own verbs,
|
|
101
|
+
* keyed by action name (e.g. `select`, `insert`).
|
|
102
|
+
*/
|
|
103
|
+
readonly keywords: Readonly<Record<string, DomainKeywordTranslation>>;
|
|
104
|
+
/**
|
|
105
|
+
* Extra bare tokenizer keywords beyond the derived set — connectives,
|
|
106
|
+
* literals, and operators-as-words (e.g. `and`, `or`, `null`, `between`).
|
|
107
|
+
*/
|
|
108
|
+
readonly tokenizerKeywords?: readonly string[];
|
|
109
|
+
/**
|
|
110
|
+
* Extra native→normalized entries for the tokenizer's keyword map.
|
|
111
|
+
* These OVERRIDE derived entries with the same native word.
|
|
112
|
+
*/
|
|
113
|
+
readonly keywordExtras?: readonly DomainKeywordEntry[];
|
|
114
|
+
/**
|
|
115
|
+
* Domain-specific role markers for this language, merged over the slice's
|
|
116
|
+
* `roleMarkers` (vocabulary wins). Use for roles the language profile has no
|
|
117
|
+
* marker for (e.g. SQL `condition` → ja `条件`) or where the domain needs a
|
|
118
|
+
* different marker than the language default.
|
|
119
|
+
*/
|
|
120
|
+
readonly roleMarkerOverrides?: Readonly<Record<string, RoleMarkerSlice>>;
|
|
121
|
+
}
|