19 package org.turro.jpa.embeddables;
21 import java.io.Serializable;
22 import java.util.List;
23 import javax.persistence.Embeddable;
24 import org.apache.commons.text.WordUtils;
25 import org.turro.names.NamesDB;
26 import org.turro.string.Strings;
35 private String informal, formal, full;
42 this.informal = informal;
64 if(!Strings.isBlank(informal))
return getInformal();
69 if(!Strings.isBlank(formal))
return getFormal();
75 public void guessFrom(String name,
boolean entity) {
76 if(entity || isJuridical(name)) {
77 setFull(Strings.normalize(name));
81 String first = NamesDB.firstName(Strings.normalize(name));
82 if(!Strings.isBlank(first)) {
87 String surname = firstSurname(remaining);
88 if(!Strings.isBlank(surname)) {
97 private final static List<String> connectives = List.of(
"del",
"de",
"van",
"von",
"i");
98 private final static List<String> juridicals = List.of(
",",
".");
100 private void normalize() {
101 full = Strings.normalize(full);
102 informal = Strings.normalize(informal);
103 formal = Strings.normalize(formal);
106 private String capitalize(String name) {
107 String capitalized = Strings.normalize(WordUtils.capitalizeFully(name,
' ',
'.',
'-'));
108 for(String connective : connectives) {
109 capitalized = capitalized.replaceAll(
110 " " + WordUtils.capitalizeFully(connective) +
" ",
111 " " + connective +
" ");
116 private String firstSurname(String text) {
117 for(String connective : connectives) {
118 if(text.toLowerCase().startsWith(connective +
" ")) {
119 return Strings.untilFirst(text,
" ", connective.length() + 1);
122 return Strings.untilFirst(text,
" ");
125 private boolean isJuridical(String name) {
126 for(String juridical : juridicals) {
127 if(name.toLowerCase().contains(juridical))
return true;
void setInformal(String informal)
void guessFrom(String name, boolean entity)
void setFull(String full)
void setFormal(String formal)