@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 David Cornelson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @sharpee/parser-en-us
|
|
2
|
+
|
|
3
|
+
English (US) parser for the Sharpee Interactive Fiction Platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @sharpee/parser-en-us
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { EnglishParser } from '@sharpee/parser-en-us';
|
|
15
|
+
import { ParserFactory } from '@sharpee/stdlib';
|
|
16
|
+
import { EnglishLanguageProvider } from '@sharpee/lang-en-us';
|
|
17
|
+
|
|
18
|
+
// Register the parser
|
|
19
|
+
ParserFactory.registerParser('en-US', EnglishParser);
|
|
20
|
+
|
|
21
|
+
// Create language provider
|
|
22
|
+
const language = new EnglishLanguageProvider();
|
|
23
|
+
|
|
24
|
+
// Create parser instance
|
|
25
|
+
const parser = ParserFactory.createParser('en-US', language);
|
|
26
|
+
|
|
27
|
+
// Parse commands
|
|
28
|
+
const result = parser.parse('take the red ball');
|
|
29
|
+
if (result.success) {
|
|
30
|
+
console.log(result.value.action); // 'if.action.taking'
|
|
31
|
+
console.log(result.value.structure.directObject?.text); // 'the red ball'
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
### Compound Verbs
|
|
38
|
+
- "look at" → examining
|
|
39
|
+
- "pick up" → taking
|
|
40
|
+
- "put down" → dropping
|
|
41
|
+
- "turn on/off" → switching on/off
|
|
42
|
+
|
|
43
|
+
### Rich Information Preservation
|
|
44
|
+
- Articles preserved: "the", "a", "an"
|
|
45
|
+
- Modifiers tracked: "red", "small", "wooden"
|
|
46
|
+
- Position information for all tokens
|
|
47
|
+
- Original text reconstructible
|
|
48
|
+
|
|
49
|
+
### Grammar Patterns
|
|
50
|
+
- `VERB_ONLY`: "look", "wait"
|
|
51
|
+
- `VERB_NOUN`: "take ball", "examine mirror"
|
|
52
|
+
- `VERB_PREP_NOUN`: "look at painting"
|
|
53
|
+
- `VERB_NOUN_PREP_NOUN`: "put ball in box"
|
|
54
|
+
- `DIRECTION_ONLY`: "north", "n"
|
|
55
|
+
|
|
56
|
+
### Abbreviations
|
|
57
|
+
- Verb abbreviations: "x" → "examine", "l" → "look"
|
|
58
|
+
- Direction abbreviations: "n" → "north", "se" → "southeast"
|
|
59
|
+
|
|
60
|
+
## Parsed Command Structure
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface ParsedCommand {
|
|
64
|
+
rawInput: string;
|
|
65
|
+
tokens: Token[];
|
|
66
|
+
structure: {
|
|
67
|
+
verb: VerbPhrase;
|
|
68
|
+
directObject?: NounPhrase;
|
|
69
|
+
preposition?: PrepPhrase;
|
|
70
|
+
indirectObject?: NounPhrase;
|
|
71
|
+
};
|
|
72
|
+
pattern: string;
|
|
73
|
+
confidence: number;
|
|
74
|
+
action: string;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Example Output
|
|
79
|
+
|
|
80
|
+
Input: "put the small key in the wooden box"
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"action": "if.action.putting",
|
|
85
|
+
"structure": {
|
|
86
|
+
"verb": {
|
|
87
|
+
"text": "put",
|
|
88
|
+
"head": "put"
|
|
89
|
+
},
|
|
90
|
+
"directObject": {
|
|
91
|
+
"text": "the small key",
|
|
92
|
+
"head": "key",
|
|
93
|
+
"articles": ["the"],
|
|
94
|
+
"modifiers": ["small"],
|
|
95
|
+
"candidates": ["key"]
|
|
96
|
+
},
|
|
97
|
+
"preposition": {
|
|
98
|
+
"text": "in"
|
|
99
|
+
},
|
|
100
|
+
"indirectObject": {
|
|
101
|
+
"text": "the wooden box",
|
|
102
|
+
"head": "box",
|
|
103
|
+
"articles": ["the"],
|
|
104
|
+
"modifiers": ["wooden"],
|
|
105
|
+
"candidates": ["box"]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"pattern": "VERB_NOUN_PREP_NOUN",
|
|
109
|
+
"confidence": 0.7
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## English-Specific Features
|
|
114
|
+
|
|
115
|
+
- **SVO Word Order**: Subject-Verb-Object parsing
|
|
116
|
+
- **Articles**: "the", "a", "an" handling
|
|
117
|
+
- **Determiners**: "all", "every", "some"
|
|
118
|
+
- **Compound Prepositions**: Multi-word verb phrases
|
|
119
|
+
- **Flexible Adjective Placement**: "red ball" or "ball that is red"
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* English-specific direction mappings for the parser
|
|
3
|
+
* Maps English words and abbreviations to language-agnostic Direction constants
|
|
4
|
+
*/
|
|
5
|
+
import { DirectionType } from '@sharpee/world-model';
|
|
6
|
+
/**
|
|
7
|
+
* Map English direction words to Direction constants
|
|
8
|
+
*/
|
|
9
|
+
export declare const DirectionWords: Record<string, DirectionType>;
|
|
10
|
+
/**
|
|
11
|
+
* Map English abbreviations to Direction constants
|
|
12
|
+
*/
|
|
13
|
+
export declare const DirectionAbbreviations: Record<string, DirectionType>;
|
|
14
|
+
/**
|
|
15
|
+
* Parse an English direction string to a Direction constant
|
|
16
|
+
* Returns null if the string is not a recognized direction
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseDirection(input: string): DirectionType | null;
|
|
19
|
+
/**
|
|
20
|
+
* Get the English word for a Direction constant
|
|
21
|
+
* Used for display/output
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDirectionWord(direction: DirectionType): string;
|
|
24
|
+
//# sourceMappingURL=direction-mappings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction-mappings.d.ts","sourceRoot":"","sources":["../src/direction-mappings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAexD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAWhE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAgBlE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM,CAajE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* English-specific direction mappings for the parser
|
|
4
|
+
* Maps English words and abbreviations to language-agnostic Direction constants
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DirectionAbbreviations = exports.DirectionWords = void 0;
|
|
8
|
+
exports.parseDirection = parseDirection;
|
|
9
|
+
exports.getDirectionWord = getDirectionWord;
|
|
10
|
+
const world_model_1 = require("@sharpee/world-model");
|
|
11
|
+
/**
|
|
12
|
+
* Map English direction words to Direction constants
|
|
13
|
+
*/
|
|
14
|
+
exports.DirectionWords = {
|
|
15
|
+
'north': world_model_1.Direction.NORTH,
|
|
16
|
+
'south': world_model_1.Direction.SOUTH,
|
|
17
|
+
'east': world_model_1.Direction.EAST,
|
|
18
|
+
'west': world_model_1.Direction.WEST,
|
|
19
|
+
'northeast': world_model_1.Direction.NORTHEAST,
|
|
20
|
+
'northwest': world_model_1.Direction.NORTHWEST,
|
|
21
|
+
'southeast': world_model_1.Direction.SOUTHEAST,
|
|
22
|
+
'southwest': world_model_1.Direction.SOUTHWEST,
|
|
23
|
+
'up': world_model_1.Direction.UP,
|
|
24
|
+
'down': world_model_1.Direction.DOWN,
|
|
25
|
+
'in': world_model_1.Direction.IN,
|
|
26
|
+
'inside': world_model_1.Direction.IN,
|
|
27
|
+
'out': world_model_1.Direction.OUT,
|
|
28
|
+
'outside': world_model_1.Direction.OUT
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Map English abbreviations to Direction constants
|
|
32
|
+
*/
|
|
33
|
+
exports.DirectionAbbreviations = {
|
|
34
|
+
'n': world_model_1.Direction.NORTH,
|
|
35
|
+
's': world_model_1.Direction.SOUTH,
|
|
36
|
+
'e': world_model_1.Direction.EAST,
|
|
37
|
+
'w': world_model_1.Direction.WEST,
|
|
38
|
+
'ne': world_model_1.Direction.NORTHEAST,
|
|
39
|
+
'nw': world_model_1.Direction.NORTHWEST,
|
|
40
|
+
'se': world_model_1.Direction.SOUTHEAST,
|
|
41
|
+
'sw': world_model_1.Direction.SOUTHWEST,
|
|
42
|
+
'u': world_model_1.Direction.UP,
|
|
43
|
+
'd': world_model_1.Direction.DOWN
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Parse an English direction string to a Direction constant
|
|
47
|
+
* Returns null if the string is not a recognized direction
|
|
48
|
+
*/
|
|
49
|
+
function parseDirection(input) {
|
|
50
|
+
if (!input)
|
|
51
|
+
return null;
|
|
52
|
+
const normalized = input.toLowerCase().trim();
|
|
53
|
+
// Check abbreviations first (more specific)
|
|
54
|
+
if (exports.DirectionAbbreviations[normalized]) {
|
|
55
|
+
return exports.DirectionAbbreviations[normalized];
|
|
56
|
+
}
|
|
57
|
+
// Then check full words
|
|
58
|
+
if (exports.DirectionWords[normalized]) {
|
|
59
|
+
return exports.DirectionWords[normalized];
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the English word for a Direction constant
|
|
65
|
+
* Used for display/output
|
|
66
|
+
*/
|
|
67
|
+
function getDirectionWord(direction) {
|
|
68
|
+
// Find the first matching English word for this direction
|
|
69
|
+
for (const [word, dir] of Object.entries(exports.DirectionWords)) {
|
|
70
|
+
if (dir === direction) {
|
|
71
|
+
// Prefer the primary forms (not 'inside'/'outside')
|
|
72
|
+
if (direction === world_model_1.Direction.IN && word === 'inside')
|
|
73
|
+
continue;
|
|
74
|
+
if (direction === world_model_1.Direction.OUT && word === 'outside')
|
|
75
|
+
continue;
|
|
76
|
+
return word;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Fallback to lowercase version of constant
|
|
80
|
+
return direction.toLowerCase();
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=direction-mappings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction-mappings.js","sourceRoot":"","sources":["../src/direction-mappings.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA4CH,wCAgBC;AAMD,4CAaC;AA7ED,sDAAgE;AAEhE;;GAEG;AACU,QAAA,cAAc,GAAkC;IAC3D,OAAO,EAAE,uBAAS,CAAC,KAAK;IACxB,OAAO,EAAE,uBAAS,CAAC,KAAK;IACxB,MAAM,EAAE,uBAAS,CAAC,IAAI;IACtB,MAAM,EAAE,uBAAS,CAAC,IAAI;IACtB,WAAW,EA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d,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,SAAwB;IACvD,0DAA0D;IAC1D,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,sBAAc,CAAC,EAAE,CAAC;QACzD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,oDAAoD;YACpD,IAAI,SAAS,KAAK,uBAAS,CAAC,EAAE,IAAI,IAAI,KAAK,QAAQ;gBAAE,SAAS;YAC9D,IAAI,SAAS,KAAK,uBAAS,CAAC,GAAG,IAAI,IAAI,KAAK,SAAS;gBAAE,SAAS;YAChE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,4CAA4C;IAC5C,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file English Grammar Engine
|
|
3
|
+
* @description English-specific implementation of grammar matching
|
|
4
|
+
*/
|
|
5
|
+
import { GrammarEngine, GrammarContext, PatternMatch, GrammarMatchOptions, SlotMatch } from '@sharpee/if-domain';
|
|
6
|
+
import { Token } from '@sharpee/if-domain';
|
|
7
|
+
import { SlotConsumerRegistry } from './slot-consumers';
|
|
8
|
+
import type { PartialMatchFailure } from './parse-failure';
|
|
9
|
+
/**
|
|
10
|
+
* Result of attempting to match a rule - either success or failure with info
|
|
11
|
+
*/
|
|
12
|
+
export type MatchAttemptResult = {
|
|
13
|
+
success: true;
|
|
14
|
+
match: PatternMatch;
|
|
15
|
+
} | {
|
|
16
|
+
success: false;
|
|
17
|
+
failure: PartialMatchFailure;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Extended match options with failure tracking
|
|
21
|
+
*/
|
|
22
|
+
export interface ExtendedMatchOptions extends GrammarMatchOptions {
|
|
23
|
+
/** If true, collect partial match failures for error reporting */
|
|
24
|
+
trackFailures?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of findMatches with optional failure information
|
|
28
|
+
*/
|
|
29
|
+
export interface MatchResult {
|
|
30
|
+
matches: PatternMatch[];
|
|
31
|
+
failures?: PartialMatchFailure[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* English-specific grammar matching engine
|
|
35
|
+
*/
|
|
36
|
+
export declare class EnglishGrammarEngine extends GrammarEngine {
|
|
37
|
+
private slotConsumerRegistry;
|
|
38
|
+
/** Last set of partial match failures (for error reporting) */
|
|
39
|
+
private lastFailures;
|
|
40
|
+
constructor(slotConsumerRegistry?: SlotConsumerRegistry);
|
|
41
|
+
/**
|
|
42
|
+
* Get the last set of partial match failures (for error reporting)
|
|
43
|
+
*/
|
|
44
|
+
getLastFailures(): PartialMatchFailure[];
|
|
45
|
+
/**
|
|
46
|
+
* Find matching grammar rules for tokens
|
|
47
|
+
*/
|
|
48
|
+
findMatches(tokens: Token[], context: GrammarContext, options?: GrammarMatchOptions): PatternMatch[];
|
|
49
|
+
/**
|
|
50
|
+
* Try to match a single rule against tokens
|
|
51
|
+
*/
|
|
52
|
+
private tryMatchRule;
|
|
53
|
+
/**
|
|
54
|
+
* Try to match a single rule against tokens, returning failure info if no match
|
|
55
|
+
*/
|
|
56
|
+
private tryMatchRuleWithFailure;
|
|
57
|
+
/**
|
|
58
|
+
* Build semantic properties from rule and matched tokens
|
|
59
|
+
*/
|
|
60
|
+
private buildSemantics;
|
|
61
|
+
/**
|
|
62
|
+
* Consume tokens for a slot
|
|
63
|
+
*/
|
|
64
|
+
private consumeSlot;
|
|
65
|
+
/**
|
|
66
|
+
* Extract typed value from a NUMBER slot match
|
|
67
|
+
*/
|
|
68
|
+
static extractNumberValue(match: SlotMatch): number | null;
|
|
69
|
+
/**
|
|
70
|
+
* Extract typed value from an ORDINAL slot match
|
|
71
|
+
*/
|
|
72
|
+
static extractOrdinalValue(match: SlotMatch): number | null;
|
|
73
|
+
/**
|
|
74
|
+
* Extract canonical direction from a DIRECTION slot match
|
|
75
|
+
*/
|
|
76
|
+
static extractDirectionValue(match: SlotMatch): string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Extract time components from a TIME slot match
|
|
79
|
+
*/
|
|
80
|
+
static extractTimeValue(match: SlotMatch): {
|
|
81
|
+
hours: number;
|
|
82
|
+
minutes: number;
|
|
83
|
+
} | null;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=english-grammar-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"english-grammar-engine.d.ts","sourceRoot":"","sources":["../src/english-grammar-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,EACZ,mBAAmB,EAInB,SAAS,EACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,oBAAoB,EAA8C,MAAM,kBAAkB,CAAC;AACpG,OAAO,KAAK,EAAE,mBAAmB,EAAe,MAAM,iBAAiB,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GACtC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,kEAAkE;IAClE,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAClC;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD,OAAO,CAAC,oBAAoB,CAAuB;IAEnD,+DAA+D;IAC/D,OAAO,CAAC,YAAY,CAA6B;gBAErC,oBAAoB,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