Skip to content

Commit

Permalink
AKR(Backend): Try to handle irregular capitalizations of Finnish town…
Browse files Browse the repository at this point in the history
… names better [deploy]
  • Loading branch information
pkoivisto committed Sep 25, 2024
1 parent 8ba5219 commit 8c08463
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ public Pair<String, String> translateTown(final String t, final boolean retainCa
if (t == null || t.isBlank()) {
return Pair.of("", "");
}
final String town = retainCase ? t : capitalize(t.toLowerCase());
if (fiToSv.containsKey(town)) {
return Pair.of(town, fiToSv.getOrDefault(town, town));
final String normalizedCase = capitalize(t.toLowerCase());
if (fiToSv.containsKey(normalizedCase)) {
return Pair.of(normalizedCase, fiToSv.getOrDefault(normalizedCase, normalizedCase));
} else if (svToFi.containsKey(normalizedCase)) {
return Pair.of(svToFi.getOrDefault(normalizedCase, normalizedCase), normalizedCase);
}

// If the normalized string wasn't found in translation maps,
// return the string itself, with either normalized or the original capitalization,
// depending on the source of the address.
if (retainCase) {
return Pair.of(t, t);
} else {
return Pair.of(normalizedCase, normalizedCase);
}
return Pair.of(svToFi.getOrDefault(town, town), town);
}

public Pair<String, String> translateTown(final String t) {
Expand Down

0 comments on commit 8c08463

Please sign in to comment.