我正在尝试检查一个单词是否是英文单词。不确定这是否是最好的方法,有什么建议吗?它不想工作。from nltk import wordnetword_to_test = input("Please enter a word: ")if not wordnet.synsets(word_to_test): print("FALSE") #not english wordelse: print("TRUE")
1 回答

慕村9548890
TA贡献1884条经验 获得超4个赞
使用以下代码:
from nltk.corpus import wordnet
withwordnet.synsets
没有成功识别英文单词。中的所有单词都
word_list
标识为True
成功识别一个英文单词,取决于使用的词典。
from nltk.corpus import words
def check_words(word_list: list):
for word in word_list:
print(word in words.words())
word_list = ['poisson', 'stark', 'nihongo', 'abstract', 'pedo']
输出:
check_words(word_list)
False
True
False
True
False
添加回答
举报
0/150
提交
取消