@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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/direction-mappings.d.ts +24 -0
  4. package/dist/direction-mappings.d.ts.map +1 -0
  5. package/dist/direction-mappings.js +82 -0
  6. package/dist/direction-mappings.js.map +1 -0
  7. package/dist/english-grammar-engine.d.ts +85 -0
  8. package/dist/english-grammar-engine.d.ts.map +1 -0
  9. package/dist/english-grammar-engine.js +562 -0
  10. package/dist/english-grammar-engine.js.map +1 -0
  11. package/dist/english-parser.d.ts +184 -0
  12. package/dist/english-parser.d.ts.map +1 -0
  13. package/dist/english-parser.js +1268 -0
  14. package/dist/english-parser.js.map +1 -0
  15. package/dist/english-pattern-compiler.d.ts +29 -0
  16. package/dist/english-pattern-compiler.d.ts.map +1 -0
  17. package/dist/english-pattern-compiler.js +211 -0
  18. package/dist/english-pattern-compiler.js.map +1 -0
  19. package/dist/grammar.d.ts +19 -0
  20. package/dist/grammar.d.ts.map +1 -0
  21. package/dist/grammar.js +620 -0
  22. package/dist/grammar.js.map +1 -0
  23. package/dist/index.d.ts +24 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +44 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/parse-failure.d.ts +59 -0
  28. package/dist/parse-failure.d.ts.map +1 -0
  29. package/dist/parse-failure.js +132 -0
  30. package/dist/parse-failure.js.map +1 -0
  31. package/dist/parser-types.d.ts +185 -0
  32. package/dist/parser-types.d.ts.map +1 -0
  33. package/dist/parser-types.js +134 -0
  34. package/dist/parser-types.js.map +1 -0
  35. package/dist/pronoun-context.d.ts +119 -0
  36. package/dist/pronoun-context.d.ts.map +1 -0
  37. package/dist/pronoun-context.js +249 -0
  38. package/dist/pronoun-context.js.map +1 -0
  39. package/dist/scope-evaluator.d.ts +58 -0
  40. package/dist/scope-evaluator.d.ts.map +1 -0
  41. package/dist/scope-evaluator.js +205 -0
  42. package/dist/scope-evaluator.js.map +1 -0
  43. package/dist/slot-consumers/entity-slot-consumer.d.ts +36 -0
  44. package/dist/slot-consumers/entity-slot-consumer.d.ts.map +1 -0
  45. package/dist/slot-consumers/entity-slot-consumer.js +413 -0
  46. package/dist/slot-consumers/entity-slot-consumer.js.map +1 -0
  47. package/dist/slot-consumers/index.d.ts +43 -0
  48. package/dist/slot-consumers/index.d.ts.map +1 -0
  49. package/dist/slot-consumers/index.js +78 -0
  50. package/dist/slot-consumers/index.js.map +1 -0
  51. package/dist/slot-consumers/slot-consumer.d.ts +61 -0
  52. package/dist/slot-consumers/slot-consumer.d.ts.map +1 -0
  53. package/dist/slot-consumers/slot-consumer.js +31 -0
  54. package/dist/slot-consumers/slot-consumer.js.map +1 -0
  55. package/dist/slot-consumers/text-slot-consumer.d.ts +33 -0
  56. package/dist/slot-consumers/text-slot-consumer.d.ts.map +1 -0
  57. package/dist/slot-consumers/text-slot-consumer.js +157 -0
  58. package/dist/slot-consumers/text-slot-consumer.js.map +1 -0
  59. package/dist/slot-consumers/typed-slot-consumer.d.ts +35 -0
  60. package/dist/slot-consumers/typed-slot-consumer.d.ts.map +1 -0
  61. package/dist/slot-consumers/typed-slot-consumer.js +151 -0
  62. package/dist/slot-consumers/typed-slot-consumer.js.map +1 -0
  63. package/dist/slot-consumers/vocabulary-slot-consumer.d.ts +42 -0
  64. package/dist/slot-consumers/vocabulary-slot-consumer.d.ts.map +1 -0
  65. package/dist/slot-consumers/vocabulary-slot-consumer.js +186 -0
  66. package/dist/slot-consumers/vocabulary-slot-consumer.js.map +1 -0
  67. package/package.json +65 -0
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ /**
3
+ * @file Vocabulary Slot Consumer
4
+ * @description Handles vocabulary-constrained slots (ADR-088, ADR-082)
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.VocabularySlotConsumer = void 0;
8
+ const if_domain_1 = require("@sharpee/if-domain");
9
+ /**
10
+ * Built-in manner adverbs that modify how actions are performed.
11
+ * Stories can extend this via vocab.extend('manner', [...])
12
+ */
13
+ const MANNER_ADVERBS = new Set([
14
+ 'carefully', 'quietly', 'quickly', 'slowly',
15
+ 'forcefully', 'gently', 'loudly', 'softly',
16
+ 'cautiously', 'boldly', 'stealthily', 'silently',
17
+ 'hastily', 'deliberately', 'violently', 'tenderly'
18
+ ]);
19
+ /**
20
+ * Consumer for vocabulary-constrained slots (ADJECTIVE, NOUN, VOCABULARY, MANNER)
21
+ * Validates input against registered vocabulary categories
22
+ */
23
+ class VocabularySlotConsumer {
24
+ slotTypes = [
25
+ if_domain_1.SlotType.ADJECTIVE,
26
+ if_domain_1.SlotType.NOUN,
27
+ if_domain_1.SlotType.VOCABULARY,
28
+ if_domain_1.SlotType.MANNER
29
+ ];
30
+ consume(ctx) {
31
+ const { slotType } = ctx;
32
+ switch (slotType) {
33
+ case if_domain_1.SlotType.ADJECTIVE:
34
+ return this.consumeAdjective(ctx);
35
+ case if_domain_1.SlotType.NOUN:
36
+ return this.consumeNoun(ctx);
37
+ case if_domain_1.SlotType.VOCABULARY:
38
+ return this.consumeVocabulary(ctx);
39
+ case if_domain_1.SlotType.MANNER:
40
+ return this.consumeManner(ctx);
41
+ default:
42
+ return null;
43
+ }
44
+ }
45
+ /**
46
+ * Consume an adjective slot from story vocabulary
47
+ * Requires vocabulary to be registered via language provider
48
+ */
49
+ consumeAdjective(ctx) {
50
+ const { tokens, startIndex, context } = ctx;
51
+ if (startIndex >= tokens.length) {
52
+ return null;
53
+ }
54
+ const token = tokens[startIndex];
55
+ const normalized = token.normalized;
56
+ // Get adjective vocabulary from context (world has language provider)
57
+ const adjectives = this.getVocabulary(context, 'adjectives');
58
+ if (adjectives && adjectives.has(normalized)) {
59
+ return {
60
+ tokens: [startIndex],
61
+ text: token.word,
62
+ confidence: 1.0,
63
+ slotType: if_domain_1.SlotType.ADJECTIVE
64
+ };
65
+ }
66
+ return null;
67
+ }
68
+ /**
69
+ * Consume a noun slot from story vocabulary
70
+ * Requires vocabulary to be registered via language provider
71
+ */
72
+ consumeNoun(ctx) {
73
+ const { tokens, startIndex, context } = ctx;
74
+ if (startIndex >= tokens.length) {
75
+ return null;
76
+ }
77
+ const token = tokens[startIndex];
78
+ const normalized = token.normalized;
79
+ // Get noun vocabulary from context (world has language provider)
80
+ const nouns = this.getVocabulary(context, 'nouns');
81
+ if (nouns && nouns.has(normalized)) {
82
+ return {
83
+ tokens: [startIndex],
84
+ text: token.word,
85
+ confidence: 1.0,
86
+ slotType: if_domain_1.SlotType.NOUN
87
+ };
88
+ }
89
+ return null;
90
+ }
91
+ /**
92
+ * Consume a vocabulary slot from a story-defined category.
93
+ * Uses GrammarVocabularyProvider to check if word is in category
94
+ * and if the category is active in the current context.
95
+ */
96
+ consumeVocabulary(ctx) {
97
+ const { tokens, startIndex, context, slotConstraints } = ctx;
98
+ const category = slotConstraints?.vocabularyCategory;
99
+ if (startIndex >= tokens.length || !category) {
100
+ return null;
101
+ }
102
+ const token = tokens[startIndex];
103
+ const word = token.normalized;
104
+ // Get the vocabulary provider from the world
105
+ const world = context.world;
106
+ if (!world?.getGrammarVocabularyProvider) {
107
+ return null;
108
+ }
109
+ const vocabProvider = world.getGrammarVocabularyProvider();
110
+ // Check if word matches the category in current context
111
+ if (vocabProvider.match(category, word, context)) {
112
+ return {
113
+ tokens: [startIndex],
114
+ text: token.word,
115
+ confidence: 1.0,
116
+ slotType: if_domain_1.SlotType.VOCABULARY,
117
+ // Store category and matched word for action access
118
+ category,
119
+ matchedWord: word
120
+ };
121
+ }
122
+ return null;
123
+ }
124
+ /**
125
+ * Consume a manner adverb slot.
126
+ * Matches built-in manner adverbs plus any story-defined extensions.
127
+ * The matched manner is intended to feed into command.intention.manner
128
+ */
129
+ consumeManner(ctx) {
130
+ const { tokens, startIndex, context } = ctx;
131
+ if (startIndex >= tokens.length) {
132
+ return null;
133
+ }
134
+ const token = tokens[startIndex];
135
+ const word = token.normalized;
136
+ // First check built-in manner adverbs
137
+ if (MANNER_ADVERBS.has(word)) {
138
+ return {
139
+ tokens: [startIndex],
140
+ text: token.word,
141
+ confidence: 1.0,
142
+ slotType: if_domain_1.SlotType.MANNER,
143
+ manner: word
144
+ };
145
+ }
146
+ // Then check story-extended manner vocabulary
147
+ const world = context.world;
148
+ if (world?.getGrammarVocabularyProvider) {
149
+ const vocabProvider = world.getGrammarVocabularyProvider();
150
+ if (vocabProvider.match('manner', word, context)) {
151
+ return {
152
+ tokens: [startIndex],
153
+ text: token.word,
154
+ confidence: 1.0,
155
+ slotType: if_domain_1.SlotType.MANNER,
156
+ manner: word
157
+ };
158
+ }
159
+ }
160
+ return null;
161
+ }
162
+ /**
163
+ * Get vocabulary set from context
164
+ * Returns null if vocabulary not available
165
+ */
166
+ getVocabulary(context, type) {
167
+ // Try to get vocabulary from world's language provider
168
+ const world = context.world;
169
+ if (!world)
170
+ return null;
171
+ // Check for vocabulary provider interface
172
+ const provider = world.getVocabularyProvider?.();
173
+ if (!provider)
174
+ return null;
175
+ switch (type) {
176
+ case 'adjectives':
177
+ return provider.getAdjectives?.() || null;
178
+ case 'nouns':
179
+ return provider.getNouns?.() || null;
180
+ default:
181
+ return null;
182
+ }
183
+ }
184
+ }
185
+ exports.VocabularySlotConsumer = VocabularySlotConsumer;
186
+ //# sourceMappingURL=vocabulary-slot-consumer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocabulary-slot-consumer.js","sourceRoot":"","sources":["../../src/slot-consumers/vocabulary-slot-consumer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kDAAyE;AAGzE;;;GAGG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ;IAC3C,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IAC1C,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU;IAChD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C,KAAK,CAAC;QAC5B,IAAI,KAAK,EAAE,4BAA4B,EAAE,CAAC;YACxC,MAAM,aAAa,GAAG,KAAK,CAAC,4BAA4B,EAAE,CAAC;YAC3D,IAAI,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;gBACjD,OAAO;oBACL,MAAM,EAAE,CAAC,UAAU,CAAC;oBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,UAAU,EAAE,GAAG;oBACf,QAAQ,EAAE,oBAAQ,CAAC,MAAM;oBACzB,MAAM,EAAE,IAAI;iBACb,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACK,aAAa,CACnB,OAAuB,EACvB,IAA4B;QAE5B,uDAAuD;QACvD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,0CAA0C;QAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,qBAAqB,EAAE,EAAE,CAAC;QACjD,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAE3B,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,YAAY;gBACf,OAAO,QAAQ,CAAC,aAAa,EAAE,EAAE,IAAI,IAAI,CAAC;YAC5C,KAAK,OAAO;gBACV,OAAO,QAAQ,CAAC,QAAQ,EAAE,EAAE,IAAI,IAAI,CAAC;YACvC;gBACE,OAAO,IAAI,CAAC;QAChB,CAAC;IACH,CAAC;CACF;AAhMD,wDAgMC"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@sharpee/parser-en-us",
3
+ "version": "0.9.60-beta",
4
+ "description": "English (US) parser for Sharpee Interactive Fiction Platform",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "dependencies": {
16
+ "@sharpee/lang-en-us": "0.9.60-beta",
17
+ "@sharpee/world-model": "0.9.60-beta",
18
+ "@sharpee/core": "0.9.60-beta",
19
+ "@sharpee/if-domain": "0.9.60-beta"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^20.8.0",
23
+ "@typescript-eslint/eslint-plugin": "^6.7.4",
24
+ "@typescript-eslint/parser": "^6.7.4",
25
+ "eslint": "^8.50.0",
26
+ "rimraf": "^5.0.5",
27
+ "typescript": "^5.2.2"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "keywords": [
33
+ "interactive-fiction",
34
+ "if",
35
+ "text-adventure",
36
+ "sharpee",
37
+ "parser",
38
+ "english",
39
+ "natural-language"
40
+ ],
41
+ "author": "Sharpee Team",
42
+ "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/ChicagoDave/sharpee.git",
46
+ "directory": "packages/parser-en-us"
47
+ },
48
+ "homepage": "https://github.com/ChicagoDave/sharpee#readme",
49
+ "bugs": {
50
+ "url": "https://github.com/ChicagoDave/sharpee/issues"
51
+ },
52
+ "engines": {
53
+ "node": ">=18.0.0"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "tsc",
60
+ "clean": "rimraf dist",
61
+ "test": "vitest",
62
+ "test:ci": "vitest run",
63
+ "lint": "eslint src --ext .ts"
64
+ }
65
+ }