我想在文件中进行词干处理。当我在终端中使用它时它工作正常,但是当我将它应用到文本文件中时,它不起作用。终端代码:
print PorterStemmer().stem_word('complications')
功能代码:
def stemming_text_1():
with open('test.txt', 'r') as f:
text = f.read()
print text
singles = []
stemmer = PorterStemmer() #problem from HERE
for plural in text:
singles.append(stemmer.stem(plural))
print singles
输入test.txt
126211 crashes bookmarks runs error logged debug core bookmarks
126262 manual change crashes bookmarks propagated ion view bookmarks
期望/预期输出
126211 crash bookmark runs error logged debug core bookmark
126262 manual change crash bookmark propagated ion view bookmark
任何建议将不胜感激,谢谢:)