Rust library to generate word cloud images from text and images !

Overview

wordcloud-rs

A Rust library to generate word-clouds from text and images!

Example

Code

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<String, usize> = 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::Img("assets/alan_turing.jpg".to_string()), 60.));
    tokens.push((Token::Img("assets/turing_statue_bletchley.jpg".to_string()), 80.));
    tokens.push((Token::Img("assets/computer_emoji.png".to_string()), 40.));
    // Generate the word-cloud
    let wc = WordCloud::new().generate(tokens);
    // Save it
    wc.save("sample_cloud.png").unwrap();
}

Output

word_cloud_demo

You might also like...
A set of bison skeleton files that can be used to generate a Bison grammar that is written in Rust.

rust-bison-skeleton A set of bison skeleton files that can be used to generate a Bison grammar that is written in Rust. Technically it's more like a B

Rust macro that uses GPT3 codex to generate code at compiletime

gpt3_macro Rust macro that uses GPT3 codex to generate code at compiletime. Just describe what you want the function to do and (optionally) define a f

Generate Rust register maps (`struct`s) from SVD files

svd2rust Generate Rust register maps (structs) from SVD files This project is developed and maintained by the Tools team. Documentation API Minimum Su

📝 Generate your README.md from Rust doc comments

cargo-onedoc 📝 Generate README.md from doc comments. Only write your documentation once! This crate provides a Cargo subcommand that can generate Mar

Generate an SPDX Software Bill of Materials for Rust crates.

cargo-spdx cargo-spdx is currently in development and not yet ready for use. cargo-spdx provides a cargo subcommand to generate an SPDX Software Bill

Generate short, memorable phrases for throw-away names.

Generates three-word phrases of the form intensifier-adjective-noun, just like GitHub default repo names.

Generate a THIRDPARTY file with all licenses in a cargo project.

cargo-bundle-licenses Bundle all third-party licenses into a single file. NOTE This tools is not a lawyer and no guarantee of correctness can be made

Generate alerts for when metrics/recordings become absent

prometheus-absent-data-alert-rule-generator prometheus-absent-data-alert-rule-generator is a tool to generate alerts for missing data in time-series t

Generate an HTML page based on a Notion document

Notion Generator Generate an HTML page based on a Notion document! Still a bit of a work in progress, but I am about to actually use it for some actua

Owner
Teo Orthlieb
machine learning, data visualisation and hobbyist game dev
Teo Orthlieb
Output the individual word-count statistics from a set of files

Output the individual word-count statistics from a set of files, or generate a curated word list

Johnny Tidemand Vestergaard 1 Apr 3, 2022
Rust Shop is a fake cloud-based software company that you can fork.

RustShop RustShop is an attempt at building a template and utilities to help quickly set up and manage a production grade cloud-based system. The core

null 56 Dec 17, 2022
dbt Cloud™️ infrastructure-as-code that is friendly to analysts

dbterra dbt Cloud ™️ infrastructure-as-code that is friendly to analysts, bizops, etc Motivation While there are Terraform ™️ plugins that can be used

Instawork 6 May 2, 2023
UnlimCloud provides unlimited cloud storage for your files, utilizing Telegram as the storage solution

UnlimCloud provides unlimited cloud storage for your files, utilizing Telegram as the storage solution. Simply log in using your Telegram ID, and you are good to go.

inulute 5 Nov 27, 2023
Small library for text to image steganography.

hips-lib Performs text to image steganography by hinding and retrieving secret text within images or pixel arrays. This is achieved by encoding the se

hewhocopypastes 4 Feb 21, 2023
Generate bindings to use Rust code in Qt and QML

Rust Qt Binding Generator This code generator gets you started quickly to use Rust code from Qt and QML. In other words, it helps to create a Qt based

KDE GitHub Mirror 768 Dec 24, 2022
Used to generate and compare bounded timestamps.

ClockBound Summary: ClockBound allows you to generate and compare bounded timestamps that include accumulated error as reported from the local chronyd

Amazon Web Services 149 Nov 28, 2022
Generate commit messages using GPT3 based on your changes and commit history.

Commit Generate commit messages using GPT-3 based on your changes and commit history. Install You need Rust and Cargo installed on your machine. See t

Brian Le 40 Jan 3, 2023
"Philips Ambilight for desktops". A tool to generate color palettes from your desktop wallpaper and send them to Home Assistant.

Desktop Dye DesktopDye is an open source project written in Rust that allows users to have their lights paired with Home Assistant adjust to the most

Jeroen Meijer (Jay) 7 Feb 22, 2023
Ruplacer - Find and replace text in source files

Ruplacer - Find and replace text in source files

Dimitri Merejkowsky 331 Dec 28, 2022