Longest Match Tokenizer
Asked at Google
Reported by the problem's creator, not verified
You are given a string text and a dictionary that maps words to integer ids.
Examples
Example 1
Input:
{"text":"theater","dictionary":{"a":3,"the":1,"theater":2}}Output:
[2]Explanation: Both
theandtheaterstart at position 0, andtheateris longer, so the result is its id alone.Example 2
Input:
{"text":"the theater is a","dictionary":{"a":3,"the":1,"theater":2}}Output:
[1," ",2," ","i","s"," ",3]Explanation:
thegives 1, the space matches nothing and stays as" ",theatergives 2, then the space,iandsand another space stay as characters, andagives 3.Example 3
Input:
{"text":"abcx","dictionary":{"c":3,"ab":1,"abcd":2}}Output:
[1,3,"x"]Explanation:
abcdwould be the longest word at position 0, but the text there isabcx, so the longest word that matches isab. Thencmatches, andxmatches nothing.