我一直在玩各种模块(例如PyEnchant),我想做的是确定一个字符串是否是一个英文单词的开头。例如
Smo -> Smoke
A x -> x-ray
Elx -> NULL
Don -> Done
Brj -> NULL
Bes -> Besiege
Nix -> Nixed
但我不确定是否有办法做到这一点,而无需创建和加载我自己的单词列表。
我一直在玩各种模块(例如PyEnchant),我想做的是确定一个字符串是否是一个英文单词的开头。例如
Smo -> Smoke
A x -> x-ray
Elx -> NULL
Don -> Done
Brj -> NULL
Bes -> Besiege
Nix -> Nixed
但我不确定是否有办法做到这一点,而无需创建和加载我自己的单词列表。
Python does not ship with it's own word list, so you would have to load it from somewhere (whether it's a common dictionary, a custom list, etc.).
Now I'm not sure about PyEnchant, but the easiest way to then do this is to create a Trie structure within Python as then checking if a word exists is as easy as going through graph nodes till either you hit a null (return False for word existing with that prefix) or you hit the last character in your search string (return True for word existing with that prefix.) A sample on making a Trie can be found in this thread.