Skip to content

Commit 9aca7a5

Browse files
committed
v0.3.11: Fix #39, capitalization of initials with periods that are also conjunctions
1 parent c0a77a9 commit 9aca7a5

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
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.3.11 - October 17, 2015
4+
- Fix bug capitalization exceptions (#39)
35
* 0.3.10 - September 19, 2015
46
- Fix encoding of byte strings on python 2.x (#37)
57
* 0.3.9 - September 5, 2015

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, 10)
1+
VERSION = (0, 3, 11)
22
__version__ = '.'.join(map(str, VERSION))
33
__author__ = "Derek Gulbranson"
44
__author_email__ = '[email protected]'

nameparser/config/regexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
REGEXES = set([
66
("spaces", re.compile(r"\s+", re.U)),
7-
("word", re.compile(r"\w+", re.U)),
7+
("word", re.compile(r"(\w|\.)+", re.U)),
88
("mac", re.compile(r'^(ma?c)(\w+)', re.I | re.U)),
99
("initial", re.compile(r'^(\w\.|[A-Z])?$', re.U)),
1010
("nickname", re.compile(r'\s*?[\("](.+?)[\)"]', re.U)),

nameparser/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ def is_title(self, value):
265265

266266
def is_conjunction(self, piece):
267267
"""Is in the conjuctions set and not :py:func:`is_an_initial()`."""
268-
return lc(piece) in self.C.conjunctions and not self.is_an_initial(piece)
268+
return piece.lower() in self.C.conjunctions and not self.is_an_initial(piece)
269269

270270
def is_prefix(self, piece):
271271
"""Is in the prefixes set and not :py:func:`is_an_initial()`."""
272-
return lc(piece) in self.C.prefixes and not self.is_an_initial(piece)
272+
return piece.lower() in self.C.prefixes and not self.is_an_initial(piece)
273273

274274
def is_roman_numeral(self, value):
275275
"""
@@ -657,7 +657,7 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
657657

658658
def cap_word(self, word):
659659
if self.is_prefix(word) or self.is_conjunction(word):
660-
return lc(word)
660+
return word.lower()
661661
exceptions = self.C.capitalization_exceptions
662662
if lc(word) in exceptions:
663663
return exceptions[lc(word)]

tests.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,16 +1708,21 @@ def test_capitalization_with_Mac_as_hyphenated_names(self):
17081708
hn.capitalize()
17091709
self.m(str(hn), 'Donovan McNabb-Smith', hn)
17101710

1711+
def test_capitization_middle_initial_is_also_a_conjunction(self):
1712+
hn = HumanName('scott e. werner')
1713+
hn.capitalize()
1714+
self.m(str(hn), 'Scott E. Werner', hn)
1715+
17111716
# Leaving already-capitalized names alone
1712-
def test123(self):
1717+
def test_no_change_to_mixed_chase(self):
17131718
hn = HumanName('Shirley Maclaine')
17141719
hn.capitalize()
17151720
self.m(str(hn), 'Shirley Maclaine', hn)
17161721

17171722
def test_capitalize_diacritics(self):
1718-
hn = HumanName('matth\xe4us schmidt')
1723+
hn = HumanName('matthëus schmidt')
17191724
hn.capitalize()
1720-
self.m(u(hn), 'Matth\xe4us Schmidt', hn)
1725+
self.m(u(hn), 'Matthëus Schmidt', hn)
17211726

17221727
# http://code.google.com/p/python-nameparser/issues/detail?id=15
17231728
def test_downcasing_mac(self):
@@ -1966,7 +1971,8 @@ def test_variations_of_TEST_NAMES(self):
19661971
name = sys.argv[1]
19671972
hn = HumanName(name, encoding=sys.stdout.encoding)
19681973
print((repr(hn)))
1969-
print((hn.capitalize()))
1974+
hn.capitalize()
1975+
print((repr(hn)))
19701976
else:
19711977
# if log.level > 0:
19721978
# for name in TEST_NAMES:

0 commit comments

Comments
 (0)