实现Wordle之类的词云的算法 [英] Algorithm to implement a word cloud like Wordle

查看:33
本文介绍了实现Wordle之类的词云的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 是否有可用的算法来执行 Wordle 的功能?
  • 如果不是,有哪些替代品可以产生类似的输出?
  • 只是好奇
  • 想学习

推荐答案

我是 Wordle 的创建者.Wordle 的实际工作方式如下:

I'm the creator of Wordle. Here's how Wordle actually works:

统计单词,扔掉无聊的单词,按计数降序排序.保留一些 N 的前 N ​​个单词.为每个单词分配与其计数成比例的字体大小.使用 Java2D API 为每个单词生成一个 Java2D Shape.

Count the words, throw away boring words, and sort by the count, descending. Keep the top N words for some N. Assign each word a font size proportional to its count. Generate a Java2D Shape for each word, using the Java2D API.

每个词希望"在某处,例如在垂直中心的某个随机 x 位置".按频率降序,对每个单词执行此操作:

Each word "wants" to be somewhere, such as "at some random x position in the vertical center". In decreasing order of frequency, do this for each word:

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

就是这样.困难 部分是有效地进行交叉测试,为此我使用了最后一次命中缓存、分层边界框和四叉树空间索引(所有这些都是你可以通过一些勤奋的谷歌搜索).

That's it. The hard part is in doing the intersection-testing efficiently, for which I use last-hit caching, hierarchical bounding boxes, and a quadtree spatial index (all of which are things you can learn more about with some diligent googling).

正如 Reto Aebersold 所指出的,现在有一本书的章节,免费提供,涵盖了同一领域:美丽的可视化,第 3 章:Wordle

As Reto Aebersold pointed out, there's now a book chapter, freely available, that covers this same territory: Beautiful Visualization, Chapter 3: Wordle

这篇关于实现Wordle之类的词云的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