Skip to content

Commit 4edaf68

Browse files
committed
update docs to python 3, fix links, clarify suffix handling
1 parent 3a45c63 commit 4edaf68

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

docs/customize.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The other is the ``C`` attribute of a ``HumanName`` instance, e.g.
4646
<Constants() instance>
4747

4848
Both places are usually a reference to the same shared module-level
49-
:py:class:`~nameparser.config.Constants` instance, depending on how you
49+
:py:class:`~nameparser.config.CONSTANTS` instance, depending on how you
5050
instantiate the :py:class:`~nameparser.parser.HumanName` class (see below).
5151

5252
Take a look at the :py:mod:`nameparser.config` documentation to see what's
@@ -82,7 +82,7 @@ constant so that "Hon" can be parsed as a first name.
8282
]>
8383
>>> from nameparser.config import CONSTANTS
8484
>>> CONSTANTS.titles.remove('hon')
85-
SetManager(set([u'msgt', ..., u'adjutant']))
85+
SetManager({'right', ..., 'tax'})
8686
>>> hn = HumanName("Hon Solo")
8787
>>> hn
8888
<HumanName : [
@@ -99,7 +99,8 @@ constant so that "Hon" can be parsed as a first name.
9999
constant. But in some contexts it is more common as a title. If you would
100100
like "Dean" to be parsed as a title, simply add it to the titles constant.
101101

102-
You can pass multiple strings to both the ``add()`` and ``remove()``
102+
You can pass multiple strings to both the :py:func:`~nameparser.config.SetManager.add`
103+
and :py:func:`~nameparser.config.SetManager.remove`
103104
methods and each string will be added or removed. Both functions
104105
automatically normalize the strings for the parser's comparison method by
105106
making them lower case and removing periods.
@@ -110,7 +111,7 @@ making them lower case and removing periods.
110111
>>> from nameparser import HumanName
111112
>>> from nameparser.config import CONSTANTS
112113
>>> CONSTANTS.titles.add('dean', 'Chemistry')
113-
SetManager(set([u'msgt', ..., u'adjutant']))
114+
SetManager({'right', ..., 'tax'})
114115
>>> hn = HumanName("Assoc Dean of Chemistry Robert Johns")
115116
>>> hn
116117
<HumanName : [
@@ -137,7 +138,7 @@ the config on one instance could modify the behavior of another instance.
137138
>>> from nameparser import HumanName
138139
>>> instance = HumanName("")
139140
>>> instance.C.titles.add('dean')
140-
SetManager(set([u'msgt', ..., u'adjutant']))
141+
SetManager({'right', ..., 'tax'})
141142
>>> other_instance = HumanName("Dean Robert Johns")
142143
>>> other_instance # Dean parses as title
143144
<HumanName : [
@@ -164,7 +165,7 @@ reference to the module-level config values with the behavior described above.
164165
>>> instance.has_own_config
165166
False
166167
>>> instance.C.titles.add('dean')
167-
SetManager(set([u'msgt', ..., u'adjutant']))
168+
SetManager({'right', ..., 'tax'})
168169
>>> other_instance = HumanName("Dean Robert Johns", None) # <-- pass None for per-instance config
169170
>>> other_instance
170171
<HumanName : [
@@ -203,7 +204,7 @@ those changes with ``repr()``.
203204
nickname: ''
204205
]>
205206
>>> CONSTANTS.titles.add('dean')
206-
SetManager(set([u'msgt', ..., u'adjutant']))
207+
SetManager({'right', ..., 'tax'})
207208
>>> hn
208209
<HumanName : [
209210
title: ''

docs/usage.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Using the HumanName Parser
44
Example Usage
55
-------------
66

7+
The examples use Python 3, but Python 2.6+ is supported.
8+
79
.. doctest::
810
:options: +NORMALIZE_WHITESPACE
911

@@ -43,8 +45,8 @@ Example Usage
4345
suffix: 'Jr.'
4446
nickname: ''
4547
]>
46-
>>> name.suffix = ["custom","values"]
47-
>>> name.suffix
48+
>>> name.middle = ["custom","values"]
49+
>>> name.middle
4850
'custom values'
4951
>>> name.full_name = 'Doe-Ray, Jonathan "John" A. Harris'
5052
>>> name.as_dict()
@@ -63,12 +65,12 @@ Example Usage
6365
['Juan', 'Q. Xavier', 'de la Vega']
6466
>>> name = HumanName('bob v. de la macdole-eisenhower phd')
6567
>>> name.capitalize()
66-
>>> unicode(name)
68+
>>> str(name)
6769
'Bob V. de la MacDole-Eisenhower Ph.D.'
6870
>>> # Don't touch mixed case names
6971
>>> name = HumanName('Shirley Maclaine')
7072
>>> name.capitalize()
71-
>>> unicode(name)
73+
>>> str(name)
7274
'Shirley Maclaine'
7375

7476
Capitalization Support
@@ -86,7 +88,7 @@ entered in all upper or lower case.
8688

8789
>>> name = HumanName("bob v. de la macdole-eisenhower phd")
8890
>>> name.capitalize()
89-
>>> unicode(name)
91+
>>> str(name)
9092
'Bob V. de la MacDole-Eisenhower Ph.D.'
9193

9294
It will not adjust the case of mixed case names.
@@ -96,7 +98,7 @@ Nickname Handling
9698
------------------
9799

98100
The content of parenthesis or double quotes in the name will be
99-
available from the nickname attribute. (Added in v0.2.9)
101+
available from the nickname attribute.
100102

101103
.. doctest:: nicknames
102104
:options: +NORMALIZE_WHITESPACE
@@ -118,7 +120,8 @@ Change the output string with string formatting
118120
The string representation of a `HumanName` instance is controlled by its `string_format` attribute. The default value, "{title} {first} {middle} {last} {suffix} ({nickname})", includes parenthesis around nicknames. Trailing commas and empty quotes and parenthesis are automatically removed if the name has no nickname pieces.
119121

120122
You can change the default formatting for all `HumanName` instances by setting a new
121-
`CONSTANTS.string_format` value.
123+
:py:attr:`~nameparser.config.Constants.string_format` value on the shared
124+
:py:class:`~nameparser.config.CONSTANTS` configuration instance.
122125

123126
.. doctest:: string format
124127

nameparser/config/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,16 @@ class Constants(object):
133133
:param set titles:
134134
:py:attr:`titles` wrapped with :py:class:`SetManager`.
135135
:param set first_name_titles:
136-
:py:attr:`first_name_titles` wrapped with :py:class:`SetManager`.
137-
:param set suffixes:
138-
:py:attr:`suffixes` wrapped with :py:class:`SetManager`.
136+
:py:attr:`~titles.FIRST_NAME_TITLES` wrapped with :py:class:`SetManager`.
137+
:param set suffix_acronyms:
138+
:py:attr:`~suffixes.SUFFIX_ACRONYMS` wrapped with :py:class:`SetManager`.
139+
:param set suffix_not_acronyms:
140+
:py:attr:`~suffixes.SUFFIX_NOT_ACRONYMS` wrapped with :py:class:`SetManager`.
139141
:param set conjunctions:
140142
:py:attr:`conjunctions` wrapped with :py:class:`SetManager`.
141143
:type capitalization_exceptions: tuple or dict
142144
:param capitalization_exceptions:
143-
:py:attr:`capitalization_exceptions` wrapped with :py:class:`TupleManager`.
145+
:py:attr:`~capitalization.CAPITALIZATION_EXCEPTIONS` wrapped with :py:class:`TupleManager`.
144146
:type regexes: tuple or dict
145147
:param regexes:
146148
:py:attr:`regexes` wrapped with :py:class:`TupleManager`.

nameparser/config/suffixes.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
'iv',
1616
'v',
1717
])
18+
"""
19+
20+
Post-nominal pieces that are not acronyms. The parser does not remove periods
21+
when matching against these pieces.
22+
23+
"""
1824
SUFFIX_ACRONYMS = set([
1925
'ae',
2026
'afc',
@@ -109,13 +115,14 @@
109115
'vd',
110116
'vrd',
111117
])
112-
SUFFIXES = SUFFIX_ACRONYMS | SUFFIX_NOT_ACRONYMS
113118
"""
114119
115-
Pieces that come at the end of the name but are not last names. These potentially
116-
conflict with initials that might be at the end of the name.
120+
Post-nominal acronyms. Titles, degrees and other things people stick after their name
121+
that may or may not have periods between the letters. The parser removes periods
122+
when matching against these pieces.
117123
118-
These may be updated in the future because some of them are actually titles that just
119-
come at the end of the name, so semantically this is wrong. Positionally, it's correct.
120-
121-
"""
124+
"""
125+
SUFFIXES = SUFFIX_ACRONYMS | SUFFIX_NOT_ACRONYMS
126+
"""
127+
A union of the sets :py:attr:`SUFFIX_ACRONYMS` and :py:attr:`SUFFIX_NOT_ACRONYMS`
128+
"""

nameparser/parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ def as_dict(self, include_empty=True):
156156
157157
>>> name = HumanName("Bob Dole")
158158
>>> name.as_dict()
159-
{u'last': u'Dole', u'suffix': u'', u'title': u'', u'middle': u'', u'nickname': u'', u'first': u'Bob'}
159+
{'last': 'Dole', 'suffix': '', 'title': '', 'middle': '', 'nickname': '', 'first': 'Bob'}
160160
>>> name.as_dict(False)
161-
{u'last': u'Dole', u'first': u'Bob'}
161+
{'last': 'Dole', 'first': 'Bob'}
162162
163163
"""
164164
d = {}
@@ -694,13 +694,13 @@ def capitalize(self):
694694
695695
>>> name = HumanName('bob v. de la macdole-eisenhower phd')
696696
>>> name.capitalize()
697-
>>> unicode(name)
698-
u'Bob V. de la MacDole-Eisenhower Ph.D.'
697+
>>> str(name)
698+
'Bob V. de la MacDole-Eisenhower Ph.D.'
699699
>>> # Don't touch good names
700700
>>> name = HumanName('Shirley Maclaine')
701701
>>> name.capitalize()
702-
>>> unicode(name)
703-
u'Shirley Maclaine'
702+
>>> str(name)
703+
'Shirley Maclaine'
704704
705705
"""
706706
name = u(self)

0 commit comments

Comments
 (0)