Wordcloud use phrases rather than single words

懵懂的女人 提交于 2020-06-23 16:50:21

问题


I am generating a wordcloud image for single word and that works out fine. I want to generate the image for phrases. Their documentation states in the very first question that for 2 word phrases I need to use ~ to link them. I've tried this method linking my n lenght phrases but it still takes only 2 words in to consideration.

Is this the limit or there is a way to generate wordcloud with more than 2 word phrases?


wordcloud = WordCloud(
    width=1000,
    height=1000,
    background_color='black',
    stopwords=STOPWORDS).generate(str(text))
fig = plt.figure(
    figsize=(10, 10),
    facecolor='k',
    edgecolor='k')
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()

回答1:


It seems to have more to do with fitting the phrases into the cloud... if you play with https://www.wordclouds.com/ you can see that if a term is long AND frequent, the algorithm will have trouble to add into the cloud.

If you put a large concatenated word in the page, you may see this message in the corner:

with the following message:

The following words were not drawn:

very long phrase hard (13)

In order to make these words appear in your cloud, either shrink the word cloud, or lower the frequency of these words in the word list.

The same goes for doing it programaticaly.



来源:https://stackoverflow.com/questions/59567124/wordcloud-use-phrases-rather-than-single-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!