GitHub - Saphereye/symspellrs: Rust compile time library for symspell fuzzy spell checking algorithm (original) (raw)

Crates.io Docs.rs

A compact Rust library implementing a SymSpell-style fuzzy-word suggestion algorithm. It supports two primary modes:

This README contains quick usage commands, example snippets and developer commands.

Quick commands

Simple usage examples

These small snippets show the most common usage patterns. See examples/simple_usage.rsfor a complete runnable example.

  1. Compile-time embedding (recommended when your dictionary is static)

The include_dictionary! proc-macro reads a dictionary file at compile time (path is evaluated relative to the crate root) and returns a ready-to-use value (when precompute = true you get an EmbeddedSymSpell-like value backed by phf statics; otherwise the macro constructs a runtime SymSpell).

use symspellrs::include_dictionary; use symspellrs::Verbosity;

// Read tests/data/words.txt at compile time and build a ready value. let sym = include_dictionary!("tests/data/words.txt", max_distance = 2, lowercase = true);

// Query the embedded instance: let maybe_best = sym.find_top("helo"); // Option let closest = sym.lookup("helo", 2, Verbosity::Closest);

  1. Runtime construction (dynamic dictionaries)

If you load dictionaries from the network, a database, or need to modify them at runtime, use SymSpell::from_iter or SymSpell::load_iter:

use symspellrs::{SymSpell, Verbosity};

let entries = vec![ ("hello".to_string(), 3usize), ("world".to_string(), 5usize), ];

let sym = SymSpell::from_iter(2, entries); let results = sym.lookup("helo", 2, Verbosity::Top);

Examples