URL: http://github.com/derek73/python-nameparser/pull/157.diff
conj_i = [] for i, val in enumerate(conj_index): try: - if conj_index[i+1] == val+1: + if conj_index[i + 1] == val + 1: contiguous_conj_i += [val] except IndexError: pass @@ -823,12 +833,12 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0): delete_i = [] for i in contiguous_conj_i: if type(i) == tuple: - new_piece = " ".join(pieces[i[0]: i[1]+1]) - delete_i += list(range(i[0]+1, i[1]+1)) + new_piece = " ".join(pieces[i[0]: i[1] + 1]) + delete_i += list(range(i[0] + 1, i[1] + 1)) pieces[i[0]] = new_piece else: - new_piece = " ".join(pieces[i: i+2]) - delete_i += [i+1] + new_piece = " ".join(pieces[i: i + 2]) + delete_i += [i + 1] pieces[i] = new_piece # add newly joined conjunctions to constants to be found later self.C.conjunctions.add(new_piece) @@ -853,23 +863,23 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0): continue if i == 0: - new_piece = " ".join(pieces[i:i+2]) - if self.is_title(pieces[i+1]): + new_piece = " ".join(pieces[i:i + 2]) + if self.is_title(pieces[i + 1]): # when joining to a title, make new_piece a title too self.C.titles.add(new_piece) pieces[i] = new_piece - pieces.pop(i+1) + pieces.pop(i + 1) # subtract 1 from the index of all the remaining conjunctions for j, val in enumerate(conj_index): if val > i: - conj_index[j] = val-1 + conj_index[j] = val - 1 else: - new_piece = " ".join(pieces[i-1:i+2]) - if self.is_title(pieces[i-1]): + new_piece = " ".join(pieces[i - 1:i + 2]) + if self.is_title(pieces[i - 1]): # when joining to a title, make new_piece a title too self.C.titles.add(new_piece) - pieces[i-1] = new_piece + pieces[i - 1] = new_piece pieces.pop(i) rm_count = 2 try: @@ -932,7 +942,7 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0): def cap_word(self, word, attribute): if (self.is_prefix(word) and attribute in ('last', 'middle')) \ - or self.is_conjunction(word): + or self.is_conjunction(word): return word.lower() exceptions = self.C.capitalization_exceptions if lc(word) in exceptions: @@ -941,6 +951,7 @@ def cap_word(self, word, attribute): if mac_match: def cap_after_mac(m): return m.group(1).capitalize() + m.group(2).capitalize() + return self.C.regexes.mac.sub(cap_after_mac, word) else: return word.capitalize() @@ -950,6 +961,7 @@ def cap_piece(self, piece, attribute): return "" def replacement(m): return self.cap_word(m.group(0), attribute) + return self.C.regexes.word.sub(replacement, piece) def capitalize(self, force=None): diff --git a/tests.py b/tests.py index 2cdd526..79afec8 100644 --- a/tests.py +++ b/tests.py @@ -200,6 +200,10 @@ def test_surnames_attribute(self): hn = HumanName("John Edgar Casey Williams III") self.m(hn.surnames, "Edgar Casey Williams", hn) + def test_given_names(self): + hn = HumanName("Dr. Juan Q. Xavier de la Vega") + self.m(hn.given, "Juan Q. Xavier", hn) + def test_is_prefix_with_list(self): hn = HumanName() items = ['firstname', 'lastname', 'del']Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: