split(text) {
        const result = [];
        const n = text.length;
        let start = 0;
        let i = 0;

        while (i < n) {
            let node = this.trie;
            let match = null;
            let j = i;

            while (j < n && (node = node[text[j]])) {
                if (node.end) {
                    // Always keep the last (i.e., longest) match.
                    match = node.end;
                }
                ++j;
            }

            if (match) {
                if (i > start) {
                    result.push(text.slice(start, i));
                }
                result.push(match);
                i += match.length;
                start = i;
            } else {
                ++i;
            }
        }
        if (start < n) {
            result.push(text.slice(start));
        }
        return result;
    }
Splits the input text into tokens based on the dictionary.
@param {string} text The input text to split.
@returns {string[]} An array of tokens.