I am trying extract a column of reviews from a dataset and storing in a file. Now I want to lemmatize this file into new file of lemmatized sentences

Viewed 13
    *lemmatizing this file into a new file of sentences*
    
    *#reviewtext.txt - contains all the reviews from a column of database
    #And I am trying to store the lemmatized sentences into lemma file*
    
    #storing the column values into "reviews"
  

reviews = df[df.columns[10]]

#write a file containing raw reviews
with open("reviewtext.txt", "w") as f:
  f.write("\n".join(reviews))

#creating a new file to store the lemmatized sentences
lemma_file = open("lemma_reviewtext.txt","w")

#initialize the Wordnet Lemamtizer
lemmatizer = WordNetLemmatizer()

file1 = open('reviewtext.txt','r')
lines = file1.readlines()

for line in lines:
  word_list = nltk.word_tokenize(line)
  lemmatized = ' '.join([lemmatizer.lemmatize(w) for w in word_list])
  lemma_file.write("\n".join(lemmatized))

Even though I am writing the lemmatized sentences to the lemmatized file, the file is still being empty. I am not sure where am I going wrong. Any suggestions please!

0 Answers
Related