Skip to content

This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.

PhraseTrie

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

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:246

Number of unique first words (not total phrases).

number

addPhrase(phrase, tokenType): void;

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

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:286

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:262

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

The listing has no prototype, so it holds exactly its own entries: a phrase spelled __proto__ is listed rather than reaching the prototype setter and vanishing, and constructor or toString read back as the phrase’s token type, never as an inherited function.

Record<string, string>


matchAt(tokens, pos):
| NormalizerMatch
| null;

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

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