Skip to content

Commit 60a1dfd

Browse files
Fix lastname mistaken for postnominal
1 parent c32b06e commit 60a1dfd

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/main/java/com/tupilabs/human_name_parser/HumanNameParserBuilder.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ public HumanNameParserBuilder(Name name) {
137137
*/
138138
public HumanNameParserParser build() {
139139
if (this.salutations == null) {
140-
this.salutations = DEFAULT_SALUTATIONS;
140+
this.salutations = formatToRegex(DEFAULT_SALUTATIONS);
141141
}
142142
if (this.postnominals == null) {
143-
this.postnominals = DEFAULT_POSTNOMINALS;
143+
this.postnominals = formatToRegex(DEFAULT_POSTNOMINALS);
144144
}
145145
if (this.prefixes == null) {
146-
this.prefixes = DEFAULT_PREFIXES;
146+
this.prefixes = formatToRegex(DEFAULT_PREFIXES);
147147
}
148148
if (this.suffixes == null) {
149-
this.suffixes = DEFAULT_SUFFIXES;
149+
this.suffixes = formatToRegex(DEFAULT_SUFFIXES);
150150
}
151151
final HumanNameParserParser parser = new HumanNameParserParser(
152152
name,
@@ -159,6 +159,14 @@ public HumanNameParserParser build() {
159159
return parser;
160160
}
161161

162+
private List<String> formatToRegex(List<String> list) {
163+
List<String> regexList = new ArrayList<>();
164+
for (String s : list) {
165+
regexList.add(s.replace(".", "\\."));
166+
}
167+
return regexList;
168+
}
169+
162170
// salutations
163171

164172
public HumanNameParserBuilder withSalutations(List<String> salutations) {

src/test/java/com/tupilabs/human_name_parser/BuilderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ public void testExtraSalutations() {
141141
assertTrue(parser.salutations.contains("sinho"));
142142
}
143143

144+
@Test
145+
public void testLastNameNotMistakenForPostnominal() {
146+
HumanNameParserBuilder builder = new HumanNameParserBuilder("ruvin phidd");
147+
HumanNameParserParser parser = builder.build();
148+
assertTrue(parser.getFirst().contains("ruvin"));
149+
assertTrue(parser.getLast().contains("phidd"));
150+
}
151+
144152
// validations
145153

146154
@Test

0 commit comments

Comments
 (0)