【发布时间】:2019-09-08 19:38:35
【问题描述】:
我为 python 的“NLTK”库下载了“words”和“wordnet”:
import nltk
from nltk.corpus import words
from nltk.corpus import wordnet
nltk.download('words')
nltk.download('wordnet')
检查列表中的单词是否为英文。
但是,在运行脚本时,它无法将任何单词识别为英语。
这是我的脚本:
samplewords=['accident scene','a%32','j & quod','accident season','academic discount','academic diary','academic dictionary']
for word in samplewords:
if word in words.words():
print('English',word)
else:
print('Not English',word)
for word in samplewords:
if not wordnet.synsets(word):
print('Not english',word)
else:
print('English',word)
这是我对上述两个方面的收获:
Not english accident scene
Not english a%32
Not english j & quod
Not english accident season
Not english academic discount
Not english academic diary
Not english academic dictionary
我的预期结果:
English accident scene
Not english a%32
Not english j & quod
English accident season
English academic discount
English academic diary
English academic dictionary
如何确保图书馆识别出这些是英文单词?
【问题讨论】:
标签: python python-3.x nltk