Command line interface¶
There is a command line interface bundled with g2p that allows both basic and advanced functionality to be accessed from your command line. After installing g2p, you can get information about how to use the command line by running g2p --help
g2p¶
Management script for G2P
Usage:
g2p [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
--help Show this message and exit.
convert¶
Convert INPUT_TEXT through g2p mapping(s) from IN_LANG to OUT_LANG.
Visit http://g2p-studio.herokuapp.com/api/v1/langs for a list of languages.
There must be a path from IN_LANG to OUT_LANG, possibly via some intermediates. For example, mapping from fra to eng-arpabet will successively apply fra->fra-ipa, fra-ipa->eng-ipa and eng-ipa->eng-arpabet.
Usage:
g2p convert [OPTIONS] INPUT_TEXT IN_LANG OUT_LANG
Options:
--config FILE A path to a mapping configuration file to
use
-t, --tok / --no-tok Tokenize INPUT_TEXT before converting.
Default is --tok, specify --no-tok to turn
off.
--tok-lang TEXT Override the tokenizing language. Implies
--tok.
-c, --check / --no-check Check IPA outputs against panphon and/or
eng-arpabet output against ARPABET
-f, --file Read input from plain-text file INPUT_TEXT.
-d, --debugger / --no-debugger Show all the conversion steps applied.
-e, --pretty-edges Show the traduction graph in a pretty,
plain-text format.
-a, --substring-alignments Show the minimal monotonic substring
alignments.
--help Show this message and exit.
doctor¶
Check for common errors in mappings.
There should eventually be more checks here, but doctor currently checks for:
- Characters that are in IPA mappings but are not recognized by panphon library.
You can list available mappings with --list-all or --list-ipa, or by visiting http://g2p-studio.herokuapp.com/api/v1/langs .
Usage:
g2p doctor [OPTIONS]
Options:
-m, --mapping TEXT Check specified IPA mapping(s) (default: check all IPA
mappings).
--list-ipa List IPA mappings that can be specified
--list-all List all mappings that can be specified
--help Show this message and exit.
generate-mapping¶
Generate a new mapping from existing mappings in the g2p system.
This command has different modes of operation.
Standard mode:
g2p generate-mapping [--dummy|--ipa] IN_LANG [OUT_LANG]
For specified IN_LANG, generate a mapping from IN_LANG-ipa to eng-ipa, or from IN_LANG-ipa to a dummy minimalist phone inventory. This assumes the mapping IN_LANG -> IN_LANG-ipa exists and creates a mapping from its output inventory.
To generate a mapping from IN_LANG-ipa to eng-ipa from a mapping following a different patterns, e.g., from crl-equiv -> crl-ipa, specify both IN_LANG (crl-equiv in this example) and OUT_LANG (crl-ipa in this example).
Sample usage: Generate Algonquin IPA to English IPA from alq -> alq-ipa: g2p generate-mapping --ipa alq Generate Mohawk IPA to English IPA from moh-equiv -> moh-ipa: g2p generate-mapping --ipa moh-equiv moh-ipa Generate Michif IPA to English IPA from the union of crg-dv -> crg-ipa and crg-tmd -> crg-ipa: g2p generate-mapping --ipa --merge crg-dv:crg-tmd crg-ipa
List the dummy inventory used by --dummy:
g2p generate-mapping --list-dummy
From/to IPA mode:
g2p generate-mapping --from FROM_L1 --to TO_L1 g2p generate-mapping --from FROM_L1:FROM_L2:... --to TO_L1:TO_L2:...
Generate an IPA mapping from the union of FROM_L1-ipa, FROM-L2-ipa, etc to the union of TO_L1-ipa, TO-L2-ipa, etc. One or more from/to language code(s) can be specified in colon- or comma-separated lists. Note, by default we use Panphon's weighted_feature_edit_distance, but you can change this with the --distance argument
Sample usage: Generate a mapping from kwk-ipa to moh-ipa based on all mappings into kwk-ipa and moh-ipa: g2p generate-mapping --from kwk --to moh Generate a mapping from eng-ipa to crg-ipa based only on crg-dv -> crg-ipa: g2p generate-mapping --from eng --to crg-dv_to_crg-ipa Generate a mapping from kwk-ipa to moh-ipa+crg-ipa+eng-ipa based on all mappings into kwk-ipa (from side) and the union of all mappings into moh-ipa and crg-ipa plus eng-ipa_to_eng-arpabet (to side): g2p generate-mapping --from kwk --to moh:crg:eng
Full syntax for specifying FROM_Ln and TO_Ln:
lang (i.e., 3-letter code):
- If there is only one mapping into lang-ipa, "lang" refers to the
output of that mapping, e.g., "fra" means "fra_to_fra-ipa[out]".
- If there are several mappings into lang-ipa, "lang" refers to the
union of the outputs of those mappings, e.g., "moh" means the union
of "moh-equiv_to_moh-ipa[out]" and "moh-festival_to_moh-ipa[out]".
- It is an error if there are no mappings into lang-ipa.
- Only mappings from non-IPA to IPA are considered (i.e., IPA-to-IPA
mappings created by this command will not be included: use the
longer syntax below if you want to use them).
- Special case: "eng" refers to "eng-ipa_to_eng-arpabet[in]".
in-lang_to_out-lang[[in]|[out]]:
- This expanded syntax is used to avoid the union when it is not
desired, e.g., "moh-equiv_to_moh-ipa" refers only to
"moh-equiv_to_moh-ipa,out" rather than the union "moh" represents.
- If out-lang is IPA, the output inventory is used; else if in-lang
is IPA, the input inventory is used; it is an error if neither
language is IPA.
- Specify "[in]" or "[out]" to override the above default.
- "_to_" is the joiner used to specify "the mapping from 'in-lang' to
'out-lang'" in the g2p network, regardless of the name of the file
it is stored in.
If you just modified or created the mappings from which the new mapping is to be generated, don't forget to call "g2p update" first, so that "g2p generate-mapping" can see the latest version.
Call "g2p update" again after calling "g2p generate-mapping" to compile the newly generated mapping and make it available.
Note: exactly one of --ipa, --dummy, --from/--to, or --list-dummy is required.
You can list available mappings with "g2p doctor --list-ipa", or by visiting http://g2p-studio.herokuapp.com/api/v1/langs .
Usage:
g2p generate-mapping [OPTIONS] [IN_LANG] [OUT_LANG]
Options:
--distance [weighted_feature_edit_distance|hamming_feature_edit_distance|feature_edit_distance|dolgo_prime_distance|fast_levenshtein_distance|levenshtein_distance]
--merge / --no-merge Merge multiple mappings together, in which
case IN_LANG is a colon-seperated list and
OUT_LANG is required.
--ipa / --no-ipa Generate mapping from LANG-ipa to eng-ipa.
--dummy / --no-dummy Generate dummy fallback mapping to
minimalist phone inventory.
--list-dummy List the dummy phone inventory.
--from TEXT Colon- or comma-separated list of "from"
languages in from/to mode
--to TEXT Colon- or comma-separated list of "to"
languages in from/to mode
--out-dir DIRECTORY Output results in DIRECTORY instead of the
global "generated" directory.
--help Show this message and exit.
scan¶
Scan a document for non target language characters.
Displays the set of un-mapped characters in a document. Accounts for case sensitivity in the configuration.
Usage:
g2p scan [OPTIONS] LANG PATH
Options:
--help Show this message and exit.
show-mappings¶
Show cached mappings, as last updated by "g2p update".
Mappings on the path from LANG1 to LANG2 are displayed. If only LANG1 is used, all mappings to or from LANG1 are displayed. With no LANG, all cached mappings are included.
Usage:
g2p show-mappings [OPTIONS] [LANG1] [LANG2]
Options:
-v, --verbose Display mapping configs and all rules too.
--csv Output mappings in CSV format.
--help Show this message and exit.
update¶
Update cached language files.
Usage:
g2p update [OPTIONS]
Options:
-o, --out-dir DIRECTORY Output results in DIRECTORY instead of the
installed directory
(/home/runner/work/g2p/g2p/g2p/mappings/langs).
-i, --in-dir DIRECTORY Scan DIRECTORY for mappings instead of the
installed directory
(/home/runner/work/g2p/g2p/g2p/mappings/langs).
--help Show this message and exit.
update-schema¶
Generate a schema for the model configuration.
This should be done every time the model changes in a way that affects the schema. Changes to the schema should result in a minor version bump. But not every minor or major version bump requires a schema update.
Usage:
g2p update-schema [OPTIONS]
Options:
-o, --out-dir DIRECTORY Output results in DIRECTORY instead of the
installed directory (/home/runner/work/g2p/g2p/g2p/
mappings/langs/../.schema).
--help Show this message and exit.