Skip to main content

Module suggest

Module suggest 

Source
Expand description

Spelling suggestions for unknown words.

This module provides fuzzy matching to suggest corrections for misspelled words in the input. It uses Levenshtein distance to find similar words from a known vocabulary list.

When the parser encounters an unknown word, this module can suggest “Did you mean X?” alternatives based on edit distance.

Constants§

KNOWN_WORDS

Functions§

did_you_mean
The candidate an author most likely meant by word — the nearest by edit distance, compared case-insensitively, when it is within a third of the word’s length (at least one edit). The first of equally near candidates wins, so a caller that lists candidates in a stable order gets a stable answer. word itself never counts as a suggestion for itself.
find_similar
levenshtein
Compute the Levenshtein edit distance between two strings.
typo_distance
Edit distance where swapping two adjacent characters is one edit (the optimal string alignment distance) — the typo a fast typist makes most (doen for done), which plain Levenshtein counts as two.