我遇到的问题是,在我的代码中,我无法让单个单词/标记与要从原始文本中删除的停止词匹配。相反,我得到了一个完整的句子,因此无法将其与停止词匹配。请告诉我一种方法,我可以通过它获得单个令牌,然后将这些令牌与停止词匹配并删除它们。请帮帮我。
from nltk.corpus import stopwords
import string, os
def remove_stopwords(ifile):
processed_word_list = []
stopword = stopwords.words("urdu")
text = open(ifile, 'r').readlines()
for word in text:
print(word)
if word not in stopword:
processed_word_list.append('*')
print(processed_word_list)
return processed_word_list
if __name__ == "__main__":
print ("Input file path: ")
ifile = input()
remove_stopwords(ifile)