3
我想用NLTK
检查python中某个句子的拼写。内置的spell checker
无法正常工作。它给with
和'和'作为错误的拼写。NLTK的拼写检查器无法正常工作
def tokens(sent):
return nltk.word_tokenize(sent)
def SpellChecker(line):
for i in tokens(line):
strip = i.rstrip()
if not WN.synsets(strip):
print("Wrong spellings : " +i)
else:
print("No mistakes :" + i)
def removePunct(str):
return "".join(c for c in str if c not in ('!','.',':',','))
l = "Attempting artiness With black & white and clever camera angles, the movie disappointed - became even more ridiculous - as the acting was poor and the plot and lines almost non-existent. "
noPunct = removePunct(l.lower())
if(SpellChecker(noPunct)):
print(l)
print(noPunct)
有人能给我理由吗?