mirror of https://github.com/apache/lucene.git
LUCENE-9805: Hunspell: fix space + mixed case heuristics on suggestions (#2420)
This commit is contained in:
parent
c61b458719
commit
381a5cacb0
|
@ -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);
|
||||||
|
|
|
@ -15,4 +15,8 @@ spite
|
||||||
inspire
|
inspire
|
||||||
Saiph
|
Saiph
|
||||||
sahib
|
sahib
|
||||||
ship
|
ship
|
||||||
|
ESP
|
||||||
|
esp
|
||||||
|
s
|
||||||
|
S
|
|
@ -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
|
|
@ -14,4 +14,5 @@ permqnent
|
||||||
permanent-vacation
|
permanent-vacation
|
||||||
permqnent-vacation
|
permqnent-vacation
|
||||||
ina
|
ina
|
||||||
Sahip
|
Sahip
|
||||||
|
ESPs
|
Loading…
Reference in New Issue