https://github.com/inspirateur/wordcloud-rs
Rust library to generate word cloud images from text and images !
https://github.com/inspirateur/wordcloud-rs
rust rust-crate rust-library wordcloud wordcloud-generator wordcloud-visualization
Last synced: 6 months ago
JSON representation
Rust library to generate word cloud images from text and images !
- Host: GitHub
- URL: https://github.com/inspirateur/wordcloud-rs
- Owner: Inspirateur
- License: unlicense
- Created: 2022-12-04T17:09:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-22T10:24:51.000Z (9 months ago)
- Last Synced: 2025-03-27T17:37:32.613Z (6 months ago)
- Topics: rust, rust-crate, rust-library, wordcloud, wordcloud-generator, wordcloud-visualization
- Language: Rust
- Homepage: https://crates.io/crates/wordcloud-rs
- Size: 3.58 MB
- Stars: 14
- Watchers: 1
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wordcloud-rs
A Rust library to generate word-clouds from text and images!## Example
### Code
```rust
use std::collections::HashMap;
use std::fs;
use lazy_static::lazy_static;
use regex::Regex;
use wordcloud_rs::*;lazy_static! {
static ref RE_TOKEN: Regex = Regex::new(r"\w+").unwrap();
}fn tokenize(text: String) -> Vec<(Token, f32)> {
let mut counts: HashMap = HashMap::new();
for token in RE_TOKEN.find_iter(&text) {
*counts.entry(token.as_str().to_string()).or_default() += 1;
}
counts.into_iter().map(|(k, v)| (Token::Text(k), v as f32)).collect()
}fn main() {
// Prepare the tokens
let text = fs::read_to_string("assets/sample_text.txt").unwrap();
let mut tokens = tokenize(text);
tokens.push((Token::from("assets/alan_turing.jpg"), 15.));
tokens.push((Token::from("assets/turing_statue_bletchley.jpg"), 20.));
tokens.push((Token::Text("💻".to_string()), 20.));
// Generate the word-cloud
let wc = WordCloud::new().generate(tokens);
// Save it
wc.save("sample_cloud.png").unwrap();
}
```
### Output
