Skip to content

Commit 1cbd161

Browse files
committed
fix #3, handle suffix in last name part of last name comma format
1 parent b45db37 commit 1cbd161

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
# The short X.Y version.
5959
version = nameparser.__version__
6060
# The full version, including alpha/beta/rc tags.
61-
release = '0.3.2'
61+
release = '0.3.3'
6262

6363
# The language for content autogenerated by Sphinx. Refer to documentation
6464
# for a list of supported languages.

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ approach. It's not perfect, but it gets you pretty far.
2929
Supports 3 different comma placement variations in the input string.
3030

3131
* Title Firstname "Nickname" Middle Middle Lastname Suffix
32-
* Lastname, Title Firstname (Nickname) Middle Middle[,] Suffix [, Suffix]
32+
* Lastname [Suffix], Title Firstname (Nickname) Middle Middle[,] Suffix [, Suffix]
3333
* Title Firstname M Lastname [Suffix], Suffix [, Suffix]
3434

3535
When there is ambiguity that cannot be resolved by a rule-based approach,

nameparser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (0, 3, 2)
1+
VERSION = (0, 3, 3)
22
__version__ = '.'.join(map(str, VERSION))
33
__author__ = "Derek Gulbranson"
44
__author_email__ = '[email protected]'

nameparser/parser.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from __future__ import unicode_literals
33

44
import logging
5-
from nameparser.util import u
6-
from nameparser.util import text_type
7-
from nameparser.util import lc
8-
from nameparser.config import CONSTANTS
9-
from nameparser.config import Constants
5+
from .util import u
6+
from .util import text_type
7+
from .util import lc
8+
from .config import CONSTANTS
9+
from .config import Constants
1010

1111
# http://code.google.com/p/python-nameparser/issues/detail?id=10
1212
log = logging.getLogger('HumanName')
@@ -374,6 +374,7 @@ def parse_full_name(self):
374374
if len(parts) == 1:
375375

376376
# no commas, title first middle middle middle last suffix
377+
# part[0]
377378

378379
pieces = self.parse_pieces(parts)
379380

@@ -403,6 +404,7 @@ def parse_full_name(self):
403404
if self.is_suffix(parts[1]):
404405

405406
# suffix comma: title first middle last [suffix], suffix [, suffix]
407+
# parts[0], parts[1:...]
406408

407409
self.suffix_list += parts[1:]
408410

@@ -431,12 +433,20 @@ def parse_full_name(self):
431433
self.middle_list.append(piece)
432434
else:
433435

434-
# lastname comma: last, title first middles[,] suffix [,suffix]
436+
# lastname comma: last [suffix], title first middles[,] suffix [,suffix]
437+
# parts[0], parts[1], parts[2:...]
435438
pieces = self.parse_pieces(parts[1].split(' '), 1)
436439

437440
log.debug("pieces: {0}".format(u(pieces)))
438441

439-
self.last_list.append(parts[0])
442+
# lastname part may have suffixes in it
443+
lastname_pieces = self.parse_pieces(parts[0].split(' '), 1)
444+
for piece in lastname_pieces:
445+
if self.is_suffix(piece):
446+
self.suffix_list.append(piece)
447+
else:
448+
self.last_list.append(piece)
449+
440450
for i, piece in enumerate(pieces):
441451
try:
442452
nxt = pieces[i + 1]

tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ def test_assume_suffix_title_and_one_other_name_is_last_name(self):
156156
hn = HumanName("Andrews, M.D.")
157157
self.m(hn.suffix, "M.D.", hn)
158158
self.m(hn.last, "Andrews", hn)
159-
159+
160+
def test_suffix_in_lastname_part_of_lastname_comma_format(self):
161+
hn = HumanName("Smith Jr., John")
162+
self.m(hn.last, "Smith", hn)
163+
self.m(hn.first, "John", hn)
164+
self.m(hn.suffix, "Jr.", hn)
165+
160166
def test_sir_exception_to_first_name_rule(self):
161167
hn = HumanName("Sir Gerald")
162168
self.m(hn.title, "Sir", hn)

0 commit comments

Comments
 (0)