Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'list' object has no attribute 'lower' gensim

I have a list of 10k words in a text file like so:

G15 KDN C30A Action Standard Air Brush Air Dilution

I am trying to convert them into lower cased tokens using this code for subsequent processing with GenSim:

data = [line.strip() for line in open("C:\corpus\TermList.txt", 'r')]
texts = [[word for word in data.lower().split()] for word in data]

and I get the following callback:

AttributeErrorTraceback (most recent call last)
<ipython-input-84-33bbe380449e> in <module>()
      1 data = [line.strip() for line in open("C:\corpus\TermList.txt", 'r')]
----> 2 texts = [[word for word in data.lower().split()] for word in data]
      3 
AttributeError: 'list' object has no attribute 'lower'

Any suggestions on what I am doing wrong and how to correct it would be greatly appreciated!!! Thank you!!

like image 976
tom Avatar asked Jan 24 '17 13:01

tom


1 Answers

try:

data = [line.strip() for line in open("C:\corpus\TermList.txt", 'r')]
texts = [[word.lower() for word in text.split()] for text in data]

you were trying to apply .lower() to data, which is a list.
.lower() can only be applied to strings.

like image 124
epattaro Avatar answered Sep 30 '22 21:09

epattaro