|
1 | 1 | Customizing the Parser with Your Own Configuration |
2 | 2 | ================================================== |
3 | 3 |
|
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. |
9 | 8 |
|
10 | 9 |
|
11 | 10 | Changing the Predefined Variables |
12 | 11 | +++++++++++++++++++++++++++++++++ |
13 | 12 |
|
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. |
19 | 39 |
|
20 | 40 |
|
21 | 41 | Parser Customization Examples |
22 | 42 | +++++++++++++++++++++++++++++ |
23 | 43 |
|
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. |
28 | 51 |
|
29 | 52 | :: |
30 | 53 |
|
@@ -54,12 +77,14 @@ that "Hon" can be parsed as a first name. |
54 | 77 | ]> |
55 | 78 |
|
56 | 79 |
|
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. |
60 | 83 |
|
61 | 84 | 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. |
63 | 88 |
|
64 | 89 | :: |
65 | 90 |
|
|
0 commit comments