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

Renders typst code blocks in Obsidian into images using Typst through the power of WASM!
Renders typst code blocks in Obsidian into images using Typst through the power of WASM!

Obsidian Typst Renders typst code blocks into images using Typst through the power of WASM! This is still very much in development, so suggestions/bug

The easiest way to search for images on your desktop 🔎
The easiest way to search for images on your desktop 🔎

What is ByteDetective? ByteDetective is a desktop app (currently available for MacOS) that acts as a semantic search engine for your photos. The aim i

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

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