Skip to content

Commit 1203f59

Browse files
committed
feat: infer leading period-abbreviations as titles in lastname-comma path (#109)
Complete the leading-title wiring across all three parse_full_name() paths. Update test_brute_force test16-18, which documented the old behavior for "Doe, John. A. Kenneth..." (unrecognized "John." parsed as first name); it's now correctly recognized as a leading title, same as the no-comma and suffix-comma paths.
1 parent 71d91a2 commit 1203f59

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

nameparser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ def parse_full_name(self) -> None:
10331033

10341034
if not self.first \
10351035
and (nxt or len(post_comma_pieces) == 1) \
1036-
and self.is_title(piece):
1036+
and self.is_leading_title(piece):
10371037
self.title_list.append(piece)
10381038
continue
10391039
if not self.first:

tests/test_brute_force.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,31 @@ def test15(self) -> None:
100100
self.m(hn.suffix, "III", hn)
101101

102102
def test16(self) -> None:
103+
# "John." is an unrecognized period-abbreviation in the leading
104+
# title position of the lastname-comma format, so is_leading_title()
105+
# now treats it as a title rather than a first name (see #109).
103106
hn = HumanName("Doe, John. A. Kenneth")
104-
self.m(hn.first, "John.", hn)
107+
self.m(hn.title, "John.", hn)
108+
self.m(hn.first, "A.", hn)
105109
self.m(hn.last, "Doe", hn)
106-
self.m(hn.middle, "A. Kenneth", hn)
110+
self.m(hn.middle, "Kenneth", hn)
107111

108112
def test17(self) -> None:
113+
# Same period-abbreviation-as-title behavior as test16 (see #109).
109114
hn = HumanName("Doe, John. A. Kenneth, Jr.")
110-
self.m(hn.first, "John.", hn)
115+
self.m(hn.title, "John.", hn)
116+
self.m(hn.first, "A.", hn)
111117
self.m(hn.last, "Doe", hn)
112-
self.m(hn.middle, "A. Kenneth", hn)
118+
self.m(hn.middle, "Kenneth", hn)
113119
self.m(hn.suffix, "Jr.", hn)
114120

115121
def test18(self) -> None:
122+
# Same period-abbreviation-as-title behavior as test16 (see #109).
116123
hn = HumanName("Doe, John. A. Kenneth III")
117-
self.m(hn.first, "John.", hn)
124+
self.m(hn.title, "John.", hn)
125+
self.m(hn.first, "A.", hn)
118126
self.m(hn.last, "Doe", hn)
119-
self.m(hn.middle, "A. Kenneth", hn)
127+
self.m(hn.middle, "Kenneth", hn)
120128
self.m(hn.suffix, "III", hn)
121129

122130
def test19(self) -> None:

tests/test_titles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,9 @@ def test_leading_period_abbreviation_suffix_comma(self) -> None:
285285
self.m(hn.first, "John", hn)
286286
self.m(hn.last, "Smith", hn)
287287
self.m(hn.suffix, "Jr.", hn)
288+
289+
def test_leading_period_abbreviation_lastname_comma(self) -> None:
290+
hn = HumanName("Smith, Major. John")
291+
self.m(hn.title, "Major.", hn)
292+
self.m(hn.first, "John", hn)
293+
self.m(hn.last, "Smith", hn)

0 commit comments

Comments
 (0)