Skip to content

PhraseTrie

Defined in: packages/engine/src/normalizer/PhraseTrie.ts:92

Word-level trie for single-pass multi-word phrase matching.

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")] }
new PhraseTrie(): PhraseTrie;

PhraseTrie

get size(): number;

Defined in: packages/engine/src/normalizer/PhraseTrie.ts:212

Number of unique first words (not total phrases).

number

addPhrase(phrase, tokenType): void;

Defined in: packages/engine/src/normalizer/PhraseTrie.ts:114

Register a phrase for fusion into a single compound token.

ParameterTypeDescription
phrasestringMulti-word phrase (e.g., “to the power of”)
tokenTypestringTarget token type after fusion (e.g., “CARET”)

void


canStart(word): boolean;

Defined in: packages/engine/src/normalizer/PhraseTrie.ts:243

Check if any phrase starts with this word (case-insensitive).

ParameterType
wordstring

boolean


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).

Record<string, string>


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.

ParameterTypeDescription
tokensToken[]The current token stream
posnumberPosition to attempt matching from

| NormalizerMatch | null

The longest NormalizerMatch, or null on no match