Skip to content

Commit 6efb200

Browse files
committed
clarify customization documentation
1 parent 9d3fb8f commit 6efb200

3 files changed

Lines changed: 45 additions & 20 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ To run the tests locally, just run `python tests.py`.
2525

2626
You can also pass a name string to `tests.py` to see how it will be parsed.
2727

28-
$ ./tests.py "Secretary of State Hillary Rodham-Clinton"
28+
$ python tests.py "Secretary of State Hillary Rodham-Clinton"
2929
<HumanName : [
3030
Title: 'Secretary of State'
3131
First: 'Hillary'

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Installation
5050
5151
If you're starting a new project, I recommend installing master from GitHub to give v0.3
5252
a try. Customizing it is not backwards compatible with v0.2.10 (the current version on
53-
pypi) because the configuration layout chagned, but passes all the same tests, and is
53+
pypi) because the configuration layout changed, but passes all the same tests, and is
5454
easier to configure.
5555

5656
``pip install -e git+git://github.com/derek73/python-nameparser.git#egg=nameparser``

docs/customize.rst

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
Customizing the Parser with Your Own Configuration
22
==================================================
33

4-
Recognition of titles, prefixes, suffixes and conjunctions is provided
5-
by matching the lower case characters of a name piece with pre-defined
6-
sets located in :py:mod:`nameparser.config`. Since everyone's data are a
7-
little bit different, you can easily adjust these predefined sets to
8-
help fine tune the parser for your dataset.
4+
Recognition of titles, prefixes, suffixes and conjunctions is provided by
5+
matching the lower case characters of a name piece with pre-defined sets
6+
of strings located in :py:mod:`nameparser.config`. You can easily adjust
7+
these predefined sets to help fine tune the parser for your dataset.
98

109

1110
Changing the Predefined Variables
1211
+++++++++++++++++++++++++++++++++
1312

14-
There are a few ways to adjust the parser configuration depending on your needs.
15-
The config is available via ``from nameparser.config import CONSTANTS`` or on the
16-
``C`` attribute of a ``HumanName`` instance, e.g. ``hn.C``. Take a look
17-
at the :py:mod:`nameparser.config` documentation to get a better idea what they are
18-
and how they are used, but here's a quick walk through.
13+
There are a few ways to adjust the parser configuration depending on your
14+
needs. The config is available in two places that may or may not represent
15+
the same :py:class:`~nameparser.config.Constants` instance depending on
16+
how you instantiate the :py:class:`~nameparser.parser.HumanName` class.
17+
18+
The first is via ``from nameparser.config import CONSTANTS``.
19+
20+
::
21+
22+
>>> from nameparser.config import CONSTANTS
23+
>>> CONSTANTS
24+
<Constants() instance>
25+
26+
The other is the ``C`` attribute of a ``HumanName`` instance, e.g.
27+
``hn.C``.
28+
29+
::
30+
31+
>>> from nameparser import HumanName
32+
>>> hn = HumanName("Dean Robert Johns")
33+
>>> hn.C
34+
<Constants() instance>
35+
36+
Take a look at the :py:mod:`nameparser.config` documentation to see what's
37+
in the constants. Here's a quick walk through of some examples where you
38+
might want to adjust them.
1939

2040

2141
Parser Customization Examples
2242
+++++++++++++++++++++++++++++
2343

24-
"Hon" is a common abbreviation for "Honorable", a title used when addressing
25-
judges. It is also sometimes a first name. If your dataset contains more
26-
"Hon"s than judges, you may wish to remove it from the titles constant so
27-
that "Hon" can be parsed as a first name.
44+
"Hon" is a common abbreviation for "Honorable", a title used when
45+
addressing judges, and is included in the default tiles constants which
46+
means it will never be considered a first name.
47+
48+
But "Hon is also sometimes a first name. If your dataset contains more
49+
"Hon"s than "Honorable"s, you may wish to remove it from the titles
50+
constant so that "Hon" can be parsed as a first name.
2851

2952
::
3053

@@ -54,12 +77,14 @@ that "Hon" can be parsed as a first name.
5477
]>
5578

5679

57-
"Dean" is a common first name, but sometimes it is more common as a title.
58-
If you would like "Dean" to be parsed as a title, simply add it to the
59-
titles constant.
80+
"Dean" is a common first name so it is not included in the default titles
81+
constant. But in some contexts it is more common as a title. If you would
82+
like "Dean" to be parsed as a title, simply add it to the titles constant.
6083

6184
You can pass multiple strings to both the ``add()`` and ``remove()``
62-
methods and each string will be added or removed.
85+
methods and each string will be added or removed. Both functions
86+
automatically normalize the strings for the parser's comparison method by
87+
making them lower case and removing periods.
6388

6489
::
6590

0 commit comments

Comments
 (0)