// attractors: map of words (lower case) to number of changes allowed static S levenAttract(Map attractors, S text) { L tok = javaTok(text); for (int i = 1; i < l(tok); i += 2) { S t = tok.get(i); if (!startsWithLetter(t)) continue; tok.set(i, levenAttract_word(attractors, t)); } ret join(tok); } static S levenAttract_word(Map attractors, S word) { word = toLower(word); if (attractors.containsKey(word)) ret word; S best = null; int bestScore = 1000; for (S attractor : keys(attractors)) { int limit = attractors.get(attractor); int diff = leven_limited(attractor, word, min(limit+1, bestScore)); if (diff <= limit && diff < bestScore) { best = attractor; bestScore = diff; } } ret or(best, word); }