T2: NameNormalizer testy + transliteratePolish, token-strip titles [checkpoint]
This commit is contained in:
+40
-8
@@ -20,12 +20,31 @@ public class NameNormalizer {
|
||||
public String makeSlug(String fullName) {
|
||||
String normalized = Normalizer.normalize(fullName, Normalizer.Form.NFKD);
|
||||
normalized = normalized.replaceAll("\\p{M}", "");
|
||||
normalized = normalized.replaceAll("[^a-zA-Z0-9\\s-]", " ");
|
||||
normalized = normalized.toLowerCase().replaceAll("\\s+", "-").replaceAll("-+", "-");
|
||||
normalized = normalized.replaceAll("[^\\p{L}\\s-]", "");
|
||||
normalized = transliteratePolish(normalized.toLowerCase());
|
||||
normalized = normalized.replaceAll("\\s+", "-").replaceAll("-+", "-");
|
||||
normalized = normalized.replaceAll("^-|-$", "");
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private String transliteratePolish(String input) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("ł", "l"); map.put("Ł", "l");
|
||||
map.put("ę", "e"); map.put("Ĕ", "e");
|
||||
map.put("ó", "o"); map.put("Ō", "o");
|
||||
map.put("ą", "a"); map.put("Ą", "a");
|
||||
map.put("ś", "s"); map.put("Ś", "s");
|
||||
map.put("ź", "z"); map.put("Ź", "z");
|
||||
map.put("ż", "z"); map.put("Ż", "z");
|
||||
map.put("ć", "c"); map.put("Ć", "c");
|
||||
map.put("ń", "n"); map.put("Ń", "n");
|
||||
String result = input;
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
result = result.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String extractFullName(String rawName) {
|
||||
return extractGivenAndFamilyNames(rawName);
|
||||
}
|
||||
@@ -62,12 +81,25 @@ public class NameNormalizer {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static final List<String> TITLE_PREFIXES = List.of(
|
||||
"prof. dr hab.", "prof.dr hab.", "prof. dr.", "prof. dr",
|
||||
"dr hab.", "dr.hab.", "dr. hab.", "dr.hab",
|
||||
"mgr inż.", "mgr inż", "mgr.inż.", "mgr.inż",
|
||||
"prof.", "prof", "dr.", "dr",
|
||||
"mgr.", "mgr", "inż.", "inż",
|
||||
"lek.", "lek.med.", "n. med.", "n. o zdr.",
|
||||
"licencjat inż.", "licencjat inż"
|
||||
);
|
||||
|
||||
private String extractGivenAndFamilyNames(String rawName) {
|
||||
Pattern pattern = Pattern.compile(
|
||||
"(?i)(prof\\.\\s*|dr\\s*hab\\.\\s*|dr\\.\\s*|mgr\\s*|in\u017c\\.\\s*)",
|
||||
Pattern.MULTILINE | Pattern.DOTALL
|
||||
);
|
||||
Matcher matcher = pattern.matcher(rawName);
|
||||
return matcher.replaceAll("").trim();
|
||||
String name = rawName.trim();
|
||||
String lower = name.toLowerCase();
|
||||
for (String prefix : TITLE_PREFIXES) {
|
||||
if (lower.startsWith(prefix.toLowerCase())) {
|
||||
name = name.substring(prefix.length()).trim();
|
||||
lower = name.toLowerCase();
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user