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 =
result.stream().map(s -> capitalizeAfterSpace(low, s)).collect(Collectors.toList());
result.stream().map(s -> capitalizeAfterSpace(word, s)).collect(Collectors.toList());
result.clear();
result.addAll(adjusted);
}
}
// 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 tail = candidate.length() - space - 1;
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)
+ Character.toUpperCase(candidate.charAt(space + 1))
+ candidate.substring(space + 2);

View File

@ -16,3 +16,7 @@ inspire
Saiph
sahib
ship
ESP
esp
s
S

View File

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

View File

@ -15,3 +15,4 @@ permanent-vacation
permqnent-vacation
ina
Sahip
ESPs