@lokascript/domain-learn 2.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.
Files changed (44) hide show
  1. package/dist/generators/gloss-generator.d.ts +18 -0
  2. package/dist/generators/learn-renderer.d.ts +13 -0
  3. package/dist/generators/sentence-generator.d.ts +34 -0
  4. package/dist/index.cjs +6116 -0
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.cts +441 -0
  7. package/dist/index.d.ts +55 -0
  8. package/dist/index.js +6056 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/profiles/ar.d.ts +2 -0
  11. package/dist/profiles/de.d.ts +2 -0
  12. package/dist/profiles/en.d.ts +2 -0
  13. package/dist/profiles/es.d.ts +2 -0
  14. package/dist/profiles/fr.d.ts +2 -0
  15. package/dist/profiles/index.d.ts +20 -0
  16. package/dist/profiles/ja.d.ts +2 -0
  17. package/dist/profiles/ko.d.ts +2 -0
  18. package/dist/profiles/pt.d.ts +2 -0
  19. package/dist/profiles/tr.d.ts +2 -0
  20. package/dist/profiles/zh.d.ts +2 -0
  21. package/dist/schemas/index.d.ts +31 -0
  22. package/dist/tokenizers/index.d.ts +23 -0
  23. package/dist/types.d.ts +266 -0
  24. package/package.json +63 -0
  25. package/src/__tests__/schemas.test.ts +145 -0
  26. package/src/__tests__/sentence-generation.test.ts +189 -0
  27. package/src/generators/gloss-generator.ts +145 -0
  28. package/src/generators/learn-renderer.ts +291 -0
  29. package/src/generators/sentence-generator.ts +501 -0
  30. package/src/index.ts +237 -0
  31. package/src/profiles/ar.ts +526 -0
  32. package/src/profiles/de.ts +481 -0
  33. package/src/profiles/en.ts +181 -0
  34. package/src/profiles/es.ts +829 -0
  35. package/src/profiles/fr.ts +466 -0
  36. package/src/profiles/index.ts +34 -0
  37. package/src/profiles/ja.ts +301 -0
  38. package/src/profiles/ko.ts +286 -0
  39. package/src/profiles/pt.ts +484 -0
  40. package/src/profiles/tr.ts +511 -0
  41. package/src/profiles/zh.ts +256 -0
  42. package/src/schemas/index.ts +576 -0
  43. package/src/tokenizers/index.ts +409 -0
  44. package/src/types.ts +321 -0
