我试着从课文中删除非英语单词。问题:在NLTK语料库中,还有许多词是不存在的。
我的代码:
import pandas as pd
lst = ['I have equipped my house with a new [xxx] HP203X climatisation unit']
df = pd.DataFrame(lst, columns=['Sentences'])
import nltk
nltk.download('words')
words = set(nltk.corpus.words.words())
df['Sentences'] = df['Sentences'].apply(lambda x: " ".join(w for w in nltk.wordpunct_tokenize(x) if w.lower() in (words)))
df输入:I have equipped my house with a new [xxx] HP203X climatisation unit
结果:I have my house with a new unit
应该是:I have equipped my house with a new climatisation unit
我不知道如何完成nltk.corpus.words.words(),以避免像equipped,climatisation这样的词从句子中被改写。
发布于 2022-05-12 09:41:04
您可以使用
words.update(['climatisation', 'equipped'])在这里,words是一个集合,这就是为什么.extend(word_list)不能工作。
https://stackoverflow.com/questions/72099620
复制相似问题