LUCENE-9805: Hunspell: fix space + mixed case heuristics on suggestions (#2420)

This commit is contained in:
Peter Gromov 2021-02-23 13:00:02 +01:00 committed by GitHub
parent c61b458719
commit 381a5cacb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View File

@ -70,18 +70,18 @@ class ModifyingSuggester {
} }
List<String> adjusted = List<String> adjusted =
result.stream().map(s -> capitalizeAfterSpace(low, s)).collect(Collectors.toList()); result.stream().map(s -> capitalizeAfterSpace(word, s)).collect(Collectors.toList());
result.clear(); result.clear();
result.addAll(adjusted); result.addAll(adjusted);
} }
} }
// aNew -> "a New" (instead of "a new") // aNew -> "a New" (instead of "a new")
private String capitalizeAfterSpace(String lowMisspelled, String candidate) { private String capitalizeAfterSpace(String misspelled, String candidate) {
int space = candidate.indexOf(' '); int space = candidate.indexOf(' ');
int tail = candidate.length() - space - 1; int tail = candidate.length() - space - 1;
if (space > 0 if (space > 0
&& lowMisspelled.regionMatches(lowMisspelled.length() - tail, candidate, space + 1, tail)) { && !misspelled.regionMatches(misspelled.length() - tail, candidate, space + 1, tail)) {
return candidate.substring(0, space + 1) return candidate.substring(0, space + 1)
+ Character.toUpperCase(candidate.charAt(space + 1)) + Character.toUpperCase(candidate.charAt(space + 1))
+ candidate.substring(space + 2); + candidate.substring(space + 2);

View File

@ -15,4 +15,8 @@ spite
inspire inspire
Saiph Saiph
sahib sahib
ship ship
ESP
esp
s
S

View File

@ -13,3 +13,4 @@ McDonald
permanent permanent
in, in a in, in a
Saiph, Ship, Sahib Saiph, Ship, Sahib
ESP, ESP s, Esp, Esp s

View File

@ -14,4 +14,5 @@ permqnent
permanent-vacation permanent-vacation
permqnent-vacation permqnent-vacation
ina ina
Sahip Sahip
ESPs