python 3.x - AttributeError: 'str' object has no attribute 'words' -


i'm using python34. want frequency of words csv file show error. here code.anyone me solve problem.

from textblob import textblob tb import math  words={} def tfidf(word, blob, bloblist):     return tf(word, blob) * idf(word, bloblist)  def tf(word, blob):     return blob.words.count(word) / len(blob.words)  def n_containing(word, bloblist):     return sum(1 blob in bloblist if word in blob)  def idf(word, bloblist):     return math.log(len(bloblist) / (1 + n_containing(words, bloblist)))  bloblist = open('afterstopwords.csv', 'r').read()  i, blob in enumerate(bloblist):      print("top words in document {}".format(i + 1))      scores = {word: tfidf(word, blob, bloblist) word in blob.words}      sorted_words = sorted(scores.items(), key=lambda x: x[1], reverse=true)      word, score in sorted_words[:3]:          print("\tword: {}, tf-idf: {}".format(word, round(score, 5))) 

and error is:

 top words in document 1  traceback (most recent call last):  file "d:\python34\tfidf.py", line 45, in <module>     scores = {word: tfidf(word, blob, bloblist) word in blob.words}  attributeerror: 'str' object has no attribute 'words' 

from http://stevenloria.com/finding-important-words-in-a-document-using-tf-idf/ of code bloblist is:

bloblist = [document1, document2, document3] 

don't change it. plus, preceding code documents like:

document1 = tb("""blablabla""") 

here's did...i use function opening files in python, openfile holds file details.

txt =openfile()   document1=tb(txt)   bloblist = [document1]  

the rest of original code unchanged. works have been able finish small files. takes long larger files. , doesn't accurate @ all. word count use https://rmtheis.wordpress.com/2012/09/26/count-word-frequency-with-python/
, has worked 9999 rows each being 50-75 characters long. seems accurate too, results seem equivalent wordcloud results.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -