@@ -281,7 +281,9 @@ def is_roman_numeral(self, value):
281281 def is_suffix (self , piece ):
282282 """Is in the suffixes set and not :py:func:`is_an_initial()`."""
283283 # suffixes may have periods inside them like "M.D."
284- return lc (piece ).replace ('.' ,'' ) in self .C .suffixes and not self .is_an_initial (piece )
284+ return ((lc (piece ).replace ('.' ,'' ) in self .C .suffix_acronyms ) \
285+ or (lc (piece ) in self .C .suffixes )) \
286+ and not self .is_an_initial (piece )
285287
286288 def are_suffixes (self , pieces ):
287289 """Return True if all pieces are suffixes."""
@@ -304,9 +306,6 @@ def is_an_initial(self, value):
304306 """
305307 return bool (self .C .regexes .initial .match (value ))
306308
307- # def is_a_roman_numeral(value):
308- # return re_roman_numeral.match(value) or False
309-
310309
311310 ### full_name parser
312311
@@ -412,7 +411,7 @@ def parse_full_name(self):
412411 nxt = None
413412
414413 # title must have a next piece, unless it's just a title
415- if self .is_title (piece ) and (nxt or p_len == 1 ):
414+ if self .is_title (piece ) and (nxt or p_len == 1 ) and not self . first :
416415 self .title_list .append (piece )
417416 continue
418417 if not self .first :
@@ -446,7 +445,7 @@ def parse_full_name(self):
446445 except IndexError :
447446 nxt = None
448447
449- if self .is_title (piece ) and (nxt or len (pieces ) == 1 ):
448+ if self .is_title (piece ) and (nxt or len (pieces ) == 1 ) and not self . first :
450449 self .title_list .append (piece )
451450 continue
452451 if not self .first :
@@ -483,7 +482,7 @@ def parse_full_name(self):
483482 except IndexError :
484483 nxt = None
485484
486- if self .is_title (piece ) and (nxt or len (pieces ) == 1 ):
485+ if self .is_title (piece ) and (nxt or len (pieces ) == 1 ) and not self . first :
487486 self .title_list .append (piece )
488487 continue
489488 if not self .first :
@@ -522,7 +521,9 @@ def parse_full_name(self):
522521 def parse_pieces (self , parts , additional_parts_count = 0 ):
523522 """
524523 Split parts on spaces and remove commas, join on conjunctions and
525- lastname prefixes.
524+ lastname prefixes. If parts have periods in the middle, try splitting
525+ on periods and check if the parts are titles or suffixes. If they are
526+ add to the constant so they will be found.
526527
527528 :param list parts: name part strings from the comma split
528529 :param int additional_parts_count:
@@ -533,12 +534,31 @@ def parse_pieces(self, parts, additional_parts_count=0):
533534 :rtype: list
534535 """
535536
536- tmp = []
537+ output = []
537538 for part in parts :
538539 if not isinstance (part , text_types ):
539540 raise TypeError ("Name parts must be strings. Got {0}" .format (type (part )))
540- tmp += [x .strip (' ,' ) for x in part .split (' ' )]
541- return self .join_on_conjunctions (tmp , additional_parts_count )
541+ output += [x .strip (' ,' ) for x in part .split (' ' )]
542+
543+ # If there's periods, check if it's titles without spaces and add spaces
544+ # so they get picked up later as titles.
545+ for part in output :
546+ # if this part has a period not at the beginning or end
547+ if self .C .regexes .period_not_at_end .match (part ):
548+ # split on periods, any of the split pieces titles or suffixes? ("Lt.Gov.")
549+ period_chunks = part .split ("." )
550+ titles = filter (self .is_title , period_chunks )
551+ suffixes = filter (self .is_suffix , period_chunks )
552+
553+ # add the part to the constant so it will be found
554+ if len (list (titles )):
555+ self .C .titles .add (part )
556+ continue
557+ if len (list (suffixes )):
558+ self .C .suffixes .add (part )
559+ continue
560+
561+ return self .join_on_conjunctions (output , additional_parts_count )
542562
543563 def join_on_conjunctions (self , pieces , additional_parts_count = 0 ):
544564 """
0 commit comments