@sharpee/if-domain 0.9.60-beta
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/README.md +71 -0
- package/dist/changes.d.ts +8 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +6 -0
- package/dist/changes.js.map +1 -0
- package/dist/contracts.d.ts +270 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +6 -0
- package/dist/contracts.js.map +1 -0
- package/dist/events.d.ts +124 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +123 -0
- package/dist/events.js.map +1 -0
- package/dist/grammar/grammar-builder.d.ts +507 -0
- package/dist/grammar/grammar-builder.d.ts.map +1 -0
- package/dist/grammar/grammar-builder.js +47 -0
- package/dist/grammar/grammar-builder.js.map +1 -0
- package/dist/grammar/grammar-engine.d.ts +65 -0
- package/dist/grammar/grammar-engine.d.ts.map +1 -0
- package/dist/grammar/grammar-engine.js +370 -0
- package/dist/grammar/grammar-engine.js.map +1 -0
- package/dist/grammar/index.d.ts +10 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +26 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/grammar/pattern-compiler.d.ts +38 -0
- package/dist/grammar/pattern-compiler.d.ts.map +1 -0
- package/dist/grammar/pattern-compiler.js +22 -0
- package/dist/grammar/pattern-compiler.js.map +1 -0
- package/dist/grammar/scope-builder.d.ts +26 -0
- package/dist/grammar/scope-builder.d.ts.map +1 -0
- package/dist/grammar/scope-builder.js +67 -0
- package/dist/grammar/scope-builder.js.map +1 -0
- package/dist/grammar/vocabulary-provider.d.ts +163 -0
- package/dist/grammar/vocabulary-provider.d.ts.map +1 -0
- package/dist/grammar/vocabulary-provider.js +89 -0
- package/dist/grammar/vocabulary-provider.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/language-provider.d.ts +106 -0
- package/dist/language-provider.d.ts.map +1 -0
- package/dist/language-provider.js +14 -0
- package/dist/language-provider.js.map +1 -0
- package/dist/parser-contracts/index.d.ts +10 -0
- package/dist/parser-contracts/index.d.ts.map +1 -0
- package/dist/parser-contracts/index.js +26 -0
- package/dist/parser-contracts/index.js.map +1 -0
- package/dist/parser-contracts/parser-factory.d.ts +46 -0
- package/dist/parser-contracts/parser-factory.d.ts.map +1 -0
- package/dist/parser-contracts/parser-factory.js +78 -0
- package/dist/parser-contracts/parser-factory.js.map +1 -0
- package/dist/parser-contracts/parser-internals.d.ts +125 -0
- package/dist/parser-contracts/parser-internals.d.ts.map +1 -0
- package/dist/parser-contracts/parser-internals.js +26 -0
- package/dist/parser-contracts/parser-internals.js.map +1 -0
- package/dist/parser-contracts/parser-types.d.ts +128 -0
- package/dist/parser-contracts/parser-types.d.ts.map +1 -0
- package/dist/parser-contracts/parser-types.js +9 -0
- package/dist/parser-contracts/parser-types.js.map +1 -0
- package/dist/parser-language-provider.d.ts +158 -0
- package/dist/parser-language-provider.d.ts.map +1 -0
- package/dist/parser-language-provider.js +10 -0
- package/dist/parser-language-provider.js.map +1 -0
- package/dist/sequencing.d.ts +53 -0
- package/dist/sequencing.d.ts.map +1 -0
- package/dist/sequencing.js +6 -0
- package/dist/sequencing.js.map +1 -0
- package/dist/vocabulary-contracts/index.d.ts +7 -0
- package/dist/vocabulary-contracts/index.d.ts.map +1 -0
- package/dist/vocabulary-contracts/index.js +23 -0
- package/dist/vocabulary-contracts/index.js.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.d.ts +19 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.d.ts.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.js +73 -0
- package/dist/vocabulary-contracts/vocabulary-adapters.js.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-registry.d.ts +98 -0
- package/dist/vocabulary-contracts/vocabulary-registry.d.ts.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-registry.js +383 -0
- package/dist/vocabulary-contracts/vocabulary-registry.js.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-types.d.ts +240 -0
- package/dist/vocabulary-contracts/vocabulary-types.d.ts.map +1 -0
- package/dist/vocabulary-contracts/vocabulary-types.js +64 -0
- package/dist/vocabulary-contracts/vocabulary-types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Grammar Builder Interfaces
|
|
3
|
+
* @description Language-agnostic interfaces for defining grammar rules
|
|
4
|
+
*/
|
|
5
|
+
import { IEntity } from '@sharpee/core';
|
|
6
|
+
/**
|
|
7
|
+
* Slot types for grammar patterns
|
|
8
|
+
* Controls how the parser handles slot matching
|
|
9
|
+
*/
|
|
10
|
+
export declare enum SlotType {
|
|
11
|
+
/** Default: resolve slot text to an entity via vocabulary lookup */
|
|
12
|
+
ENTITY = "entity",
|
|
13
|
+
/** Capture raw text without entity resolution (single token) */
|
|
14
|
+
TEXT = "text",
|
|
15
|
+
/** Capture raw text until next pattern element or end (greedy) */
|
|
16
|
+
TEXT_GREEDY = "text_greedy",
|
|
17
|
+
/** Resolve entity but mark as instrument for the action */
|
|
18
|
+
INSTRUMENT = "instrument",
|
|
19
|
+
/** Match cardinal/ordinal direction (n, s, e, w, ne, up, down, etc.) */
|
|
20
|
+
DIRECTION = "direction",
|
|
21
|
+
/** Match integer (digits or words: 1, 29, one, twenty) */
|
|
22
|
+
NUMBER = "number",
|
|
23
|
+
/** Match ordinal (1st, first, 2nd, second, etc.) */
|
|
24
|
+
ORDINAL = "ordinal",
|
|
25
|
+
/** Match time expression (10:40, 6:00) */
|
|
26
|
+
TIME = "time",
|
|
27
|
+
/** Match manner adverb (carefully, quickly, forcefully) - feeds intention.manner */
|
|
28
|
+
MANNER = "manner",
|
|
29
|
+
/** Match text enclosed in double quotes */
|
|
30
|
+
QUOTED_TEXT = "quoted_text",
|
|
31
|
+
/** Match conversation topic (one or more words) */
|
|
32
|
+
TOPIC = "topic",
|
|
33
|
+
/** Match word from a story-defined vocabulary category */
|
|
34
|
+
VOCABULARY = "vocabulary",
|
|
35
|
+
/** @deprecated Use VOCABULARY with .fromVocabulary() instead */
|
|
36
|
+
ADJECTIVE = "adjective",
|
|
37
|
+
/** @deprecated Use VOCABULARY with .fromVocabulary() instead */
|
|
38
|
+
NOUN = "noun"
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Constraint types for slot matching
|
|
42
|
+
*/
|
|
43
|
+
export type PropertyConstraint = Record<string, any>;
|
|
44
|
+
export type FunctionConstraint = (entity: IEntity, context: GrammarContext) => boolean;
|
|
45
|
+
export type ScopeConstraintBuilder = (scope: ScopeBuilder) => ScopeBuilder;
|
|
46
|
+
export type Constraint = PropertyConstraint | FunctionConstraint | ScopeConstraintBuilder;
|
|
47
|
+
/**
|
|
48
|
+
* Context provided to constraint functions
|
|
49
|
+
*/
|
|
50
|
+
export interface GrammarContext {
|
|
51
|
+
world: any;
|
|
52
|
+
actorId: string;
|
|
53
|
+
actionId?: string;
|
|
54
|
+
currentLocation: string;
|
|
55
|
+
slots: Map<string, IEntity[]>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scope builder for constraint definitions
|
|
59
|
+
*/
|
|
60
|
+
export interface ScopeBuilder {
|
|
61
|
+
visible(): ScopeBuilder;
|
|
62
|
+
touchable(): ScopeBuilder;
|
|
63
|
+
carried(): ScopeBuilder;
|
|
64
|
+
nearby(): ScopeBuilder;
|
|
65
|
+
matching(constraint: PropertyConstraint | FunctionConstraint): ScopeBuilder;
|
|
66
|
+
kind(kind: string): ScopeBuilder;
|
|
67
|
+
orExplicitly(entityIds: string[]): ScopeBuilder;
|
|
68
|
+
orRule(ruleId: string): ScopeBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Require the entity to have a specific trait
|
|
71
|
+
* @param traitType The trait type constant (e.g., TraitType.PORTABLE)
|
|
72
|
+
*/
|
|
73
|
+
hasTrait(traitType: string): ScopeBuilder;
|
|
74
|
+
build(): ScopeConstraint;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Internal scope constraint representation
|
|
78
|
+
*/
|
|
79
|
+
export interface ScopeConstraint {
|
|
80
|
+
base: 'visible' | 'touchable' | 'carried' | 'nearby' | 'all';
|
|
81
|
+
filters: Array<PropertyConstraint | FunctionConstraint>;
|
|
82
|
+
/** Required trait types the entity must have */
|
|
83
|
+
traitFilters: string[];
|
|
84
|
+
explicitEntities: string[];
|
|
85
|
+
includeRules: string[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* ADR-082: Typed slot value for non-entity slots
|
|
89
|
+
* Each variant carries the parsed/typed value from the input
|
|
90
|
+
*/
|
|
91
|
+
export type TypedSlotValue = {
|
|
92
|
+
type: 'direction';
|
|
93
|
+
direction: string;
|
|
94
|
+
canonical: string;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'number';
|
|
97
|
+
value: number;
|
|
98
|
+
word: string;
|
|
99
|
+
} | {
|
|
100
|
+
type: 'ordinal';
|
|
101
|
+
value: number;
|
|
102
|
+
word: string;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'time';
|
|
105
|
+
hours: number;
|
|
106
|
+
minutes: number;
|
|
107
|
+
text: string;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'manner';
|
|
110
|
+
word: string;
|
|
111
|
+
} | {
|
|
112
|
+
type: 'quoted_text';
|
|
113
|
+
text: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'topic';
|
|
116
|
+
words: string[];
|
|
117
|
+
} | {
|
|
118
|
+
type: 'vocabulary';
|
|
119
|
+
word: string;
|
|
120
|
+
category: string;
|
|
121
|
+
} | {
|
|
122
|
+
type: 'adjective';
|
|
123
|
+
word: string;
|
|
124
|
+
} | {
|
|
125
|
+
type: 'noun';
|
|
126
|
+
word: string;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Pattern builder for defining grammar rules
|
|
130
|
+
*/
|
|
131
|
+
export interface PatternBuilder {
|
|
132
|
+
/**
|
|
133
|
+
* Require a slot's entity to have a specific trait
|
|
134
|
+
* This is the primary method for semantic constraints in grammar.
|
|
135
|
+
* @param slot The slot name from the pattern
|
|
136
|
+
* @param traitType The trait type constant (e.g., TraitType.CONTAINER)
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* grammar.define('board :target')
|
|
141
|
+
* .hasTrait('target', TraitType.ENTERABLE)
|
|
142
|
+
* .mapsTo('if.action.entering')
|
|
143
|
+
* .build();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
hasTrait(slot: string, traitType: string): PatternBuilder;
|
|
147
|
+
/**
|
|
148
|
+
* Define a constraint for a slot (advanced use)
|
|
149
|
+
* Prefer .hasTrait() for trait-based constraints.
|
|
150
|
+
* @param slot The slot name from the pattern
|
|
151
|
+
* @param constraint The constraint to apply
|
|
152
|
+
*/
|
|
153
|
+
where(slot: string, constraint: Constraint): PatternBuilder;
|
|
154
|
+
/**
|
|
155
|
+
* Mark a slot as capturing raw text (single token) instead of resolving to entity
|
|
156
|
+
* For greedy text capture, use :slot... syntax in the pattern
|
|
157
|
+
* @param slot The slot name from the pattern
|
|
158
|
+
*/
|
|
159
|
+
text(slot: string): PatternBuilder;
|
|
160
|
+
/**
|
|
161
|
+
* Mark a slot as an instrument for the action
|
|
162
|
+
* The slot will still resolve to an entity, but be stored in command.instrument
|
|
163
|
+
* @param slot The slot name from the pattern
|
|
164
|
+
*/
|
|
165
|
+
instrument(slot: string): PatternBuilder;
|
|
166
|
+
/**
|
|
167
|
+
* Map this pattern to an action
|
|
168
|
+
* @param action The action identifier
|
|
169
|
+
*/
|
|
170
|
+
mapsTo(action: string): PatternBuilder;
|
|
171
|
+
/**
|
|
172
|
+
* Set the priority for this pattern (higher = preferred)
|
|
173
|
+
* @param priority The priority value
|
|
174
|
+
*/
|
|
175
|
+
withPriority(priority: number): PatternBuilder;
|
|
176
|
+
/**
|
|
177
|
+
* Add semantic mappings for verbs
|
|
178
|
+
* @param verbs Map of verb text to semantic properties
|
|
179
|
+
*/
|
|
180
|
+
withSemanticVerbs(verbs: Record<string, Partial<SemanticProperties>>): PatternBuilder;
|
|
181
|
+
/**
|
|
182
|
+
* Add semantic mappings for prepositions
|
|
183
|
+
* @param prepositions Map of preposition text to spatial relations
|
|
184
|
+
*/
|
|
185
|
+
withSemanticPrepositions(prepositions: Record<string, string>): PatternBuilder;
|
|
186
|
+
/**
|
|
187
|
+
* Add semantic mappings for directions
|
|
188
|
+
* @param directions Map of direction text to normalized directions
|
|
189
|
+
*/
|
|
190
|
+
withSemanticDirections(directions: Record<string, string>): PatternBuilder;
|
|
191
|
+
/**
|
|
192
|
+
* Set default semantic properties
|
|
193
|
+
* @param defaults Default semantic properties
|
|
194
|
+
*/
|
|
195
|
+
withDefaultSemantics(defaults: Partial<SemanticProperties>): PatternBuilder;
|
|
196
|
+
/**
|
|
197
|
+
* Mark a slot as a number (integer)
|
|
198
|
+
* Matches digits (1, 29, 100) or words (one, twenty)
|
|
199
|
+
* @param slot The slot name from the pattern
|
|
200
|
+
*/
|
|
201
|
+
number(slot: string): PatternBuilder;
|
|
202
|
+
/**
|
|
203
|
+
* Mark a slot as an ordinal
|
|
204
|
+
* Matches ordinal words (first, second) or suffixed numbers (1st, 2nd)
|
|
205
|
+
* @param slot The slot name from the pattern
|
|
206
|
+
*/
|
|
207
|
+
ordinal(slot: string): PatternBuilder;
|
|
208
|
+
/**
|
|
209
|
+
* Mark a slot as a time expression
|
|
210
|
+
* Matches HH:MM format (10:40, 6:00)
|
|
211
|
+
* @param slot The slot name from the pattern
|
|
212
|
+
*/
|
|
213
|
+
time(slot: string): PatternBuilder;
|
|
214
|
+
/**
|
|
215
|
+
* Mark a slot as a direction
|
|
216
|
+
* Matches built-in direction vocabulary (n, north, up, etc.)
|
|
217
|
+
* @param slot The slot name from the pattern
|
|
218
|
+
*/
|
|
219
|
+
direction(slot: string): PatternBuilder;
|
|
220
|
+
/**
|
|
221
|
+
* Mark a slot as a manner adverb
|
|
222
|
+
* Matches built-in manner vocabulary (carefully, quickly, forcefully, etc.)
|
|
223
|
+
* The matched word is stored in command.intention.manner
|
|
224
|
+
* @param slot The slot name from the pattern
|
|
225
|
+
*/
|
|
226
|
+
manner(slot: string): PatternBuilder;
|
|
227
|
+
/**
|
|
228
|
+
* Mark a slot as matching a story-defined vocabulary category
|
|
229
|
+
* The category must be registered via world.getVocabularyProvider().define()
|
|
230
|
+
*
|
|
231
|
+
* @param slot The slot name from the pattern
|
|
232
|
+
* @param category The vocabulary category name
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Register vocabulary
|
|
237
|
+
* vocab.define('panel-colors', {
|
|
238
|
+
* words: ['red', 'yellow', 'mahogany', 'pine'],
|
|
239
|
+
* when: (ctx) => ctx.currentLocation === insideMirrorId
|
|
240
|
+
* });
|
|
241
|
+
*
|
|
242
|
+
* // Use in grammar
|
|
243
|
+
* grammar
|
|
244
|
+
* .define('push :color panel')
|
|
245
|
+
* .fromVocabulary('color', 'panel-colors')
|
|
246
|
+
* .mapsTo('push_panel')
|
|
247
|
+
* .build();
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
fromVocabulary(slot: string, category: string): PatternBuilder;
|
|
251
|
+
/**
|
|
252
|
+
* @deprecated Use fromVocabulary() with a named category instead
|
|
253
|
+
* Mark a slot as an adjective from story vocabulary
|
|
254
|
+
*/
|
|
255
|
+
adjective(slot: string): PatternBuilder;
|
|
256
|
+
/**
|
|
257
|
+
* @deprecated Use fromVocabulary() with a named category instead
|
|
258
|
+
* Mark a slot as a noun from story vocabulary
|
|
259
|
+
*/
|
|
260
|
+
noun(slot: string): PatternBuilder;
|
|
261
|
+
/**
|
|
262
|
+
* Mark a slot as quoted text
|
|
263
|
+
* Matches text enclosed in double quotes
|
|
264
|
+
* @param slot The slot name from the pattern
|
|
265
|
+
*/
|
|
266
|
+
quotedText(slot: string): PatternBuilder;
|
|
267
|
+
/**
|
|
268
|
+
* Mark a slot as a conversation topic
|
|
269
|
+
* Consumes one or more words as a topic
|
|
270
|
+
* @param slot The slot name from the pattern
|
|
271
|
+
*/
|
|
272
|
+
topic(slot: string): PatternBuilder;
|
|
273
|
+
/**
|
|
274
|
+
* Build the final grammar rule
|
|
275
|
+
*/
|
|
276
|
+
build(): GrammarRule;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Main grammar builder interface
|
|
280
|
+
*/
|
|
281
|
+
export interface GrammarBuilder {
|
|
282
|
+
/**
|
|
283
|
+
* Define a new grammar pattern
|
|
284
|
+
* @param pattern The pattern string (e.g., "put :item in|into :container")
|
|
285
|
+
*/
|
|
286
|
+
define(pattern: string): PatternBuilder;
|
|
287
|
+
/**
|
|
288
|
+
* ADR-087: Define grammar patterns for an action with verb aliases
|
|
289
|
+
* @param actionId The action identifier to map patterns to
|
|
290
|
+
* @returns An ActionGrammarBuilder for fluent configuration
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* grammar
|
|
295
|
+
* .forAction('if.action.pushing')
|
|
296
|
+
* .verbs(['push', 'press', 'shove', 'move'])
|
|
297
|
+
* .pattern(':target')
|
|
298
|
+
* .where('target', scope => scope.touchable())
|
|
299
|
+
* .build();
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
forAction(actionId: string): ActionGrammarBuilder;
|
|
303
|
+
/**
|
|
304
|
+
* Get all defined rules
|
|
305
|
+
*/
|
|
306
|
+
getRules(): GrammarRule[];
|
|
307
|
+
/**
|
|
308
|
+
* Clear all rules
|
|
309
|
+
*/
|
|
310
|
+
clear(): void;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* ADR-087: Action-centric grammar builder
|
|
314
|
+
* Allows defining multiple patterns for an action with verb aliases
|
|
315
|
+
*/
|
|
316
|
+
export interface ActionGrammarBuilder {
|
|
317
|
+
/**
|
|
318
|
+
* Define verb aliases for this action
|
|
319
|
+
* Each verb will generate a separate pattern
|
|
320
|
+
* @param verbs Array of verb strings (e.g., ['push', 'press', 'shove'])
|
|
321
|
+
*/
|
|
322
|
+
verbs(verbs: string[]): ActionGrammarBuilder;
|
|
323
|
+
/**
|
|
324
|
+
* Define a pattern template (without verb)
|
|
325
|
+
* Will be combined with each verb to create full patterns
|
|
326
|
+
* @param pattern Pattern template (e.g., ':target' becomes 'push :target', 'press :target', etc.)
|
|
327
|
+
*/
|
|
328
|
+
pattern(pattern: string): ActionGrammarBuilder;
|
|
329
|
+
/**
|
|
330
|
+
* Define multiple pattern templates
|
|
331
|
+
* Each pattern will be combined with each verb
|
|
332
|
+
* @param patterns Array of pattern templates
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* grammar
|
|
337
|
+
* .forAction('if.action.pushing')
|
|
338
|
+
* .verbs(['push', 'press'])
|
|
339
|
+
* .patterns([':target', ':target :direction'])
|
|
340
|
+
* .build();
|
|
341
|
+
* // Generates: push :target, press :target, push :target :direction, press :target :direction
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
patterns(patterns: string[]): ActionGrammarBuilder;
|
|
345
|
+
/**
|
|
346
|
+
* Define direction patterns with aliases
|
|
347
|
+
* Creates standalone direction patterns (no verb prefix)
|
|
348
|
+
* @param directionMap Map of canonical direction to aliases
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```typescript
|
|
352
|
+
* grammar
|
|
353
|
+
* .forAction('if.action.going')
|
|
354
|
+
* .directions({
|
|
355
|
+
* 'north': ['north', 'n'],
|
|
356
|
+
* 'south': ['south', 's'],
|
|
357
|
+
* })
|
|
358
|
+
* .build();
|
|
359
|
+
* // Generates patterns 'north', 'n', 'south', 's' each with direction semantics
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
directions(directionMap: Record<string, string[]>): ActionGrammarBuilder;
|
|
363
|
+
/**
|
|
364
|
+
* Require a slot's entity to have a specific trait (applies to all generated patterns)
|
|
365
|
+
* This is the primary method for semantic constraints in grammar.
|
|
366
|
+
* @param slot The slot name from the pattern
|
|
367
|
+
* @param traitType The trait type constant (e.g., TraitType.CONTAINER)
|
|
368
|
+
*/
|
|
369
|
+
hasTrait(slot: string, traitType: string): ActionGrammarBuilder;
|
|
370
|
+
/**
|
|
371
|
+
* Define a constraint for a slot (applies to all generated patterns)
|
|
372
|
+
* Prefer .hasTrait() for trait-based constraints.
|
|
373
|
+
* @param slot The slot name from the pattern
|
|
374
|
+
* @param constraint The constraint to apply
|
|
375
|
+
*/
|
|
376
|
+
where(slot: string, constraint: Constraint): ActionGrammarBuilder;
|
|
377
|
+
/**
|
|
378
|
+
* Set priority for all generated patterns
|
|
379
|
+
* @param priority The priority value (higher = preferred)
|
|
380
|
+
*/
|
|
381
|
+
withPriority(priority: number): ActionGrammarBuilder;
|
|
382
|
+
/**
|
|
383
|
+
* Set default semantic properties for all generated patterns
|
|
384
|
+
* @param defaults Default semantic properties
|
|
385
|
+
*/
|
|
386
|
+
withDefaultSemantics(defaults: Partial<SemanticProperties>): ActionGrammarBuilder;
|
|
387
|
+
/**
|
|
388
|
+
* Mark a slot as a specific type (applies to all generated patterns)
|
|
389
|
+
* @param slot The slot name
|
|
390
|
+
* @param slotType The slot type
|
|
391
|
+
*/
|
|
392
|
+
slotType(slot: string, slotType: SlotType): ActionGrammarBuilder;
|
|
393
|
+
/**
|
|
394
|
+
* Build all patterns and add them to the grammar
|
|
395
|
+
* Generates patterns from: verbs × patterns combinations
|
|
396
|
+
*/
|
|
397
|
+
build(): void;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* A compiled grammar rule
|
|
401
|
+
*/
|
|
402
|
+
export interface GrammarRule {
|
|
403
|
+
id: string;
|
|
404
|
+
pattern: string;
|
|
405
|
+
compiledPattern?: CompiledPattern;
|
|
406
|
+
slots: Map<string, SlotConstraint>;
|
|
407
|
+
action: string;
|
|
408
|
+
priority: number;
|
|
409
|
+
semantics?: SemanticMapping;
|
|
410
|
+
defaultSemantics?: Partial<SemanticProperties>;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Semantic properties that can be derived from grammar
|
|
414
|
+
*/
|
|
415
|
+
export interface SemanticProperties {
|
|
416
|
+
/** How an action is performed */
|
|
417
|
+
manner?: 'normal' | 'careful' | 'careless' | 'forceful' | 'stealthy' | 'quick';
|
|
418
|
+
/** Spatial relationship for placement actions */
|
|
419
|
+
spatialRelation?: 'in' | 'on' | 'under' | 'behind' | 'beside' | 'above' | 'below';
|
|
420
|
+
/** Direction for movement */
|
|
421
|
+
direction?: 'north' | 'south' | 'east' | 'west' | 'up' | 'down' | 'northeast' | 'northwest' | 'southeast' | 'southwest' | 'in' | 'out';
|
|
422
|
+
/** Whether the preposition was implicit */
|
|
423
|
+
implicitPreposition?: boolean;
|
|
424
|
+
/** Whether a direction was implicit */
|
|
425
|
+
implicitDirection?: boolean;
|
|
426
|
+
/** Custom properties for specific actions */
|
|
427
|
+
[key: string]: any;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Mapping from text variations to semantic properties
|
|
431
|
+
*/
|
|
432
|
+
export interface SemanticMapping {
|
|
433
|
+
/** Map verb variations to properties */
|
|
434
|
+
verbs?: Record<string, Partial<SemanticProperties>>;
|
|
435
|
+
/** Map preposition variations to spatial relations */
|
|
436
|
+
prepositions?: Record<string, string>;
|
|
437
|
+
/** Map direction variations to normalized directions */
|
|
438
|
+
directions?: Record<string, string>;
|
|
439
|
+
/** Function to compute dynamic semantics based on match */
|
|
440
|
+
compute?: (match: any) => Partial<SemanticProperties>;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Slot constraint definition
|
|
444
|
+
*/
|
|
445
|
+
export interface SlotConstraint {
|
|
446
|
+
name: string;
|
|
447
|
+
constraints: Constraint[];
|
|
448
|
+
/** Required trait types the entity must have (from .hasTrait()) */
|
|
449
|
+
traitFilters?: string[];
|
|
450
|
+
/** How the parser should handle this slot (default: ENTITY) */
|
|
451
|
+
slotType?: SlotType;
|
|
452
|
+
/** For VOCABULARY slots: the category name to match against */
|
|
453
|
+
vocabularyCategory?: string;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Token in a pattern
|
|
457
|
+
*/
|
|
458
|
+
export interface PatternToken {
|
|
459
|
+
type: 'literal' | 'slot' | 'alternates';
|
|
460
|
+
value: string;
|
|
461
|
+
alternates?: string[];
|
|
462
|
+
optional?: boolean;
|
|
463
|
+
slotType?: SlotType;
|
|
464
|
+
greedy?: boolean;
|
|
465
|
+
vocabularyCategory?: string;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Compiled pattern for efficient matching
|
|
469
|
+
*/
|
|
470
|
+
export interface CompiledPattern {
|
|
471
|
+
tokens: PatternToken[];
|
|
472
|
+
slots: Map<string, number>;
|
|
473
|
+
minTokens: number;
|
|
474
|
+
maxTokens: number;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Slot match data with multi-object support
|
|
478
|
+
*/
|
|
479
|
+
export interface SlotMatch {
|
|
480
|
+
tokens: number[];
|
|
481
|
+
text: string;
|
|
482
|
+
slotType?: SlotType;
|
|
483
|
+
confidence?: number;
|
|
484
|
+
isAll?: boolean;
|
|
485
|
+
isList?: boolean;
|
|
486
|
+
items?: SlotMatch[];
|
|
487
|
+
excluded?: SlotMatch[];
|
|
488
|
+
category?: string;
|
|
489
|
+
matchedWord?: string;
|
|
490
|
+
manner?: string;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Result of pattern matching
|
|
494
|
+
*/
|
|
495
|
+
export interface PatternMatch {
|
|
496
|
+
rule: GrammarRule;
|
|
497
|
+
confidence: number;
|
|
498
|
+
slots: Map<string, SlotMatch>;
|
|
499
|
+
consumed: number;
|
|
500
|
+
semantics?: SemanticProperties;
|
|
501
|
+
matchedTokens?: {
|
|
502
|
+
verb?: string;
|
|
503
|
+
preposition?: string;
|
|
504
|
+
direction?: string;
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
//# sourceMappingURL=grammar-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar-builder.d.ts","sourceRoot":"","sources":["../../src/grammar/grammar-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;;GAGG;AACH,oBAAY,QAAQ;IAClB,oEAAoE;IACpE,MAAM,WAAW;IACjB,gEAAgE;IAChE,IAAI,SAAS;IACb,kEAAkE;IAClE,WAAW,gBAAgB;IAC3B,2DAA2D;IAC3D,UAAU,eAAe;IAGzB,wEAAwE;IACxE,SAAS,cAAc;IACvB,0DAA0D;IAC1D,MAAM,WAAW;IACjB,oDAAoD;IACpD,OAAO,YAAY;IACnB,0CAA0C;IAC1C,IAAI,SAAS;IACb,oFAAoF;IACpF,MAAM,WAAW;IAGjB,2CAA2C;IAC3C,WAAW,gBAAgB;IAC3B,mDAAmD;IACnD,KAAK,UAAU;IAGf,0DAA0D;IAC1D,UAAU,eAAe;IAGzB,gEAAgE;IAChE,SAAS,cAAc;IACvB,gEAAgE;IAChE,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACrD,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC;AACvF,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,CAAC;AAE3E,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,sBAAsB,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,GAAG,CAA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E,CAAC;IAEvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,aAAa,CAAC,EAAE;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Grammar Builder Interfaces
|
|
4
|
+
* @description Language-agnostic interfaces for defining grammar rules
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SlotType = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Slot types for grammar patterns
|
|
10
|
+
* Controls how the parser handles slot matching
|
|
11
|
+
*/
|
|
12
|
+
var SlotType;
|
|
13
|
+
(function (SlotType) {
|
|
14
|
+
/** Default: resolve slot text to an entity via vocabulary lookup */
|
|
15
|
+
SlotType["ENTITY"] = "entity";
|
|
16
|
+
/** Capture raw text without entity resolution (single token) */
|
|
17
|
+
SlotType["TEXT"] = "text";
|
|
18
|
+
/** Capture raw text until next pattern element or end (greedy) */
|
|
19
|
+
SlotType["TEXT_GREEDY"] = "text_greedy";
|
|
20
|
+
/** Resolve entity but mark as instrument for the action */
|
|
21
|
+
SlotType["INSTRUMENT"] = "instrument";
|
|
22
|
+
// ADR-082: Built-in typed value slots
|
|
23
|
+
/** Match cardinal/ordinal direction (n, s, e, w, ne, up, down, etc.) */
|
|
24
|
+
SlotType["DIRECTION"] = "direction";
|
|
25
|
+
/** Match integer (digits or words: 1, 29, one, twenty) */
|
|
26
|
+
SlotType["NUMBER"] = "number";
|
|
27
|
+
/** Match ordinal (1st, first, 2nd, second, etc.) */
|
|
28
|
+
SlotType["ORDINAL"] = "ordinal";
|
|
29
|
+
/** Match time expression (10:40, 6:00) */
|
|
30
|
+
SlotType["TIME"] = "time";
|
|
31
|
+
/** Match manner adverb (carefully, quickly, forcefully) - feeds intention.manner */
|
|
32
|
+
SlotType["MANNER"] = "manner";
|
|
33
|
+
// ADR-082: Text variant slots
|
|
34
|
+
/** Match text enclosed in double quotes */
|
|
35
|
+
SlotType["QUOTED_TEXT"] = "quoted_text";
|
|
36
|
+
/** Match conversation topic (one or more words) */
|
|
37
|
+
SlotType["TOPIC"] = "topic";
|
|
38
|
+
// ADR-082: Category-based vocabulary slots
|
|
39
|
+
/** Match word from a story-defined vocabulary category */
|
|
40
|
+
SlotType["VOCABULARY"] = "vocabulary";
|
|
41
|
+
// Deprecated: Use VOCABULARY with named categories instead
|
|
42
|
+
/** @deprecated Use VOCABULARY with .fromVocabulary() instead */
|
|
43
|
+
SlotType["ADJECTIVE"] = "adjective";
|
|
44
|
+
/** @deprecated Use VOCABULARY with .fromVocabulary() instead */
|
|
45
|
+
SlotType["NOUN"] = "noun";
|
|
46
|
+
})(SlotType || (exports.SlotType = SlotType = {}));
|
|
47
|
+
//# sourceMappingURL=grammar-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar-builder.js","sourceRoot":"","sources":["../../src/grammar/grammar-builder.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH;;;GAGG;AACH,IAAY,QAqCX;AArCD,WAAY,QAAQ;IAClB,oEAAoE;IACpE,6BAAiB,CAAA;IACjB,gEAAgE;IAChE,yBAAa,CAAA;IACb,kEAAkE;IAClE,uCAA2B,CAAA;IAC3B,2DAA2D;IAC3D,qCAAyB,CAAA;IAEzB,sCAAsC;IACtC,wEAAwE;IACxE,mCAAuB,CAAA;IACvB,0DAA0D;IAC1D,6BAAiB,CAAA;IACjB,oDAAoD;IACpD,+BAAmB,CAAA;IACnB,0CAA0C;IAC1C,yBAAa,CAAA;IACb,oFAAoF;IACpF,6BAAiB,CAAA;IAEjB,8BAA8B;IAC9B,2CAA2C;IAC3C,uCAA2B,CAAA;IAC3B,mDAAmD;IACnD,2BAAe,CAAA;IAEf,2CAA2C;IAC3C,0DAA0D;IAC1D,qCAAyB,CAAA;IAEzB,2DAA2D;IAC3D,gEAAgE;IAChE,mCAAuB,CAAA;IACvB,gEAAgE;IAChE,yBAAa,CAAA;AACf,CAAC,EArCW,QAAQ,wBAAR,QAAQ,QAqCnB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Grammar Engine Base
|
|
3
|
+
* @description Abstract base class for grammar matching engines
|
|
4
|
+
*/
|
|
5
|
+
import { Token } from '../parser-contracts/parser-types';
|
|
6
|
+
import { GrammarRule, PatternMatch, GrammarContext, GrammarBuilder } from './grammar-builder';
|
|
7
|
+
import { PatternCompiler } from './pattern-compiler';
|
|
8
|
+
/**
|
|
9
|
+
* Grammar matching options
|
|
10
|
+
*/
|
|
11
|
+
export interface GrammarMatchOptions {
|
|
12
|
+
/** Minimum confidence threshold */
|
|
13
|
+
minConfidence?: number;
|
|
14
|
+
/** Maximum number of matches to return */
|
|
15
|
+
maxMatches?: number;
|
|
16
|
+
/** Whether to allow partial matches */
|
|
17
|
+
allowPartial?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Abstract base class for grammar engines
|
|
21
|
+
* Language-specific implementations provide concrete matching logic
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class GrammarEngine {
|
|
24
|
+
protected rules: GrammarRule[];
|
|
25
|
+
protected rulesByAction: Map<string, GrammarRule[]>;
|
|
26
|
+
protected compiler: PatternCompiler;
|
|
27
|
+
constructor(compiler: PatternCompiler);
|
|
28
|
+
/**
|
|
29
|
+
* Add a grammar rule
|
|
30
|
+
*/
|
|
31
|
+
addRule(rule: GrammarRule): void;
|
|
32
|
+
/**
|
|
33
|
+
* Add multiple rules
|
|
34
|
+
*/
|
|
35
|
+
addRules(rules: GrammarRule[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Find matching grammar rules for tokens
|
|
38
|
+
*/
|
|
39
|
+
abstract findMatches(tokens: Token[], context: GrammarContext, options?: GrammarMatchOptions): PatternMatch[];
|
|
40
|
+
/**
|
|
41
|
+
* Get the best match from a set of tokens
|
|
42
|
+
*/
|
|
43
|
+
getBestMatch(tokens: Token[], context: GrammarContext, options?: GrammarMatchOptions): PatternMatch | null;
|
|
44
|
+
/**
|
|
45
|
+
* Clear all rules
|
|
46
|
+
*/
|
|
47
|
+
clear(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get all rules
|
|
50
|
+
*/
|
|
51
|
+
getRules(): GrammarRule[];
|
|
52
|
+
/**
|
|
53
|
+
* Get rules for a specific action
|
|
54
|
+
*/
|
|
55
|
+
getRulesForAction(action: string): GrammarRule[];
|
|
56
|
+
/**
|
|
57
|
+
* Sort rules by priority (descending)
|
|
58
|
+
*/
|
|
59
|
+
protected sortRules(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Create a grammar builder connected to this engine
|
|
62
|
+
*/
|
|
63
|
+
createBuilder(): GrammarBuilder;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=grammar-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar-engine.d.ts","sourceRoot":"","sources":["../../src/grammar/grammar-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AACzD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,cAAc,EAEd,cAAc,EAOf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAA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