@sharpee/parser-en-us 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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/direction-mappings.d.ts +24 -0
- package/dist/direction-mappings.d.ts.map +1 -0
- package/dist/direction-mappings.js +82 -0
- package/dist/direction-mappings.js.map +1 -0
- package/dist/english-grammar-engine.d.ts +85 -0
- package/dist/english-grammar-engine.d.ts.map +1 -0
- package/dist/english-grammar-engine.js +562 -0
- package/dist/english-grammar-engine.js.map +1 -0
- package/dist/english-parser.d.ts +184 -0
- package/dist/english-parser.d.ts.map +1 -0
- package/dist/english-parser.js +1268 -0
- package/dist/english-parser.js.map +1 -0
- package/dist/english-pattern-compiler.d.ts +29 -0
- package/dist/english-pattern-compiler.d.ts.map +1 -0
- package/dist/english-pattern-compiler.js +211 -0
- package/dist/english-pattern-compiler.js.map +1 -0
- package/dist/grammar.d.ts +19 -0
- package/dist/grammar.d.ts.map +1 -0
- package/dist/grammar.js +620 -0
- package/dist/grammar.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/parse-failure.d.ts +59 -0
- package/dist/parse-failure.d.ts.map +1 -0
- package/dist/parse-failure.js +132 -0
- package/dist/parse-failure.js.map +1 -0
- package/dist/parser-types.d.ts +185 -0
- package/dist/parser-types.d.ts.map +1 -0
- package/dist/parser-types.js +134 -0
- package/dist/parser-types.js.map +1 -0
- package/dist/pronoun-context.d.ts +119 -0
- package/dist/pronoun-context.d.ts.map +1 -0
- package/dist/pronoun-context.js +249 -0
- package/dist/pronoun-context.js.map +1 -0
- package/dist/scope-evaluator.d.ts +58 -0
- package/dist/scope-evaluator.d.ts.map +1 -0
- package/dist/scope-evaluator.js +205 -0
- package/dist/scope-evaluator.js.map +1 -0
- package/dist/slot-consumers/entity-slot-consumer.d.ts +36 -0
- package/dist/slot-consumers/entity-slot-consumer.d.ts.map +1 -0
- package/dist/slot-consumers/entity-slot-consumer.js +413 -0
- package/dist/slot-consumers/entity-slot-consumer.js.map +1 -0
- package/dist/slot-consumers/index.d.ts +43 -0
- package/dist/slot-consumers/index.d.ts.map +1 -0
- package/dist/slot-consumers/index.js +78 -0
- package/dist/slot-consumers/index.js.map +1 -0
- package/dist/slot-consumers/slot-consumer.d.ts +61 -0
- package/dist/slot-consumers/slot-consumer.d.ts.map +1 -0
- package/dist/slot-consumers/slot-consumer.js +31 -0
- package/dist/slot-consumers/slot-consumer.js.map +1 -0
- package/dist/slot-consumers/text-slot-consumer.d.ts +33 -0
- package/dist/slot-consumers/text-slot-consumer.d.ts.map +1 -0
- package/dist/slot-consumers/text-slot-consumer.js +157 -0
- package/dist/slot-consumers/text-slot-consumer.js.map +1 -0
- package/dist/slot-consumers/typed-slot-consumer.d.ts +35 -0
- package/dist/slot-consumers/typed-slot-consumer.d.ts.map +1 -0
- package/dist/slot-consumers/typed-slot-consumer.js +151 -0
- package/dist/slot-consumers/typed-slot-consumer.js.map +1 -0
- package/dist/slot-consumers/vocabulary-slot-consumer.d.ts +42 -0
- package/dist/slot-consumers/vocabulary-slot-consumer.d.ts.map +1 -0
- package/dist/slot-consumers/vocabulary-slot-consumer.js +186 -0
- package/dist/slot-consumers/vocabulary-slot-consumer.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Pronoun Context for Parser (ADR-089 Phase B)
|
|
3
|
+
* @description Tracks entity references for pronoun resolution
|
|
4
|
+
*
|
|
5
|
+
* Enables commands like:
|
|
6
|
+
* - "take lamp. light it" → "it" = lamp
|
|
7
|
+
* - "talk to Alice. give her the key" → "her" = Alice
|
|
8
|
+
* - "take all. drop them" → "them" = all items taken
|
|
9
|
+
*/
|
|
10
|
+
import type { IParsedCommand, IValidatedCommand } from '@sharpee/world-model';
|
|
11
|
+
import type { PronounSet } from '@sharpee/world-model';
|
|
12
|
+
/**
|
|
13
|
+
* Reference to an entity mentioned in a command
|
|
14
|
+
*/
|
|
15
|
+
export interface EntityReference {
|
|
16
|
+
/** The entity's ID */
|
|
17
|
+
entityId: string;
|
|
18
|
+
/** How the player referred to it ("the lamp", "Alice") */
|
|
19
|
+
text: string;
|
|
20
|
+
/** Turn number when this reference was set */
|
|
21
|
+
turnNumber: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Context for resolving pronouns in commands
|
|
25
|
+
*/
|
|
26
|
+
export interface PronounContext {
|
|
27
|
+
/**
|
|
28
|
+
* Inanimate singular - last direct object that's not an actor
|
|
29
|
+
* Used for "it" resolution
|
|
30
|
+
*/
|
|
31
|
+
it: EntityReference | null;
|
|
32
|
+
/**
|
|
33
|
+
* Plural - last list, "all" result, or plural entity
|
|
34
|
+
* Used for "them" resolution (inanimate plural)
|
|
35
|
+
*/
|
|
36
|
+
them: EntityReference[] | null;
|
|
37
|
+
/**
|
|
38
|
+
* Animate by object pronoun - keyed by the object pronoun form
|
|
39
|
+
* "him" → entity using he/him
|
|
40
|
+
* "her" → entity using she/her
|
|
41
|
+
* Also handles animate singular "them" and neopronouns
|
|
42
|
+
*/
|
|
43
|
+
animateByPronoun: Map<string, EntityReference>;
|
|
44
|
+
/**
|
|
45
|
+
* Last successful command (for "again"/"g" command)
|
|
46
|
+
*/
|
|
47
|
+
lastCommand: IParsedCommand | null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Standard pronouns that the parser should recognize
|
|
51
|
+
*/
|
|
52
|
+
export declare const RECOGNIZED_PRONOUNS: readonly ["it", "them", "him", "her", "xem", "zir", "hir", "em", "faer"];
|
|
53
|
+
export type RecognizedPronoun = typeof RECOGNIZED_PRONOUNS[number];
|
|
54
|
+
/**
|
|
55
|
+
* Check if a word is a recognized pronoun
|
|
56
|
+
*/
|
|
57
|
+
export declare function isRecognizedPronoun(word: string): word is RecognizedPronoun;
|
|
58
|
+
/**
|
|
59
|
+
* Inanimate pronoun sets for objects without ActorTrait
|
|
60
|
+
*/
|
|
61
|
+
export declare const INANIMATE_IT: PronounSet;
|
|
62
|
+
export declare const INANIMATE_THEM: PronounSet;
|
|
63
|
+
/**
|
|
64
|
+
* Set the global pronoun context manager (called by parser)
|
|
65
|
+
*/
|
|
66
|
+
export declare function setPronounContextManager(manager: PronounContextManager | null): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get the global pronoun context manager (used by slot consumers)
|
|
69
|
+
*/
|
|
70
|
+
export declare function getPronounContextManager(): PronounContextManager | null;
|
|
71
|
+
/**
|
|
72
|
+
* Manager for pronoun context
|
|
73
|
+
* Handles updating and resolving pronoun references
|
|
74
|
+
*/
|
|
75
|
+
export declare class PronounContextManager {
|
|
76
|
+
private context;
|
|
77
|
+
constructor();
|
|
78
|
+
/**
|
|
79
|
+
* Create an empty pronoun context
|
|
80
|
+
*/
|
|
81
|
+
private createEmptyContext;
|
|
82
|
+
/**
|
|
83
|
+
* Reset the pronoun context (e.g., on game restart)
|
|
84
|
+
*/
|
|
85
|
+
reset(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get the current pronoun context (for debugging/testing)
|
|
88
|
+
*/
|
|
89
|
+
getContext(): Readonly<PronounContext>;
|
|
90
|
+
/**
|
|
91
|
+
* Resolve a pronoun to entity references
|
|
92
|
+
* @param pronoun The pronoun to resolve ("it", "him", "her", "them", etc.)
|
|
93
|
+
* @returns Entity reference(s) or null if no match
|
|
94
|
+
*/
|
|
95
|
+
resolve(pronoun: string): EntityReference[] | null;
|
|
96
|
+
/**
|
|
97
|
+
* Update pronoun context after a successful command execution
|
|
98
|
+
* @param command The validated command with resolved entity IDs
|
|
99
|
+
* @param world The world model (for entity lookup)
|
|
100
|
+
* @param turnNumber Current turn number
|
|
101
|
+
*/
|
|
102
|
+
updateFromCommand(command: IValidatedCommand, world: any, // WorldModel
|
|
103
|
+
turnNumber: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Process a validated object reference and update context
|
|
106
|
+
* Uses the already-resolved entity ID from validation
|
|
107
|
+
*/
|
|
108
|
+
private processValidatedReference;
|
|
109
|
+
/**
|
|
110
|
+
* Register an entity that was mentioned (for external use)
|
|
111
|
+
* This allows actions to register entities they interact with
|
|
112
|
+
*/
|
|
113
|
+
registerEntity(entityId: string, text: string, world: any, turnNumber: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Get the last successful command (for "again" support)
|
|
116
|
+
*/
|
|
117
|
+
getLastCommand(): IParsedCommand | null;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=pronoun-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pronoun-context.d.ts","sourceRoot":"","sources":["../src/pronoun-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAe,iBAAiB,EAA6B,MAAM,sBAAsB,CAAC;AACtH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,EAAE,EAAE,eAAe,GAAG,IAAI,CAAC;IAE3B;;;OAGG;IACH,IAAI,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;IAE/B;;;;;OAKG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE/C;;OAEG;IACH,WAAW,EAAE,cAAc,GAAG,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,0EAKtB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAEnE;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,iBAAiB,CAE3E;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,UAO1B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,UAO5B,CAAC;AAQF;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,GAAG,IAAI,CAEpF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,qBAAqB,GAAG,IAAI,CAEvE;AAED;;;GAGG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,OAAO,CAAiB;;IAMhC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAS1B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,UAAU,IAAI,QAAQ,CAAC,cAAc,CAAC;IAItC;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,EAAE,GAAG,IAAI;IAsClD;;;;;OAKG;IACH,iBAAiB,CACf,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,GAAG,EAAE,aAAa;IACzB,UAAU,EAAE,MAAM,GACjB,IAAI;IAyBP;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IA4CjC;;;OAGG;IACH,cAAc,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,GAAG,EACV,UAAU,EAAE,MAAM,GACjB,IAAI;IAmCP;;OAEG;IACH,cAAc,IAAI,cAAc,GAAG,IAAI;CAGxC"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Pronoun Context for Parser (ADR-089 Phase B)
|
|
4
|
+
* @description Tracks entity references for pronoun resolution
|
|
5
|
+
*
|
|
6
|
+
* Enables commands like:
|
|
7
|
+
* - "take lamp. light it" → "it" = lamp
|
|
8
|
+
* - "talk to Alice. give her the key" → "her" = Alice
|
|
9
|
+
* - "take all. drop them" → "them" = all items taken
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PronounContextManager = exports.INANIMATE_THEM = exports.INANIMATE_IT = exports.RECOGNIZED_PRONOUNS = void 0;
|
|
13
|
+
exports.isRecognizedPronoun = isRecognizedPronoun;
|
|
14
|
+
exports.setPronounContextManager = setPronounContextManager;
|
|
15
|
+
exports.getPronounContextManager = getPronounContextManager;
|
|
16
|
+
/**
|
|
17
|
+
* Standard pronouns that the parser should recognize
|
|
18
|
+
*/
|
|
19
|
+
exports.RECOGNIZED_PRONOUNS = [
|
|
20
|
+
// Standard object pronouns
|
|
21
|
+
'it', 'them', 'him', 'her',
|
|
22
|
+
// Neopronouns (object form)
|
|
23
|
+
'xem', 'zir', 'hir', 'em', 'faer'
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Check if a word is a recognized pronoun
|
|
27
|
+
*/
|
|
28
|
+
function isRecognizedPronoun(word) {
|
|
29
|
+
return exports.RECOGNIZED_PRONOUNS.includes(word.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Inanimate pronoun sets for objects without ActorTrait
|
|
33
|
+
*/
|
|
34
|
+
exports.INANIMATE_IT = {
|
|
35
|
+
subject: 'it',
|
|
36
|
+
object: 'it',
|
|
37
|
+
possessive: 'its',
|
|
38
|
+
possessiveAdj: 'its',
|
|
39
|
+
reflexive: 'itself',
|
|
40
|
+
verbForm: 'singular'
|
|
41
|
+
};
|
|
42
|
+
exports.INANIMATE_THEM = {
|
|
43
|
+
subject: 'they',
|
|
44
|
+
object: 'them',
|
|
45
|
+
possessive: 'theirs',
|
|
46
|
+
possessiveAdj: 'their',
|
|
47
|
+
reflexive: 'themselves',
|
|
48
|
+
verbForm: 'plural'
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Module-level pronoun context manager instance
|
|
52
|
+
* Set by the parser, used by slot consumers
|
|
53
|
+
*/
|
|
54
|
+
let _pronounContextManager = null;
|
|
55
|
+
/**
|
|
56
|
+
* Set the global pronoun context manager (called by parser)
|
|
57
|
+
*/
|
|
58
|
+
function setPronounContextManager(manager) {
|
|
59
|
+
_pronounContextManager = manager;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the global pronoun context manager (used by slot consumers)
|
|
63
|
+
*/
|
|
64
|
+
function getPronounContextManager() {
|
|
65
|
+
return _pronounContextManager;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Manager for pronoun context
|
|
69
|
+
* Handles updating and resolving pronoun references
|
|
70
|
+
*/
|
|
71
|
+
class PronounContextManager {
|
|
72
|
+
context;
|
|
73
|
+
constructor() {
|
|
74
|
+
this.context = this.createEmptyContext();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create an empty pronoun context
|
|
78
|
+
*/
|
|
79
|
+
createEmptyContext() {
|
|
80
|
+
return {
|
|
81
|
+
it: null,
|
|
82
|
+
them: null,
|
|
83
|
+
animateByPronoun: new Map(),
|
|
84
|
+
lastCommand: null
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Reset the pronoun context (e.g., on game restart)
|
|
89
|
+
*/
|
|
90
|
+
reset() {
|
|
91
|
+
this.context = this.createEmptyContext();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the current pronoun context (for debugging/testing)
|
|
95
|
+
*/
|
|
96
|
+
getContext() {
|
|
97
|
+
return this.context;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolve a pronoun to entity references
|
|
101
|
+
* @param pronoun The pronoun to resolve ("it", "him", "her", "them", etc.)
|
|
102
|
+
* @returns Entity reference(s) or null if no match
|
|
103
|
+
*/
|
|
104
|
+
resolve(pronoun) {
|
|
105
|
+
const normalized = pronoun.toLowerCase();
|
|
106
|
+
// DEBUG: Verify pronoun resolution
|
|
107
|
+
if (process.env.DEBUG_PRONOUNS) {
|
|
108
|
+
console.log(`[PronounContext] resolve("${pronoun}") context.it=${this.context.it?.entityId}`);
|
|
109
|
+
}
|
|
110
|
+
switch (normalized) {
|
|
111
|
+
case 'it':
|
|
112
|
+
return this.context.it ? [this.context.it] : null;
|
|
113
|
+
case 'them':
|
|
114
|
+
// Could be plural inanimate OR singular they/them animate
|
|
115
|
+
if (this.context.them && this.context.them.length > 0) {
|
|
116
|
+
return this.context.them;
|
|
117
|
+
}
|
|
118
|
+
// Check for singular they/them actor
|
|
119
|
+
const themEntity = this.context.animateByPronoun.get('them');
|
|
120
|
+
return themEntity ? [themEntity] : null;
|
|
121
|
+
case 'him':
|
|
122
|
+
case 'her':
|
|
123
|
+
case 'xem':
|
|
124
|
+
case 'zir':
|
|
125
|
+
case 'hir':
|
|
126
|
+
case 'em':
|
|
127
|
+
case 'faer':
|
|
128
|
+
const animateEntity = this.context.animateByPronoun.get(normalized);
|
|
129
|
+
return animateEntity ? [animateEntity] : null;
|
|
130
|
+
default:
|
|
131
|
+
// Check if it's a registered animate pronoun (for custom neopronouns)
|
|
132
|
+
const customEntity = this.context.animateByPronoun.get(normalized);
|
|
133
|
+
return customEntity ? [customEntity] : null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Update pronoun context after a successful command execution
|
|
138
|
+
* @param command The validated command with resolved entity IDs
|
|
139
|
+
* @param world The world model (for entity lookup)
|
|
140
|
+
* @param turnNumber Current turn number
|
|
141
|
+
*/
|
|
142
|
+
updateFromCommand(command, world, // WorldModel
|
|
143
|
+
turnNumber) {
|
|
144
|
+
// DEBUG: Verify pronoun context is being updated
|
|
145
|
+
if (process.env.DEBUG_PRONOUNS) {
|
|
146
|
+
console.log(`[PronounContext] updateFromCommand turn=${turnNumber} directObject=${command.directObject?.entity?.id}`);
|
|
147
|
+
}
|
|
148
|
+
// Store last command for "again" support
|
|
149
|
+
this.context.lastCommand = command.parsed;
|
|
150
|
+
// Process direct object - use validated entity directly
|
|
151
|
+
if (command.directObject) {
|
|
152
|
+
this.processValidatedReference(command.directObject, world, turnNumber);
|
|
153
|
+
}
|
|
154
|
+
// Process indirect object - use validated entity directly
|
|
155
|
+
if (command.indirectObject) {
|
|
156
|
+
this.processValidatedReference(command.indirectObject, world, turnNumber);
|
|
157
|
+
}
|
|
158
|
+
// Process instrument if present
|
|
159
|
+
if (command.instrument) {
|
|
160
|
+
this.processValidatedReference(command.instrument, world, turnNumber);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Process a validated object reference and update context
|
|
165
|
+
* Uses the already-resolved entity ID from validation
|
|
166
|
+
*/
|
|
167
|
+
processValidatedReference(ref, world, turnNumber) {
|
|
168
|
+
const entity = ref.entity;
|
|
169
|
+
if (!entity) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const entityRef = {
|
|
173
|
+
entityId: entity.id,
|
|
174
|
+
text: ref.parsed?.text || entity.id,
|
|
175
|
+
turnNumber
|
|
176
|
+
};
|
|
177
|
+
// Check if this is an actor (animate)
|
|
178
|
+
// Use 'any' cast since parser-en-us doesn't have trait type definitions
|
|
179
|
+
const actorTrait = entity.get('actor');
|
|
180
|
+
if (actorTrait?.pronouns) {
|
|
181
|
+
// Animate entity - store by object pronoun
|
|
182
|
+
const pronounSet = Array.isArray(actorTrait.pronouns)
|
|
183
|
+
? actorTrait.pronouns[0]
|
|
184
|
+
: actorTrait.pronouns;
|
|
185
|
+
this.context.animateByPronoun.set(pronounSet.object, entityRef);
|
|
186
|
+
// For multiple pronoun sets, register all object pronouns
|
|
187
|
+
if (Array.isArray(actorTrait.pronouns)) {
|
|
188
|
+
for (const ps of actorTrait.pronouns) {
|
|
189
|
+
this.context.animateByPronoun.set(ps.object, entityRef);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
// Inanimate entity - check grammatical number
|
|
195
|
+
const identityTrait = entity.get('identity');
|
|
196
|
+
if (identityTrait?.grammaticalNumber === 'plural') {
|
|
197
|
+
this.context.them = [entityRef];
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
this.context.it = entityRef;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Register an entity that was mentioned (for external use)
|
|
206
|
+
* This allows actions to register entities they interact with
|
|
207
|
+
*/
|
|
208
|
+
registerEntity(entityId, text, world, turnNumber) {
|
|
209
|
+
const entity = world.getEntity(entityId);
|
|
210
|
+
if (!entity) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const ref = {
|
|
214
|
+
entityId,
|
|
215
|
+
text,
|
|
216
|
+
turnNumber
|
|
217
|
+
};
|
|
218
|
+
const actorTrait = entity.get('actor');
|
|
219
|
+
if (actorTrait?.pronouns) {
|
|
220
|
+
const pronounSet = Array.isArray(actorTrait.pronouns)
|
|
221
|
+
? actorTrait.pronouns[0]
|
|
222
|
+
: actorTrait.pronouns;
|
|
223
|
+
this.context.animateByPronoun.set(pronounSet.object, ref);
|
|
224
|
+
// For multiple pronoun sets, register all object pronouns
|
|
225
|
+
if (Array.isArray(actorTrait.pronouns)) {
|
|
226
|
+
for (const ps of actorTrait.pronouns) {
|
|
227
|
+
this.context.animateByPronoun.set(ps.object, ref);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const identityTrait = entity.get('identity');
|
|
233
|
+
if (identityTrait?.grammaticalNumber === 'plural') {
|
|
234
|
+
this.context.them = [ref];
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
this.context.it = ref;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Get the last successful command (for "again" support)
|
|
243
|
+
*/
|
|
244
|
+
getLastCommand() {
|
|
245
|
+
return this.context.lastCommand;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.PronounContextManager = PronounContextManager;
|
|
249
|
+
//# sourceMappingURL=pronoun-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pronoun-context.js","sourceRoot":"","sources":["../src/pronoun-context.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AA8DH,kDAEC;AAgCD,4DAEC;AAKD,4DAEC;AA1DD;;GAEG;AACU,QAAA,mBAAmB,GAAG;IACjC,2BAA2B;IAC3B,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAC1B,4BAA4B;IAC5B,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;CACzB,CAAC;AAIX;;GAEG;AACH,SAAgB,mBAAmB,CAAC,IAAY;IAC9C,OAAO,2BAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAuB,CAAC,CAAC;AAC/E,CAAC;AAED;;GAEG;AACU,QAAA,YAAY,GAAe;IACtC,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,SAAS,EAAE,QAAQ;IACnB,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEW,QAAA,cAAc,GAAe;IACxC,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,QAAQ;IACpB,aAAa,EAAE,OAAO;IACtB,SAAS,EAAE,YAAY;IACvB,QAAQ,EAAE,QAAQ;CACnB,CAAC;AAEF;;;GAGG;AACH,IAAI,sBAAsB,GAAiC,IAAI,CAAC;AAEhE;;GAEG;AACH,SAAgB,wBAAwB,CAAC,OAAqC;IAC5E,sBAAsB,GAAG,OAAO,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB;IACtC,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAa,qBAAqB;IACxB,OAAO,CA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,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBACpD,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC7C,IAAI,aAAa,EAAE,iBAAiB,KAAK,QAAQ,EAAE,CAAC;gBAClD,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IAClC,CAAC;CACF;AAjND,sDAiNC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Scope Evaluator
|
|
3
|
+
* @description Evaluates scope constraints against the world model
|
|
4
|
+
*/
|
|
5
|
+
import { ScopeConstraint, GrammarContext } from '@sharpee/if-domain';
|
|
6
|
+
import { IEntity } from '@sharpee/core';
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates scope constraints to find matching entities
|
|
9
|
+
*/
|
|
10
|
+
export declare class ScopeEvaluator {
|
|
11
|
+
/**
|
|
12
|
+
* Get entities that match a scope constraint
|
|
13
|
+
*/
|
|
14
|
+
static getEntitiesInScope(constraint: ScopeConstraint, context: GrammarContext): IEntity[];
|
|
15
|
+
/**
|
|
16
|
+
* Check if a single entity matches a scope constraint
|
|
17
|
+
*/
|
|
18
|
+
static entityMatchesScope(entity: IEntity, constraint: ScopeConstraint, context: GrammarContext): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get all entities in the world
|
|
21
|
+
*/
|
|
22
|
+
private static getAllEntities;
|
|
23
|
+
/**
|
|
24
|
+
* Get visible entities from current location
|
|
25
|
+
*/
|
|
26
|
+
private static getVisibleEntities;
|
|
27
|
+
/**
|
|
28
|
+
* Get touchable entities from current location
|
|
29
|
+
*/
|
|
30
|
+
private static getTouchableEntities;
|
|
31
|
+
/**
|
|
32
|
+
* Get entities carried by the actor
|
|
33
|
+
*/
|
|
34
|
+
private static getCarriedEntities;
|
|
35
|
+
/**
|
|
36
|
+
* Get nearby entities (visible + adjacent locations)
|
|
37
|
+
*/
|
|
38
|
+
private static getNearbyEntities;
|
|
39
|
+
/**
|
|
40
|
+
* Check if entity matches a filter
|
|
41
|
+
*/
|
|
42
|
+
private static matchesFilter;
|
|
43
|
+
/**
|
|
44
|
+
* Check if entity has a specific trait
|
|
45
|
+
* Supports both entity.has() method and entity.get() method patterns
|
|
46
|
+
*/
|
|
47
|
+
private static entityHasTrait;
|
|
48
|
+
/**
|
|
49
|
+
* Get entity names and aliases for matching
|
|
50
|
+
* Supports both legacy attributes.name and IdentityTrait patterns
|
|
51
|
+
*/
|
|
52
|
+
private static getEntityNames;
|
|
53
|
+
/**
|
|
54
|
+
* Find entities by name in a given scope
|
|
55
|
+
*/
|
|
56
|
+
static findEntitiesByName(name: string, constraint: ScopeConstraint, context: GrammarContext): IEntity[];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=scope-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-evaluator.d.ts","sourceRoot":"","sources":["../src/scope-evaluator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,eAAe,EAGf,cAAc,EACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;GAEG;AACH,qBAAa,cAAc;IACzB;;OAEG;IACH,MAAM,CAAC,kBAAkB,CACvB,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,EAAE;IA0DZ;;OAEG;IACH,MAAM,CAAC,kBAAkB,CACvB,MAAM,EAAE,OAAO,EACf,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO;IAKV;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAO7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAOjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAOnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAOjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAoB5B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAe7B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IA8B7B;;OAEG;IACH,MAAM,CAAC,kBAAkB,CACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,EAAE;CAwBb"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Scope Evaluator
|
|
4
|
+
* @description Evaluates scope constraints against the world model
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ScopeEvaluator = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Evaluates scope constraints to find matching entities
|
|
10
|
+
*/
|
|
11
|
+
class ScopeEvaluator {
|
|
12
|
+
/**
|
|
13
|
+
* Get entities that match a scope constraint
|
|
14
|
+
*/
|
|
15
|
+
static getEntitiesInScope(constraint, context) {
|
|
16
|
+
// If no world model, return empty array
|
|
17
|
+
if (!context.world) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
// Start with base scope
|
|
21
|
+
let entities = [];
|
|
22
|
+
switch (constraint.base) {
|
|
23
|
+
case 'all':
|
|
24
|
+
entities = this.getAllEntities(context);
|
|
25
|
+
break;
|
|
26
|
+
case 'visible':
|
|
27
|
+
entities = this.getVisibleEntities(context);
|
|
28
|
+
break;
|
|
29
|
+
case 'touchable':
|
|
30
|
+
entities = this.getTouchableEntities(context);
|
|
31
|
+
break;
|
|
32
|
+
case 'carried':
|
|
33
|
+
entities = this.getCarriedEntities(context);
|
|
34
|
+
break;
|
|
35
|
+
case 'nearby':
|
|
36
|
+
entities = this.getNearbyEntities(context);
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
entities = [];
|
|
40
|
+
}
|
|
41
|
+
// Apply filters
|
|
42
|
+
for (const filter of constraint.filters) {
|
|
43
|
+
entities = entities.filter(entity => this.matchesFilter(entity, filter, context));
|
|
44
|
+
}
|
|
45
|
+
// Apply trait filters
|
|
46
|
+
if (constraint.traitFilters && constraint.traitFilters.length > 0) {
|
|
47
|
+
entities = entities.filter(entity => constraint.traitFilters.every(traitType => this.entityHasTrait(entity, traitType)));
|
|
48
|
+
}
|
|
49
|
+
// Add explicit entities
|
|
50
|
+
if (constraint.explicitEntities.length > 0) {
|
|
51
|
+
const additionalEntities = constraint.explicitEntities
|
|
52
|
+
.map(id => context.world.getEntity(id))
|
|
53
|
+
.filter(Boolean);
|
|
54
|
+
entities = [...entities, ...additionalEntities];
|
|
55
|
+
}
|
|
56
|
+
// Remove duplicates
|
|
57
|
+
const uniqueIds = new Set(entities.map(e => e.id));
|
|
58
|
+
return entities.filter((e, i, arr) => arr.findIndex(e2 => e2.id === e.id) === i);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a single entity matches a scope constraint
|
|
62
|
+
*/
|
|
63
|
+
static entityMatchesScope(entity, constraint, context) {
|
|
64
|
+
const matchingEntities = this.getEntitiesInScope(constraint, context);
|
|
65
|
+
return matchingEntities.some(e => e.id === entity.id);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get all entities in the world
|
|
69
|
+
*/
|
|
70
|
+
static getAllEntities(context) {
|
|
71
|
+
if (!context.world?.getAllEntities) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
return context.world.getAllEntities();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get visible entities from current location
|
|
78
|
+
*/
|
|
79
|
+
static getVisibleEntities(context) {
|
|
80
|
+
if (!context.world?.getVisibleEntities) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return context.world.getVisibleEntities(context.actorId, context.currentLocation);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get touchable entities from current location
|
|
87
|
+
*/
|
|
88
|
+
static getTouchableEntities(context) {
|
|
89
|
+
if (!context.world?.getTouchableEntities) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
return context.world.getTouchableEntities(context.actorId, context.currentLocation);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get entities carried by the actor
|
|
96
|
+
*/
|
|
97
|
+
static getCarriedEntities(context) {
|
|
98
|
+
if (!context.world?.getCarriedEntities) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
return context.world.getCarriedEntities(context.actorId);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get nearby entities (visible + adjacent locations)
|
|
105
|
+
*/
|
|
106
|
+
static getNearbyEntities(context) {
|
|
107
|
+
if (!context.world?.getNearbyEntities) {
|
|
108
|
+
// Fallback to visible if nearby not implemented
|
|
109
|
+
return this.getVisibleEntities(context);
|
|
110
|
+
}
|
|
111
|
+
return context.world.getNearbyEntities(context.actorId, context.currentLocation);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if entity matches a filter
|
|
115
|
+
*/
|
|
116
|
+
static matchesFilter(entity, filter, context) {
|
|
117
|
+
if (typeof filter === 'function') {
|
|
118
|
+
// Function constraint
|
|
119
|
+
return filter(entity, context);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Property constraint
|
|
123
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
124
|
+
const entityValue = entity[key];
|
|
125
|
+
if (entityValue !== value) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if entity has a specific trait
|
|
134
|
+
* Supports both entity.has() method and entity.get() method patterns
|
|
135
|
+
*/
|
|
136
|
+
static entityHasTrait(entity, traitType) {
|
|
137
|
+
// Check for .has() method (trait system standard)
|
|
138
|
+
if (typeof entity.has === 'function') {
|
|
139
|
+
return entity.has(traitType);
|
|
140
|
+
}
|
|
141
|
+
// Check for .get() method returning truthy value (alternate pattern)
|
|
142
|
+
if (typeof entity.get === 'function') {
|
|
143
|
+
const trait = entity.get(traitType);
|
|
144
|
+
return trait !== undefined && trait !== null;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get entity names and aliases for matching
|
|
150
|
+
* Supports both legacy attributes.name and IdentityTrait patterns
|
|
151
|
+
*/
|
|
152
|
+
static getEntityNames(entity) {
|
|
153
|
+
const names = [];
|
|
154
|
+
// Check attributes (legacy pattern)
|
|
155
|
+
if (entity.attributes) {
|
|
156
|
+
if (entity.attributes.displayName) {
|
|
157
|
+
names.push(String(entity.attributes.displayName));
|
|
158
|
+
}
|
|
159
|
+
if (entity.attributes.name) {
|
|
160
|
+
names.push(String(entity.attributes.name));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Check IdentityTrait (via .get() method)
|
|
164
|
+
if (typeof entity.get === 'function') {
|
|
165
|
+
const identity = entity.get('identity');
|
|
166
|
+
if (identity && typeof identity === 'object') {
|
|
167
|
+
if (identity.name) {
|
|
168
|
+
names.push(String(identity.name));
|
|
169
|
+
}
|
|
170
|
+
// Also check aliases
|
|
171
|
+
if (Array.isArray(identity.aliases)) {
|
|
172
|
+
names.push(...identity.aliases.map(String));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return names;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Find entities by name in a given scope
|
|
180
|
+
*/
|
|
181
|
+
static findEntitiesByName(name, constraint, context) {
|
|
182
|
+
const entitiesInScope = this.getEntitiesInScope(constraint, context);
|
|
183
|
+
const searchName = name.toLowerCase();
|
|
184
|
+
// Try exact match first (name or any alias)
|
|
185
|
+
const exactMatches = entitiesInScope.filter(e => {
|
|
186
|
+
if (!e)
|
|
187
|
+
return false;
|
|
188
|
+
const names = this.getEntityNames(e);
|
|
189
|
+
return names.some(n => n.toLowerCase() === searchName);
|
|
190
|
+
});
|
|
191
|
+
if (exactMatches.length > 0) {
|
|
192
|
+
return exactMatches;
|
|
193
|
+
}
|
|
194
|
+
// Try partial match
|
|
195
|
+
const partialMatches = entitiesInScope.filter(e => {
|
|
196
|
+
if (!e)
|
|
197
|
+
return false;
|
|
198
|
+
const names = this.getEntityNames(e);
|
|
199
|
+
return names.some(n => n.toLowerCase().includes(searchName));
|
|
200
|
+
});
|
|
201
|
+
return partialMatches;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.ScopeEvaluator = ScopeEvaluator;
|
|
205
|
+
//# sourceMappingURL=scope-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-evaluator.js","sourceRoot":"","sources":["../src/scope-evaluator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH;;GAEG;AACH,MAAa,cAAc;IACzB;;OAEG;IACH,MAAM,CAAC,kBAAkB,CACvB,UAA2B,EAC3B,OAAuB;QAEvB,wCAAwC;QACxC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,wBAAwB;QACxB,IAAI,QAAQ,GAAc,EAAE,CAAC;QAE7B,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;YACxB,KAAK,KAAK;gBACR,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,C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