简体   繁体   English

无法将词形还原词放入列表

[英]Trouble putting lemmatized words into a list

So I am working with a lemmatizer in Python, pystempel to be exact.所以我正在使用 Python 中的词形还原器,确切地说是pystempel And I am trying to lemmatize words in a text file and write the values all down in a list, so I can do some further work with the lemmatized list.我正在尝试对文本文件中的单词进行词形还原并将值全部写在一个列表中,这样我就可以对词形化列表做一些进一步的工作。 However, I can't get the lemmatizer to actually change the value of these words.但是,我无法让词形还原器实际更改这些单词的值。

import string
from stempel import StempelStemmer

stemmer = StempelStemmer.polimorf()

for word in *text file*:
 (stemmer.stem(word))

Something like this doesen't work because I think it just lemmatizes the words and does nothing else.像这样的东西是行不通的,因为我认为它只是使单词词形还原而没有其他作用。 Can someone help out and tell me how I could lemmatize each word from the text file and put them into a list that I can use later on?有人可以帮忙告诉我如何对文本文件中的每个单词进行词形还原并将它们放入我以后可以使用的列表中吗?

Strings are an immutable datatype, you cannot change their value.字符串是不可变的数据类型,您不能更改它们的值。 Your lemmatizer is probably returning a value that is the new string that has been lemmatized.您的 lemmatizer 可能会返回一个值,该值是已被词形化的新字符串。 You should probably take each lemmatized value and append it to a list.您可能应该获取每个词形还原值并将其附加到列表中。 Example:例子:

lemmatized = []
for word in text file: 
  lemmatized.append(stemmer.stem(word))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM