Skip to content

Commit 0f1d426

Browse files
committed
Fix #54 error for names that end with conjunction
1 parent f21e7be commit 0f1d426

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

docs/release_log.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Release Log
22
===========
3+
* 0.5.1 - August 12, 2016
4+
- Fix error for names that end with conjunction (#54)
35
* 0.5.0 - August 4, 2016
46
- Refactor join_on_conjunctions(), fix #53
57
* 0.4.1 - July 25, 2016

nameparser/__init__.py

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

nameparser/parser.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,9 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
607607
rootname_pieces = [p for p in pieces if self.is_rootname(p)]
608608
total_length= len(rootname_pieces) + additional_parts_count
609609

610-
# find all the conjunctions, join any conjunctions that are next to each other, then join those newly joined conjunctions and any single conjunctions to the piece before and after it
610+
# find all the conjunctions, join any conjunctions that are next to each
611+
# other, then join those newly joined conjunctions and any single
612+
# conjunctions to the piece before and after it
611613
conj_index = [i for i, piece in enumerate(pieces) if self.is_conjunction(piece)]
612614

613615
contiguous_conj_i = []
@@ -667,11 +669,17 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
667669
self.C.titles.add(new_piece)
668670
pieces[i-1] = new_piece
669671
pieces.pop(i)
670-
pieces.pop(i)
671-
# subtract 2 from the index of all the remaining conjunctions
672+
rm_count = 2
673+
try:
674+
pieces.pop(i)
675+
except IndexError:
676+
rm_count = 1
677+
pass
678+
# subtract the number of removed pieces from the index
679+
# of all the remaining conjunctions
672680
for j,val in enumerate(conj_index):
673681
if val > i:
674-
conj_index[j]=val-2
682+
conj_index[j] = val - rm_count
675683

676684

677685
# join prefixes to following lastnames: ['de la Vega'], ['van Buren']

tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,26 @@ def test_multiple_conjunctions(self):
10731073
def test_multiple_conjunctions2(self):
10741074
hn = HumanName("part1 of and The part2 of the part3 And part4")
10751075
self.m(hn.first, "part1 of and The part2 of the part3 And part4", hn)
1076+
1077+
def test_ends_with_conjunction(self):
1078+
hn = HumanName("Jon Dough and")
1079+
self.m(hn.first, "Jon", hn)
1080+
self.m(hn.last, "Dough and", hn)
1081+
1082+
def test_ends_with_two_conjunctions(self):
1083+
hn = HumanName("Jon Dough and of")
1084+
self.m(hn.first, "Jon", hn)
1085+
self.m(hn.last, "Dough and of", hn)
1086+
1087+
def test_starts_with_conjunction(self):
1088+
hn = HumanName("and Jon Dough")
1089+
self.m(hn.first, "and Jon", hn)
1090+
self.m(hn.last, "Dough", hn)
1091+
1092+
def test_starts_with_two_conjunctions(self):
1093+
hn = HumanName("the and Jon Dough")
1094+
self.m(hn.first, "the and Jon", hn)
1095+
self.m(hn.last, "Dough", hn)
10761096

10771097
# Potential conjunction/prefix treated as initial (because uppercase)
10781098
def test_uppercase_middle_initial_conflict_with_conjunction(self):

0 commit comments

Comments
 (0)