PhraseTrie
Defined in: packages/engine/src/normalizer/PhraseTrie.ts:92
Word-level trie for single-pass multi-word phrase matching.
Example
Section titled “Example”const trie = new PhraseTrie();trie.addPhrase("to the power of", "CARET");trie.addPhrase("power of", "CARET");trie.addPhrase("abyssal whip", "ITEM");
// At position 0 with tokens ["to","the","power","of","3"]const match = trie.matchAt(tokens, 0);// → { consumed: 4, replacement: [CARET("to the power of")] }Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PhraseTrie(): PhraseTrie;Returns
Section titled “Returns”PhraseTrie
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size(): number;Defined in: packages/engine/src/normalizer/PhraseTrie.ts:212
Number of unique first words (not total phrases).
Returns
Section titled “Returns”number
Methods
Section titled “Methods”addPhrase()
Section titled “addPhrase()”addPhrase(phrase, tokenType): void;Defined in: packages/engine/src/normalizer/PhraseTrie.ts:114
Register a phrase for fusion into a single compound token.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
phrase | string | Multi-word phrase (e.g., “to the power of”) |
tokenType | string | Target token type after fusion (e.g., “CARET”) |
Returns
Section titled “Returns”void
canStart()
Section titled “canStart()”canStart(word): boolean;Defined in: packages/engine/src/normalizer/PhraseTrie.ts:243
Check if any phrase starts with this word (case-insensitive).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
word | string |
Returns
Section titled “Returns”boolean
getAllPhrases()
Section titled “getAllPhrases()”getAllPhrases(): Record<string, string>;Defined in: packages/engine/src/normalizer/PhraseTrie.ts:223
Return all registered phrases and their target token types.
Used by diagnostic mode to expose the complete trie structure to the playground’s NormalizerTab for rendering ALL registered phrases (not just the ones that matched in this evaluation).
Returns
Section titled “Returns”Record<string, string>
matchAt()
Section titled “matchAt()”matchAt(tokens, pos): | NormalizerMatch | null;Defined in: packages/engine/src/normalizer/PhraseTrie.ts:161
Attempt to match a phrase starting at pos in the token stream.
Walks the trie one token at a time, tracking the deepest terminal
node reached. Returns the longest match found, or null if no
phrase starts at this position.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tokens | Token[] | The current token stream |
pos | number | Position to attempt matching from |
Returns
Section titled “Returns”| NormalizerMatch
| null
The longest NormalizerMatch, or null on no match