Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trouble putting lemmatized words into a list

So I am working with a lemmatizer in Python, pystempel to be exact. 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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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. 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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading