person_names
person_names
¶
Write full names in a locale's own order and read them back into first, middle, and last names.
A full name without a plan pattern is written the way Faker writes the locale's names: given name first in
en_US, family name first in ja_JP, hu_HU, and ru_RU, and family name first with no space in
zh_CN and ko_KR. nameparser reads full names back, told which order to expect: the column's pattern's
order, or else the locale's.
This module lives outside replacement.generators so free-text replacement can read names without loading the
generator implementations.
Classes:
| Name | Description |
|---|---|
FullNameLayout |
How a locale writes a full name. |
Functions:
| Name | Description |
|---|---|
full_name_layout |
Return the layout of the first Faker full-name format for |
write_full_name |
Return |
read_full_name |
Return the |
parse_full_name |
Return nameparser's reading of |
is_kept_title |
Return whether replacement keeps the title |
titles_before |
Find titles written just before a name in |
name_affixes |
Return |
FullNameLayout(family_first, separator)
dataclass
¶
How a locale writes a full name.
Attributes:
| Name | Type | Description |
|---|---|---|
family_first |
bool
|
Whether the family name comes before the given name. |
separator |
str
|
Text between the two names: a space, or nothing in Chinese and Korean. |
full_name_layout(locale)
cached
¶
Return the layout of the first Faker full-name format for locale that has a given and a family name.
Raises:
| Type | Description |
|---|---|
GenerationError
|
If Faker cannot load |
Example
full_name_layout("zh_CN") is family first with no separator, from Faker's {{last_name}}{{first_name}}.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/person_names.py
write_full_name(first, last, locale)
¶
Return first and last as a full name in locale's layout.
Example
write_full_name("太郎", "山田", "ja_JP") is "山田 太郎".
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/person_names.py
read_full_name(full_name, *, locale, pattern=None)
¶
Return the first, middle, and last names in full_name, read by nameparser.
The name is read in the order of pattern when it places both a first and a last name, and otherwise in
locale's order. A comma always marks the last name first, a particle such as van stays with the last name,
and titles and suffixes are left out.
Example
read_full_name("Hopper, Grace", locale="en_US") and read_full_name("Nagy Péter", locale="hu_HU")
have first names Grace and Péter.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/person_names.py
parse_full_name(full_name, *, locale, pattern=None)
¶
Return nameparser's reading of full_name, in the order :func:read_full_name describes.
The result also gives each word's role and position, such as a title, given name, or family name.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/person_names.py
is_kept_title(word)
¶
Return whether replacement keeps the title word: one of a profession or office, such as Dr..
Structured and free-text replacement both keep a title only when this is true, and drop every other title.
Example
is_kept_title("Dr.") and is_kept_title("Capt") are true; is_kept_title("Mrs.") is false.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/person_names.py
titles_before(text, name_start, *, floor=0)
¶
Find titles written just before a name in text and return where they start and the ones to keep.
Up to three capitalized words that nameparser knows as titles, each followed by spaces, are read back from
name_start but not before floor. The kept text has only the titles :func:is_kept_title keeps, each
with the spaces after it, so writing it in place of text[start:name_start] drops the others.
Example
titles_before("Seen by Mr. Dr. Ada", 16) is (8, "Dr. "), and titles_before("Seen by Ada", 8) is
(8, "").
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/person_names.py
name_affixes(full_name, *, locale, pattern=None)
¶
Return full_name's leading titles and trailing suffixes as written, or "" for each it lacks.
Titles of a profession or office, such as Dr. and Capt., and suffixes such as Jr. and PhD are
kept, each with the spaces and commas that follow or precede it. Other titles, such as Mr. and Mrs.,
are left out. Names whose titles or suffixes sit between name words return
("", "").
Example
name_affixes("Dr. Ada Lovelace, PhD", locale="en_US") is ("Dr. ", ", PhD"), and
name_affixes("Mrs. Grace Hopper", locale="en_US") is ("", "").