Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hunspell: don't proceed with other suggestions if we found good REP ones #13156

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ Improvements

* GITHUB#13155: Hunspell: allow ignoring exceptions on duplicate ICONV/OCONV mappings (Peter Gromov)

* GITHUB#13156: Hunspell: don't proceed with other suggestions if we found good REP ones (Peter Gromov)

Optimizations
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ private Suggestion capitalizeAfterSpace(String candidate) {

private boolean tryVariationsOf(String word) {
boolean hasGoodSuggestions = trySuggestion(word.toUpperCase(Locale.ROOT));
hasGoodSuggestions |= tryRep(word);

GradedSuggestions repResult = tryRep(word);
if (repResult == GradedSuggestions.Best) return true;

hasGoodSuggestions |= repResult == GradedSuggestions.Normal;

if (!speller.dictionary.mapTable.isEmpty()) {
enumerateMapReplacements(word, "", 0);
Expand Down Expand Up @@ -155,12 +159,20 @@ private boolean tryVariationsOf(String word) {
return hasGoodSuggestions;
}

private boolean tryRep(String word) {
private enum GradedSuggestions {
None,
Normal,
Best
}

private GradedSuggestions tryRep(String word) {
boolean hasBest = false;
int before = result.size();
for (RepEntry entry : speller.dictionary.repTable) {
for (String candidate : entry.substitute(word)) {
candidate = candidate.trim();
if (trySuggestion(candidate)) {
hasBest = true;
continue;
}

Expand All @@ -170,7 +182,8 @@ private boolean tryRep(String word) {
}
}
}
return result.size() > before;
if (hasBest) return GradedSuggestions.Best;
return result.size() > before ? GradedSuggestions.Normal : GradedSuggestions.None;
}

private void enumerateMapReplacements(String word, String accumulated, int offset) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
a lot
in spite, inspire
in spite
what
what
Wednesday
Wednesday
Wednesday
Wednesday
which, witch, winch, wish
which, witch
Oh, my gosh!
OH, MY GOSH!
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ a lot, lot
un alunno
bar
vinte e un
auto's, auto
auto's
art nouveau
nouveau