File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
main/java/com/tupilabs/human_name_parser
test/java/com/tupilabs/human_name_parser Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments