0

I want to generate word clouds of different part of speech of text. The problem I face is that I don't want to tune the parameters myself for each of them. Moreover, since I am running this on a number of docs, it is very tedious to do so for each. Is there an automated approach?

    max_w=max(len(verbs),len(adjectives),len(adverbs),len(nouns))
    word_cloud_generator("verbs",verbs,description,len(verbs)/max_w)
    word_cloud_generator("adjectives",adjectives,description,len(adjectives)/max_w)
    word_cloud_generator("adverbs",adverbs,description,len(adverbs)/max_w)
    word_cloud_generator("nouns",nouns,description,len(nouns)/max_w)

    def word_cloud_generator(part,data,description,scale):
        TEXT= " ".join(data)
        xlim=600*(scale)
        ylim=600*(scale)
        max_size= 200*(scale)
        min_size=2*(scale)
        threshold=4*(scale)
        tags = make_tags(get_tag_counts(TEXT), maxsize=max_size,minsize=min_size)
        tags=[a for a in tags if a['size'] > threshold]
        filename=description+ "_"+part+'.png'
        create_tag_image(tags,filename , size=(xlim, ylim), fontname='Molengo', \
            background=(0,0,0),rectangular=True)

Please help.

Edit: The above code tries to select word cloud parameters depending upon the number of words in the text. But the results I get aren't efficent enough. By efficiency I mean an uncluttered and non overlapping word cloud with reasonable image size.

Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142
  • Please clarify what you code does, and what you need help with. Is there an automated approch to do *what* ? What you have there looks plenty automated already – Stiffo Aug 07 '15 at 14:28
  • @Stiffo Thanks for reply! Sorry for not explaining before. Please check now. – Abhishek Bhatia Aug 07 '15 at 14:40
  • 1
    Don't know how to help you in a reasonable amount of time, you might try and check out a similar python project: https://github.com/amueller/word_cloud – Stiffo Aug 07 '15 at 14:44
  • http://stackoverflow.com/questions/29264410/creating-word-cloud-in-python-making-words-different-sizes and http://stackoverflow.com/questions/16645799/how-to-create-a-word-cloud-from-a-corpus-in-python – alvas Aug 07 '15 at 15:19
  • @Stiffo Thanks! This seems to work better. Just one question when using `wordcloud = WordCloud(width=1600, height=800).generate(TEXT)` does it remove the common words or should I use process_text http://amueller.github.io/word_cloud/generated/wordcloud.WordCloud.html#wordcloud.WordCloud.process_text – Abhishek Bhatia Aug 07 '15 at 15:29
  • Sorry, but no idea. I've never used it. You'll need to try your way or try to read any documentation on the page – Stiffo Aug 10 '15 at 07:26

0 Answers0