@@ -0,0 +1,441 @@
1
+ import * as _lokascript_framework from '@lokascript/framework';
2
+ import { PatternGenLanguageProfile, LanguageTokenizer, SemanticNode, CodeGenerator, MultilingualDSL } from '@lokascript/framework';
3
+
4
+ /**
5
+ * Domain-Learn Types
6
+ *
7
+ * Types for the learning domain DSL, extending the framework with
8
+ * communicative functions, morphology tables, and sentence rendering.
9
+ */
10
+ /** The 7 communicative functions that exercises can target */
11
+ type CommunicativeFunction = 'commanding' | 'describing' | 'narrating' | 'questioning' | 'negating' | 'planning' | 'progressing';
12
+ declare const ALL_FUNCTIONS: readonly CommunicativeFunction[];
13
+ /** The 15 core verbs in the learning domain */
14
+ type CoreVerb = 'add' | 'remove' | 'toggle' | 'put' | 'set' | 'show' | 'hide' | 'get' | 'wait' | 'fetch' | 'send' | 'go' | 'increment' | 'decrement' | 'take';
15
+ declare const ALL_VERBS: readonly CoreVerb[];
16
+ type SemanticRole = 'patient' | 'destination' | 'source' | 'instrument' | 'possessive' | 'manner' | 'style';
17
+ type VerbValence = 'intransitive' | 'transitive' | 'ditransitive';
18
+ interface CommandProfile {
19
+ verb: CoreVerb;
20
+ valence: VerbValence;
21
+ targetRole: SemanticRole | null;
22
+ hasPatient: boolean;
23
+ }
24
+ interface SentenceFrame {
25
+ function: CommunicativeFunction;
26
+ template: string;
27
+ verbForm: string;
28
+ example: string;
29
+ }
30
+ interface LanguageFrames {
31
+ code: string;
32
+ wordOrder: 'SVO' | 'SOV' | 'VSO';
33
+ frames: SentenceFrame[];
34
+ }
35
+ interface RenderedSentence {
36
+ language: string;
37
+ function: CommunicativeFunction;
38
+ sentence: string;
39
+ verbForm: string;
40
+ verbValue: string;
41
+ }
42
+ interface InterlinearGloss {
43
+ tokens: string[];
44
+ roles: string[];
45
+ english: string[];
46
+ }
47
+ interface EnglishForms {
48
+ base: string;
49
+ thirdPerson: string;
50
+ past: string;
51
+ pastParticiple: string;
52
+ presentParticiple: string;
53
+ }
54
+ interface JapaneseForms {
55
+ dictionary: string;
56
+ verbClass: 'godan' | 'ichidan' | 'suru' | 'kuru' | 'special';
57
+ stem: string;
58
+ masu: string;
59
+ mashita: string;
60
+ ta: string;
61
+ te: string;
62
+ nai: string;
63
+ masen: string;
64
+ potential: string;
65
+ volitional: string;
66
+ ba: string;
67
+ tara: string;
68
+ }
69
+ interface SpanishPersonForms {
70
+ yo: string;
71
+ tu: string;
72
+ el: string;
73
+ nosotros: string;
74
+ vosotros: string;
75
+ ellos: string;
76
+ }
77
+ interface SpanishForms {
78
+ infinitive: string;
79
+ verbClass: 'ar' | 'er' | 'ir';
80
+ irregular: boolean;
81
+ present: SpanishPersonForms;
82
+ preterite: SpanishPersonForms;
83
+ imperfect: SpanishPersonForms;
84
+ future: SpanishPersonForms;
85
+ imperative: {
86
+ tu: string;
87
+ usted: string;
88
+ ustedes: string;
89
+ };
90
+ gerund: string;
91
+ pastParticiple: {
92
+ ms: string;
93
+ fs: string;
94
+ mp: string;
95
+ fp: string;
96
+ };
97
+ }
98
+ interface ArabicPersonForms {
99
+ howa: string;
100
+ hiya: string;
101
+ anta: string;
102
+ anti: string;
103
+ ana: string;
104
+ hum: string;
105
+ nahnu: string;
106
+ }
107
+ interface ArabicForms {
108
+ root: string;
109
+ form: 'I' | 'II' | 'III' | 'IV' | 'V' | 'VI' | 'VII' | 'VIII' | 'X';
110
+ past: ArabicPersonForms;
111
+ present: ArabicPersonForms;
112
+ imperative: {
113
+ ms: string;
114
+ fs: string;
115
+ mp: string;
116
+ };
117
+ activeParticiple: string;
118
+ passiveParticiple: string;
119
+ masdar: string;
120
+ }
121
+ interface ChineseForms {
122
+ base: string;
123
+ pinyin: string;
124
+ patterns: {
125
+ completed: string;
126
+ experience: string;
127
+ progressive: string;
128
+ future: string;
129
+ negPresent: string;
130
+ negPast: string;
131
+ };
132
+ }
133
+ interface KoreanForms {
134
+ dictionary: string;
135
+ verbClass: 'hada' | 'native' | 'special';
136
+ stem: string;
137
+ hapnida: string;
138
+ haesseumnida: string;
139
+ haeyo: string;
140
+ haesseoyo: string;
141
+ imperative: string;
142
+ past: string;
143
+ negative: string;
144
+ progressive: string;
145
+ future: string;
146
+ }
147
+ interface FrenchPersonForms {
148
+ je: string;
149
+ tu: string;
150
+ il: string;
151
+ nous: string;
152
+ vous: string;
153
+ ils: string;
154
+ }
155
+ interface FrenchForms {
156
+ infinitive: string;
157
+ imperative: {
158
+ tu: string;
159
+ vous: string;
160
+ };
161
+ present: FrenchPersonForms;
162
+ passeCompose: {
163
+ il: string;
164
+ je: string;
165
+ };
166
+ imparfait: {
167
+ il: string;
168
+ };
169
+ futur: {
170
+ il: string;
171
+ };
172
+ gerondif: string;
173
+ }
174
+ interface TurkishForms {
175
+ dictionary: string;
176
+ imperative: {
177
+ sen: string;
178
+ siz: string;
179
+ };
180
+ present: {
181
+ ben: string;
182
+ sen: string;
183
+ o: string;
184
+ biz: string;
185
+ siz: string;
186
+ onlar: string;
187
+ };
188
+ past: {
189
+ o: string;
190
+ ben: string;
191
+ };
192
+ future: {
193
+ o: string;
194
+ };
195
+ negative: {
196
+ o: string;
197
+ };
198
+ progressive: {
199
+ o: string;
200
+ };
201
+ gerund: string;
202
+ }
203
+ interface GermanPersonForms {
204
+ ich: string;
205
+ du: string;
206
+ er: string;
207
+ wir: string;
208
+ ihr: string;
209
+ sie: string;
210
+ }
211
+ interface GermanForms {
212
+ infinitive: string;
213
+ separablePrefix: string;
214
+ imperative: {
215
+ du: string;
216
+ Sie: string;
217
+ };
218
+ present: GermanPersonForms;
219
+ past: {
220
+ ich: string;
221
+ er: string;
222
+ };
223
+ perfect: {
224
+ er: string;
225
+ };
226
+ future: {
227
+ er: string;
228
+ };
229
+ presentParticiple: string;
230
+ }
231
+ interface PortuguesePersonForms {
232
+ eu: string;
233
+ voce: string;
234
+ ele: string;
235
+ nos: string;
236
+ voces: string;
237
+ eles: string;
238
+ }
239
+ interface PortugueseForms {
240
+ infinitive: string;
241
+ imperative: {
242
+ voce: string;
243
+ voces: string;
244
+ };
245
+ present: PortuguesePersonForms;
246
+ preterite: {
247
+ ele: string;
248
+ eu: string;
249
+ };
250
+ imperfect: {
251
+ ele: string;
252
+ };
253
+ future: {
254
+ ele: string;
255
+ };
256
+ gerund: string;
257
+ }
258
+ type AnyForms = EnglishForms | JapaneseForms | SpanishForms | ArabicForms | ChineseForms | KoreanForms | FrenchForms | TurkishForms | GermanForms | PortugueseForms;
259
+
260
+ interface LearnLanguageProfile {
261
+ /** Base framework profile for pattern generation */
262
+ patternProfile: PatternGenLanguageProfile;
263
+ /** Morphology table: verb → conjugation forms */
264
+ morphologyTable: Record<string, AnyForms>;
265
+ /** Sentence frames per communicative function */
266
+ frames: LanguageFrames;
267
+ /** Default sentence subject */
268
+ defaultSubject: string;
269
+ }
270
+
271
+ declare const allSchemas: _lokascript_framework.CommandSchema[];
272
+
273
+ declare const enProfile: LearnLanguageProfile;
274
+
275
+ declare const jaProfile: LearnLanguageProfile;
276
+
277
+ declare const esProfile: LearnLanguageProfile;
278
+
279
+ declare const arProfile: LearnLanguageProfile;
280
+
281
+ declare const zhProfile: LearnLanguageProfile;
282
+
283
+ declare const koProfile: LearnLanguageProfile;
284
+
285
+ declare const frProfile: LearnLanguageProfile;
286
+
287
+ declare const trProfile: LearnLanguageProfile;
288
+
289
+ declare const deProfile: LearnLanguageProfile;
290
+
291
+ declare const ptProfile: LearnLanguageProfile;
292
+
293
+ /**
294
+ * Language Profiles Index
295
+ *
296
+ * Re-exports all 10 language profiles and provides a registry lookup.
297
+ */
298
+
299
+ /** All profiles indexed by language code */
300
+ declare const ALL_PROFILES: Record<string, LearnLanguageProfile>;
301
+
302
+ /**
303
+ * Learn Domain Tokenizers
304
+ *
305
+ * Language-specific tokenizers for learning domain input (10 languages).
306
+ * Created via the framework's createSimpleTokenizer factory.
307
+ *
308
+ * These tokenizers handle:
309
+ * - Command verb keyword classification
310
+ * - Role marker particle/preposition classification
311
+ * - CSS selector recognition (#id, .class)
312
+ * - Non-Latin script handling (Japanese, Arabic, Korean, Chinese)
313
+ */
314
+
315
+ declare const EnglishLearnTokenizer: LanguageTokenizer;
316
+ declare const JapaneseLearnTokenizer: LanguageTokenizer;
317
+ declare const SpanishLearnTokenizer: LanguageTokenizer;
318
+ declare const ArabicLearnTokenizer: LanguageTokenizer;
319
+ declare const ChineseLearnTokenizer: LanguageTokenizer;
320
+ declare const KoreanLearnTokenizer: LanguageTokenizer;
321
+ declare const FrenchLearnTokenizer: LanguageTokenizer;
322
+ declare const TurkishLearnTokenizer: LanguageTokenizer;
323
+ declare const GermanLearnTokenizer: LanguageTokenizer;
324
+ declare const PortugueseLearnTokenizer: LanguageTokenizer;
325
+
326
+ /**
327
+ * Learn Code Generator — The Inverted Generator
328
+ *
329
+ * Unlike domain-sql (natural language → SQL), this generator produces
330
+ * natural language sentences WITH morphology applied as its "compiled output".
331
+ *
332
+ * The standard CodeGenerator.generate() interface returns the commanding form
333
+ * in English. The extended generateForFunction() method produces sentences in
334
+ * any language × communicative function combination.
335
+ */
336
+
337
+ interface ResolvedMarker {
338
+ marker: string;
339
+ position: 'before' | 'after';
340
+ }
341
+ declare function resolveMarker(verb: string, role: string, language: string): ResolvedMarker;
342
+ declare function attachMarker(value: string, resolved: ResolvedMarker): string;
343
+ declare function registerProfile(code: string, profile: LearnLanguageProfile): void;
344
+ declare function getProfile(code: string): LearnLanguageProfile | undefined;
345
+ /**
346
+ * Generate a sentence for a SemanticNode in a specific language and
347
+ * communicative function.
348
+ */
349
+ declare function generateForFunction(node: SemanticNode, fn: CommunicativeFunction, language: string): RenderedSentence | null;
350
+ /**
351
+ * Standard CodeGenerator interface — returns the commanding form in English.
352
+ * This satisfies the framework's CodeGenerator contract.
353
+ */
354
+ declare const learnCodeGenerator: CodeGenerator;
355
+ /** Render across all communicative functions for a language */
356
+ declare function generateAllFunctions(node: SemanticNode, language: string): RenderedSentence[];
357
+ /** Render across all registered languages for a single function */
358
+ declare function generateCrossLingual(node: SemanticNode, fn: CommunicativeFunction): RenderedSentence[];
359
+
360
+ /**
361
+ * Learn Renderer — SemanticNode → DSL text in any language
362
+ *
363
+ * Inverse of the parser: converts a parsed SemanticNode back to
364
+ * natural-language DSL text. Used for cross-language translation
365
+ * exercises and round-trip verification.
366
+ */
367
+
368
+ /**
369
+ * Render a SemanticNode as DSL text in the target language.
370
+ * Produces the commanding form (imperative) of the command.
371
+ */
372
+ declare function renderLearn(node: SemanticNode, language: string): string;
373
+
374
+ /**
375
+ * Gloss Generator — Interlinear Gloss for Learning
376
+ *
377
+ * Produces interlinear glosses from a SemanticNode, showing:
378
+ * tokens: target language tokens ["#buttonに", ".activeを", "追加して"]
379
+ * roles: grammatical labels ["DEST", "PAT", "VERB"]
380
+ * english: English gloss ["to #button", ".active", "add (imperative)"]
381
+ *
382
+ * Glosses help ESL students understand the grammatical function of each
383
+ * word/particle in context, and help code students understand the mapping
384
+ * between natural language and programming operations.
385
+ */
386
+
387
+ /**
388
+ * Generate an interlinear gloss for a SemanticNode.
389
+ */
390
+ declare function generateGloss(node: SemanticNode, fn: CommunicativeFunction, language: string): InterlinearGloss | null;
391
+
392
+ /**
393
+ * @lokascript/domain-learn — Multilingual Learning DSL
394
+ *
395
+ * A learning domain built on @lokascript/framework that formalizes
396
+ * the morphology engine: 15 verbs x 10 languages x 7 communicative
397
+ * functions, with sentence generation, interlinear glosses, and
398
+ * cross-language rendering.
399
+ *
400
+ * Unlike domain-sql (natural language -> SQL), domain-learn's "compiled
401
+ * output" IS natural language sentences with morphology applied. The
402
+ * standard CodeGenerator.generate() returns the commanding form in English.
403
+ * The extended generateForFunction() powers the exercise engine.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * import { createLearnDSL } from '@lokascript/domain-learn';
408
+ *
409
+ * const learn = createLearnDSL();
410
+ *
411
+ * // Parse multilingual command input
412
+ * const node = learn.parse('add .active to #button', 'en');
413
+ *
414
+ * // Generate sentence in any language x function
415
+ * import { generateForFunction } from '@lokascript/domain-learn';
416
+ * generateForFunction(node, 'narrating', 'ja');
417
+ * // -> { sentence: 'システムは #buttonに .activeを 追加しました', ... }
418
+ *
419
+ * // Cross-language translation
420
+ * learn.translate('add .active to #button', 'en', 'ja');
421
+ *
422
+ * // Interlinear gloss
423
+ * import { generateGloss } from '@lokascript/domain-learn';
424
+ * generateGloss(node, 'commanding', 'ja');
425
+ * // -> { tokens: ['#buttonに', '.activeを', '追加して'], roles: ['DEST', 'PAT', 'VERB'], ... }
426
+ * ```
427
+ */
428
+
429
+ /**
430
+ * Create a multilingual learning DSL instance with all 10 supported languages.
431
+ * Also registers all language profiles with the sentence generator.
432
+ */
433
+ declare function createLearnDSL(): MultilingualDSL;
434
+
435
+ declare const learnScanConfig: {
436
+ attributes: readonly ["data-learn", "_learn"];
437
+ scriptTypes: readonly ["text/learn-dsl"];
438
+ defaultLanguage: string;
439
+ };
440
+
441
+ export { ALL_FUNCTIONS, ALL_PROFILES, ALL_VERBS, type AnyForms, type ArabicForms, ArabicLearnTokenizer, type ChineseForms, ChineseLearnTokenizer, type CommandProfile, type CommunicativeFunction, type CoreVerb, type EnglishForms, EnglishLearnTokenizer, type FrenchForms, FrenchLearnTokenizer, type GermanForms, GermanLearnTokenizer, type InterlinearGloss, type JapaneseForms, JapaneseLearnTokenizer, type KoreanForms, KoreanLearnTokenizer, type LanguageFrames, type LearnLanguageProfile, type PortugueseForms, PortugueseLearnTokenizer, type RenderedSentence, type SemanticRole, type SentenceFrame, type SpanishForms, SpanishLearnTokenizer, type TurkishForms, TurkishLearnTokenizer, type VerbValence, allSchemas, arProfile, attachMarker, createLearnDSL, deProfile, enProfile, esProfile, frProfile, generateAllFunctions, generateCrossLingual, generateForFunction, generateGloss, getProfile, jaProfile, koProfile, learnCodeGenerator, learnScanConfig, ptProfile, registerProfile, renderLearn, resolveMarker, trProfile, zhProfile };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @lokascript/domain-learn — Multilingual Learning DSL
3
+ *
4
+ * A learning domain built on @lokascript/framework that formalizes
5
+ * the morphology engine: 15 verbs x 10 languages x 7 communicative
6
+ * functions, with sentence generation, interlinear glosses, and
7
+ * cross-language rendering.
8
+ *
9
+ * Unlike domain-sql (natural language -> SQL), domain-learn's "compiled
10
+ * output" IS natural language sentences with morphology applied. The
11
+ * standard CodeGenerator.generate() returns the commanding form in English.
12
+ * The extended generateForFunction() powers the exercise engine.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createLearnDSL } from '@lokascript/domain-learn';
17
+ *
18
+ * const learn = createLearnDSL();
19
+ *
20
+ * // Parse multilingual command input
21
+ * const node = learn.parse('add .active to #button', 'en');
22
+ *
23
+ * // Generate sentence in any language x function
24
+ * import { generateForFunction } from '@lokascript/domain-learn';
25
+ * generateForFunction(node, 'narrating', 'ja');
26
+ * // -> { sentence: 'システムは #buttonに .activeを 追加しました', ... }
27
+ *
28
+ * // Cross-language translation
29
+ * learn.translate('add .active to #button', 'en', 'ja');
30
+ *
31
+ * // Interlinear gloss
32
+ * import { generateGloss } from '@lokascript/domain-learn';
33
+ * generateGloss(node, 'commanding', 'ja');
34
+ * // -> { tokens: ['#buttonに', '.activeを', '追加して'], roles: ['DEST', 'PAT', 'VERB'], ... }
35
+ * ```
36
+ */
37
+ import { type MultilingualDSL } from '@lokascript/framework';
38
+ /**
39
+ * Create a multilingual learning DSL instance with all 10 supported languages.
40
+ * Also registers all language profiles with the sentence generator.
41
+ */
42
+ export declare function createLearnDSL(): MultilingualDSL;
43
+ export type { CommunicativeFunction, CoreVerb, SemanticRole, VerbValence, CommandProfile, SentenceFrame, LanguageFrames, RenderedSentence, InterlinearGloss, LearnLanguageProfile, EnglishForms, JapaneseForms, SpanishForms, ArabicForms, ChineseForms, KoreanForms, FrenchForms, TurkishForms, GermanForms, PortugueseForms, AnyForms, } from './types';
44
+ export { ALL_FUNCTIONS, ALL_VERBS } from './types';
45
+ export { allSchemas } from './schemas';
46
+ export { ALL_PROFILES, enProfile, jaProfile, esProfile, arProfile, zhProfile, koProfile, frProfile, trProfile, deProfile, ptProfile, } from './profiles';
47
+ export { EnglishLearnTokenizer, JapaneseLearnTokenizer, SpanishLearnTokenizer, ArabicLearnTokenizer, ChineseLearnTokenizer, KoreanLearnTokenizer, FrenchLearnTokenizer, TurkishLearnTokenizer, GermanLearnTokenizer, PortugueseLearnTokenizer, } from './tokenizers';
48
+ export { learnCodeGenerator, generateForFunction, generateAllFunctions, generateCrossLingual, registerProfile, getProfile, resolveMarker, attachMarker, } from './generators/sentence-generator';
49
+ export { renderLearn } from './generators/learn-renderer';
50
+ export { generateGloss } from './generators/gloss-generator';
51
+ export declare const learnScanConfig: {
52
+ attributes: readonly ["data-learn", "_learn"];
53
+ scriptTypes: readonly ["text/learn-dsl"];
54
+ defaultLanguage: string;
55
+ };