SpellingSuggestions.h header

#include <ew/app/SpellingSuggestions.h>

Namespace ew::app

Functions

int ew::app::boundedEditDistance(QStringView a, QStringView b, int cutoff)

The bounded optimal-string-alignment (restricted Damerau–Levenshtein) distance between a and b — counting a swap of two adjacent characters as one edit — capped at cutoff: the result is the true distance when it is <= cutoff, otherwise exactly cutoff + 1. Bounding lets it early-exit. Comparison is on the code points as given (callers lower-case first).

QStringList ew::app::dictionaryEditCandidates(const QString &word, const std::function< bool(const QString &)> &accept)

Generates the real words within a small edit distance of word by the generate-and-test method (Norvig): it forms every one-edit variant of word over the ASCII letters and apostrophe and keeps those accept reports as real; if none are within one edit it widens to two. Because it enumerates edits of the word (a few hundred to a few hundred-thousand strings) and only probes accept — never scans the dictionary — its cost depends on the word length, not the dictionary size, so it stays responsive against a 370k-word list. Returns the accepted words (lower-cased, de-duplicated, unranked); rank them with rankSuggestions.

QStringList ew::app::rankSuggestions(const QString &word, const QStringList &candidates, int maxResults=7)

Ranks candidates as replacements for word (best first, up to maxResults) WITHOUT filtering them — every candidate is assumed already close (e.g. from dictionaryEditCandidates). Order: fewest edits, then the smallest change to the letter multiset (so a transposition such as teh→the outranks a substitution such as teh→tea), then a longer shared prefix, then a closer length, then alphabetical. Each result carries word's Title-/ALL-CAPS casing unless the candidate is itself capitalised (a proper noun such as a codex name).

int ew::app::spellingSuggestionCutoff(int wordLength)

The maximum number of edits (substitution, insertion, deletion, or adjacent transposition) a suggestion may be from wordLength characters of typed text: 1 for short words, 2 for longer ones. Kept public so a caller can length-pre-filter a candidate set with the same threshold spellingSuggestions() applies.

QStringList ew::app::spellingSuggestions(const QString &word, const QStringList &candidates, int maxResults=7)

Ranks the candidates closest to word and returns up to maxResults, best first, for a "did you mean" menu — this is rankSuggestions restricted to candidates within the edit cutoff (spellingSuggestionCutoff), so it suits an arbitrary candidate list (e.g. codex names). An empty word yields nothing.