Esempio n. 1
0
def rawwordcloud(text, scale, width=150, height=80, POS=POS):
    t = time.time()
    tokenized = nltk.word_tokenize(text)
    tokenized = nltk.pos_tag(tokenized)
    text = []
    for token in tokenized:
        if token[1] in POS:
            text.append(token[0])
    text = ' '.join(text)
    t = timing(t, "generating texts")

    # Make wordcloud
    wordcloud = WordCloud(
        width=width, height=height, background_color='white',
        stopwords=stopwords, scale=scale)\
        .generate(text).to_array()
    t = timing(t, "generating wordcloud")

    # Make image
    img = Image.fromarray(wordcloud.astype('uint8'))
    timing(t, "generating image")
    return img