![]() |
Name Generator 4.5.2
Culture-aware name generation for C++23
|
Name generator that produces culture-aware names and surnames. More...
#include <namegen.hpp>
Public Member Functions | |
| ng ()=default | |
| Default constructor — creates an empty generator with no names. | |
| ng (const ng &)=delete | |
| Not copyable. | |
| ng & | operator= (const ng &)=delete |
| Not copyable. | |
| ng (ng &&) noexcept=default | |
| Move constructor. | |
| ng & | operator= (ng &&) noexcept=default |
| Move assignment. | |
| ~ng ()=default | |
| Default destructor. | |
| name | get_name (const name_request &request) |
| Generate a first name. | |
| name | get_name (const name_request &request, std::uint64_t call_seed) const |
| Generate a deterministic first name using a specific seed. | |
| std::vector< name > | get_name_batch (const name_request &request, const core::batch_options &options) |
| Generate a batch of name results from a seed drawn like get_name() draws its own. | |
| std::vector< name > | get_name_batch (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| Generate a batch of name results, deterministically. | |
| template<typename Sink > | |
| void | for_each_name (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of name results to a sink without holding the whole batch. | |
| template<typename Sink > | |
| void | for_each_name (const name_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of name results with a batch seed drawn like get_name() draws its own. | |
| name | get_surname (const name_request &request) |
| Generate a surname. | |
| name | get_surname (const name_request &request, std::uint64_t call_seed) const |
| Generate a deterministic surname using a specific seed. | |
| std::vector< name > | get_surname_batch (const name_request &request, const core::batch_options &options) |
| Generate a batch of surname results from a seed drawn like get_surname() draws its own. | |
| std::vector< name > | get_surname_batch (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| Generate a batch of surname results, deterministically. | |
| template<typename Sink > | |
| void | for_each_surname (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of surname results to a sink without holding the whole batch. | |
| template<typename Sink > | |
| void | for_each_surname (const name_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of surname results with a batch seed drawn like get_surname() draws its own. | |
| naming_convention | convention (culture c) const |
| How a culture composes a full name. | |
| name | get_full_name (const name_request &request) |
| Generate a full name by the culture's convention. | |
| name | get_full_name (const name_request &request, std::uint64_t call_seed) const |
| Generate a deterministic full name. | |
| std::vector< name > | get_full_name_batch (const name_request &request, const core::batch_options &options) |
| Generate a batch of full names from a seed drawn like get_full_name() draws its own. | |
| std::vector< name > | get_full_name_batch (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
Generate a batch of full names, deterministically: item i is get_full_name(request, core::item_seed(batch_seed, options.first + i)). | |
| template<typename Sink > | |
| void | for_each_full_name (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of full names to a sink, in index order. | |
| template<typename Sink > | |
| void | for_each_full_name (const name_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of full names with a batch seed drawn like get_full_name() draws its own. | |
| name | get_child_name (const name &father, const name &mother, const child_name_request &request) |
| Name a child of two people by the culture's convention. | |
| name | get_child_name (const name &father, const name &mother, const child_name_request &request, std::uint64_t call_seed) const |
| Name a child of two people, deterministically. | |
| name | get_married_name (const name &wife, const name &husband) const |
| The name a woman has after marrying, by the culture's convention. | |
| name | compose_name (const name_parts &parts, culture c, std::uint64_t call_seed=0) const |
| A name made from words the caller already has, put in the culture's order and carrying the roles of its parts. | |
| name | get_parent_name (const name &child, gender parent_gender) |
| Name a parent of an existing person, consistently with the person's name; the inverse of get_child_name(). | |
| name | get_parent_name (const name &child, gender parent_gender, std::uint64_t call_seed) const |
| Name a parent of an existing person, deterministically. | |
| std::wstring | female_form (const std::wstring &surname, culture c, bool married=false) const |
The female form of a male surname, by the culture's surname_forms.tsv rules. | |
| const std::vector< core::layer_info > & | convention_layers () const |
The layers in effect for conventions.tsv. | |
| const std::vector< core::layer_info > & | surname_form_layers () const |
The layers in effect for surname_forms.tsv. | |
| bool | has_resources () const |
| Check whether any name databases have been loaded. | |
| void | load (const std::filesystem::path &resource_path) |
| Load name files from a directory, replacing all names and layers loaded before. | |
| bool | load (dataset tier) |
| Load a dataset tier, replacing all names and layers loaded before. | |
| void | extend (const std::filesystem::path &path, core::layer_mode mode=core::layer_mode::override) |
Add name layers from a .names file or a directory of them. | |
| const core::layer_info & | extend_conventions_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override) |
Add a layer of conventions.tsv from text. | |
| const core::layer_info & | extend_surname_forms_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override) |
Add a layer of surname_forms.tsv from text. | |
| const core::layer_info & | extend_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override) |
Add a name layer from text in the .names format. | |
| const std::vector< core::layer_info > & | layers (culture c, gender g) const |
| The layers in effect for one name list. | |
| const std::vector< core::layer_info > & | surname_layers (culture c, gender g) const |
| The layers in effect for the surnames of one gender. | |
| std::uint64_t | data_hash () const |
| Hash of the loaded names, recorded in each result's signature(). | |
Static Public Member Functions | |
| static ng & | instance () |
| Access the global singleton instance. | |
| static culture | to_culture (std::wstring_view country_code) |
| Translate an ISO 3166 2-letter country code to a culture enum. | |
| static gender | to_gender (std::wstring_view gender_string) |
| Translate a gender string to a gender enum. | |
| static std::string_view | culture_code (culture c) |
| The ISO 3166 2-letter country code of a culture. | |
| static std::string_view | culture_name (culture c) |
| The name of a culture. | |
| static std::wstring | patronymic_of (patronymic_style style, const std::wstring &father, bool daughter) |
| The patronymic a father's given name gives a child. | |
Friends | |
| class | name |
| struct | ::ng_test_access |
Name generator that produces culture-aware names and surnames.
Generates realistic names by picking from popular name databases indexed by culture and gender, weighted by popularity. Supports 105 cultures.
Output is identical on every compiler and platform (dasmig-core): a seed, the same request and the same data give the same name everywhere.
Can be used as a singleton via instance() or constructed independently. Independent instances own their own name databases and random engine.
Definition at line 431 of file namegen.hpp.
|
default |
Default constructor — creates an empty generator with no names.
Call load() to populate name databases before generating.
|
inline |
A name made from words the caller already has, put in the culture's order and carrying the roles of its parts.
For a person whose name is known and whose relatives are to be named to match: pass the result to get_child_name(), get_parent_name() or get_married_name(), which read only the roles of the parts.
| parts | The words of the name. |
| c | The culture whose convention orders them; not any. |
| call_seed | Seed recorded in the name's signature. |
| std::invalid_argument | If the culture is any, the gender is not male or female, or the given name is empty. |
Definition at line 885 of file namegen.hpp.
|
inline |
How a culture composes a full name.
| c | Culture. |
conventions.tsv; the default (one surname, given name first) for a culture without a row. Definition at line 698 of file namegen.hpp.
|
inline |
The layers in effect for conventions.tsv.
Definition at line 1010 of file namegen.hpp.
|
inlinestatic |
The ISO 3166 2-letter country code of a culture.
| c | Culture. |
"br", or "" for culture::any. Definition at line 483 of file namegen.hpp.
|
inlinestatic |
The name of a culture.
| c | Culture. |
"brazilian", or "any". Definition at line 492 of file namegen.hpp.
|
inline |
Hash of the loaded names, recorded in each result's signature().
Definition at line 1221 of file namegen.hpp.
|
inline |
Add name layers from a .names file or a directory of them.
Each file names its culture and gender in its first two lines, so it adds to (or changes, or removes from) that list. A directory is applied all together, or not at all if any file is invalid.
| path | A .names file or a directory. |
| mode | How the layers combine with the names loaded before. |
| core::tsv_error | If a file cannot be read or is invalid; the names are then unchanged. |
| std::invalid_argument | If path is a file without the .names extension. |
Definition at line 1102 of file namegen.hpp.
|
inline |
Add a layer of conventions.tsv from text.
| text | Tab-separated text with a header line: culture (a culture name such as russian, the key) and any of order (given_family, family_given), patronymic (none, east_slavic, icelandic), family_name (0 or 1), surnames (1 or 2), second_surname (a chance from 0 to 1) and surname_order (paternal_first, maternal_first). |
| source | Name used in errors. |
| mode | How the layer combines with the conventions loaded before. |
| core::tsv_error | If the text is invalid; nothing then changes. |
Definition at line 1141 of file namegen.hpp.
|
inline |
Add a name layer from text in the .names format.
| text | The country code, the list (male, female or any for surnames; male-surname or female-surname for the surnames of one gender), then one name per line with an optional weight. |
| source | Name used in errors. |
| mode | How the layer combines with the names loaded before. |
| core::tsv_error | If the text is invalid; the names are then unchanged. |
Definition at line 1181 of file namegen.hpp.
|
inline |
Add a layer of surname_forms.tsv from text.
| text | Tab-separated text with a header line: culture and male (the keys: the ending of a male surname, or * for any), female (the ending a daughter has instead) and optionally married (the ending a wife has; female when empty). The longest matching male ending applies. |
| source | Name used in errors. |
| mode | How the layer combines with the rules loaded before. |
| core::tsv_error | If the text is invalid; nothing then changes. |
Definition at line 1161 of file namegen.hpp.
|
inline |
The female form of a male surname, by the culture's surname_forms.tsv rules.
| surname | A male surname. |
| c | Culture. |
| married | Whether to give the form a wife takes rather than the one a daughter has (they differ in Lithuanian). |
surname when the culture has no rule for it. Definition at line 1002 of file namegen.hpp.
|
inline |
Stream a batch of full names with a batch seed drawn like get_full_name() draws its own.
| Sink | Callable taking (std::uint64_t, name&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 785 of file namegen.hpp.
|
inline |
Stream a batch of full names to a sink, in index order.
| Sink | Callable taking (std::uint64_t, name&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 770 of file namegen.hpp.
|
inline |
Stream a batch of name results with a batch seed drawn like get_name() draws its own.
| Sink | Callable taking (std::uint64_t, name&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 588 of file namegen.hpp.
|
inline |
Stream a batch of name results to a sink without holding the whole batch.
Generates the same items as get_name_batch() and calls sink(index, item) in index order on the calling thread; index includes options.first.
| Sink | Callable taking (std::uint64_t, name&); for example core::jsonl_writer or core::csv_writer. |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 573 of file namegen.hpp.
|
inline |
Stream a batch of surname results with a batch seed drawn like get_surname() draws its own.
| Sink | Callable taking (std::uint64_t, name&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 685 of file namegen.hpp.
|
inline |
Stream a batch of surname results to a sink without holding the whole batch.
Generates the same items as get_surname_batch() and calls sink(index, item) in index order on the calling thread; index includes options.first.
| Sink | Callable taking (std::uint64_t, name&); for example core::jsonl_writer or core::csv_writer. |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 670 of file namegen.hpp.
|
inline |
Name a child of two people by the culture's convention.
The child takes its family name from the parents as the culture does: one surname cultures give the father's family name (a daughter its female form where the culture has one); two-surname cultures give one surname of each parent, in the culture's surname_order; patronymic cultures derive the patronymic from the father's given name. The given name is drawn from the father's culture. Only the parts' roles are read, so the parents can be any names (composed or not); the structure of a family (who the parents are, how many children) is the caller's.
Siblings are not made distinct: draw each with its own seed and compare, if that matters.
| father | The father's name; its culture is the child's. |
| mother | The mother's name. |
| request | The child's gender. |
| std::invalid_argument | If the father's culture is any or has no forenames or surnames loaded. |
Definition at line 812 of file namegen.hpp.
|
inline |
Name a child of two people, deterministically.
| father | The father's name; its culture is the child's. |
| mother | The mother's name. |
| request | The child's gender. |
| call_seed | Seed; the same seed, parents and data give the same name on every platform. |
| std::invalid_argument | If the father's culture is any or has no forenames or surnames loaded. |
Definition at line 827 of file namegen.hpp.
|
inline |
Generate a full name by the culture's convention.
The parts follow the culture's order: family name first for Chinese, Japanese and Korean; two surnames for Spanish and Portuguese; a patronymic from a drawn father's name for Russian and Icelandic. The parts carry roles (name::roles()). get_name() and get_surname() are unchanged by conventions.
| request | Gender and culture (both default to any). |
| std::invalid_argument | If no names are loaded for the resolved culture and gender. |
Definition at line 716 of file namegen.hpp.
|
inline |
Generate a deterministic full name.
| request | Gender and culture. |
| call_seed | Seed; the same seed, request and data give the same name on every platform. |
| std::invalid_argument | If no names are loaded for the resolved culture and gender. |
Definition at line 728 of file namegen.hpp.
|
inline |
Generate a batch of full names from a seed drawn like get_full_name() draws its own.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 743 of file namegen.hpp.
|
inline |
Generate a batch of full names, deterministically: item i is get_full_name(request, core::item_seed(batch_seed, options.first + i)).
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
Definition at line 755 of file namegen.hpp.
The name a woman has after marrying, by the culture's convention.
A single-surname culture gives her the husband's family name, in its married form where the culture has one (Kozlov gives Kozlova); a two-surname or patronymic culture leaves her name as it is. Only the roles of the names are read.
| wife | The woman's name. |
| husband | The husband's name; its culture is the one used. |
Definition at line 859 of file namegen.hpp.
|
inline |
Generate a first name.
| request | Gender and culture (both default to any). |
| std::invalid_argument | If no names loaded for the resolved culture/gender. |
Definition at line 502 of file namegen.hpp.
|
inline |
Generate a deterministic first name using a specific seed.
| request | Gender and culture. |
| call_seed | Seed; the same seed, request and data give the same name on every platform. |
| std::invalid_argument | If no names loaded for the resolved culture/gender. |
Definition at line 513 of file namegen.hpp.
|
inline |
Generate a batch of name results from a seed drawn like get_name() draws its own.
Item i is get_name(request, core::item_seed(batch_seed, options.first + i)) for the drawn batch seed; see the seeded overload.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 530 of file namegen.hpp.
|
inline |
Generate a batch of name results, deterministically.
Item i is exactly get_name(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for name). |
| batch_seed | Seed of the whole batch. |
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 551 of file namegen.hpp.
Name a parent of an existing person, consistently with the person's name; the inverse of get_child_name().
The father's family name is the child's (in its male form where the culture has one), and in a patronymic culture his given name is one whose patronymic is the child's. Two-surname cultures give the surname the child took from this parent, in the slot the culture puts it. Everything the child's name does not fix (the mother's family name, the other surname of a parent, a grandparent's name in a patronymic) is drawn. The culture is the child's. Only the roles of the child's parts are read.
| child | The person's name; its culture is the parent's. |
| parent_gender | gender::m or gender::f. |
| std::invalid_argument | If the child's culture is any, the gender is any, or the culture has no names loaded. |
Definition at line 915 of file namegen.hpp.
|
inline |
Name a parent of an existing person, deterministically.
| child | The person's name; its culture is the parent's. |
| parent_gender | gender::m or gender::f. |
| call_seed | Seed; the same seed, child and data give the same name on every platform. |
| std::invalid_argument | If the child's culture is any, the gender is any, or the culture has no names loaded. |
Definition at line 928 of file namegen.hpp.
|
inline |
Generate a surname.
| request | Culture, and gender for cultures with gendered surnames (both default to any). |
| std::invalid_argument | If no surnames loaded for the resolved culture. |
Definition at line 600 of file namegen.hpp.
|
inline |
Generate a deterministic surname using a specific seed.
| request | Culture and gender. |
| call_seed | Seed for reproducible results. |
| std::invalid_argument | If no surnames loaded for the resolved culture. |
Definition at line 610 of file namegen.hpp.
|
inline |
Generate a batch of surname results from a seed drawn like get_surname() draws its own.
Item i is get_surname(request, core::item_seed(batch_seed, options.first + i)) for the drawn batch seed; see the seeded overload.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 627 of file namegen.hpp.
|
inline |
Generate a batch of surname results, deterministically.
Item i is exactly get_surname(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for name). |
| batch_seed | Seed of the whole batch. |
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 648 of file namegen.hpp.
|
inline |
Check whether any name databases have been loaded.
true if at least one name list is loaded. Definition at line 1024 of file namegen.hpp.
|
inlinestatic |
Access the global singleton instance.
Loads the lite tier on first access (or full when lite is not found), from compiled-in data or an auto-probed resources/. For independent generators, prefer constructing a separate ng instance.
Definition at line 451 of file namegen.hpp.
The layers in effect for one name list.
| c | Culture. |
| g | gender::m or gender::f for forenames, gender::any for surnames. |
| std::out_of_range | If that list was never loaded. |
Definition at line 1198 of file namegen.hpp.
|
inline |
Load name files from a directory, replacing all names and layers loaded before.
Reads every .names file below resource_path, in path order (see doc/usage.md for the format). A path that is not a directory is ignored.
| resource_path | Directory containing .names files, such as resources/lite. |
| core::tsv_error | If a file is malformed; the names are then unchanged. |
Definition at line 1040 of file namegen.hpp.
|
inline |
Load a dataset tier, replacing all names and layers loaded before.
lite uses the compiled-in copy when built with DASMIG_NAME_EMBED. Otherwise the tier is read from the first of resources, ../resources, name-generator/resources and ../name-generator/resources that has it.
| tier | The dataset size to load (dataset::lite or dataset::full). |
true if the tier was found and loaded. | core::tsv_error | If a file is malformed. |
Definition at line 1058 of file namegen.hpp.
|
inlinestatic |
The patronymic a father's given name gives a child.
Rule-based, for names in Latin script, with a short list of irregular names (Pavel to Pavlovich, Jón to Jónsson).
| style | The culture's patronymic style. |
| father | The father's given name. |
| daughter | Whether the child is a daughter. |
Definition at line 989 of file namegen.hpp.
|
inline |
The layers in effect for surname_forms.tsv.
Definition at line 1017 of file namegen.hpp.
|
inline |
The layers in effect for the surnames of one gender.
| c | Culture. |
| g | gender::m or gender::f; gender::any is the surname list shared by both. |
| std::out_of_range | If that list was never loaded (a culture has one only when its surnames change with gender). |
Definition at line 1210 of file namegen.hpp.
|
inlinestatic |
Translate an ISO 3166 2-letter country code to a culture enum.
| country_code | Two-letter country code (e.g., L"us", L"br"). |
Definition at line 460 of file namegen.hpp.
|
inlinestatic |
Translate a gender string to a gender enum.
| gender_string | Gender string (e.g., L"male", L"female", L"m", L"f"). |
Definition at line 473 of file namegen.hpp.
|
friend |
Definition at line 2152 of file namegen.hpp.
|
friend |
Definition at line 2151 of file namegen.hpp.