上下文
看看Wordle: http://www.wordle.net/ 它比我见过的任何其他词云生成器都好看得多 注意:源代码不可用-阅读常见问题:http://www.wordle.net/faq#code
我的问题
有没有一种算法可以做到Wordle所做的呢? 如果没有,有什么替代方案可以产生类似的输出?
我为什么问这个问题
只是好奇 想要学习
上下文
看看Wordle: http://www.wordle.net/ 它比我见过的任何其他词云生成器都好看得多 注意:源代码不可用-阅读常见问题:http://www.wordle.net/faq#code
我的问题
有没有一种算法可以做到Wordle所做的呢? 如果没有,有什么替代方案可以产生类似的输出?
我为什么问这个问题
只是好奇 想要学习
当前回答
这里看到我像云一样实现Wordle。 它使用相同的螺旋算法和四叉树数据结构。
http://sourcecodecloud.codeplex.com
or
http://www.codeproject.com/Articles/224231/Word-Cloud-Tag-Cloud-Generator-Control-for-NET-Win
其他回答
我是Wordle的创造者。以下是Wordle的实际工作原理:
数单词,扔掉无聊的单词,按数量排序,降序排列。保留前N个单词的N个,为每个单词分配与其计数成比例的字体大小。使用Java2D API为每个单词生成一个Java2D Shape。
每个单词“都想”在某个地方,比如“在垂直中心的某个随机x位置”。按照出现频率的递减顺序,对每个单词执行以下操作:
place the word where it wants to be
while it intersects any of the previously placed words
move it one step along an ever-increasing spiral
就是这样。困难的部分是如何有效地进行交叉测试,为此我使用了最后一次缓存、分层边界框和四叉树空间索引(所有这些都是您可以通过google了解更多的东西)。
编辑:正如Reto Aebersold指出的,现在有一本书的章节,免费提供,涵盖了同样的领域:美丽的可视化,第3章:Wordle
我创建了一个Silverlight组件,它使用Jonathan在这里建议的算法。源代码和示例项目都可以在我的博客上找到:
http://whydoidoit.com
我的云可以让你根据不同的权重为单词着色和大小,它支持单词选择(从坐标)和选中的单词高亮显示。源代码是您的,您可以根据需要使用。
这是一个非常好的javascript代码,来自Jason Davies,它使用了d3。你甚至可以使用web字体。
演示: http://www.jasondavies.com/wordcloud/
Github: https://github.com/jasondavies/d3-cloud
这里看到我像云一样实现Wordle。 它使用相同的螺旋算法和四叉树数据结构。
http://sourcecodecloud.codeplex.com
or
http://www.codeproject.com/Articles/224231/Word-Cloud-Tag-Cloud-Generator-Control-for-NET-Win
I've implemented a word cloud generator called WordCloud.jl in Julia language. A brief description about its algorithm can be found here. Unlike most other implementations, I designed it based on gradient optimization. It’s a non-greedy algorithm in which words can be further moved after they are positioned. Thus the size of the words and the shape and size of the background mask can be kept unchanged in the generation process. This makes the outputs more accurate and easy to customize. Furthermore, we can also generate some fancy outputs like these: Comparison of Obama's and Trump's inaugural address and Wikipedia: Julia