Skip to content

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

cli

Management script for G2P

Usage:

cli [OPTIONS] COMMAND [ARGS]...

Options:

  -e, --env-file FILE   Load environment variables from this file. python-
                        dotenv must be installed.
  -A, --app IMPORT      The Flask application or factory function to load, in
                        the form 'module:name'. Module can be a dotted import
                        or file path. Name is not required if it is 'app',
                        'application', 'create_app', or 'make_app', and can be
                        'name(args)' to pass arguments.
  --debug / --no-debug  Set debug mode.
  --version             Show the Flask version.
  --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:

cli 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
  -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:

  1. 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:

cli 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:

cli 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.

routes

Show all registered routes with endpoints and methods.

Usage:

cli routes [OPTIONS]

Options:

  -s, --sort [endpoint|methods|rule|match]
                                  Method to sort routes by. "match" is the
                                  order that Flask will match routes when
                                  dispatching a request.
  --all-methods                   Show HEAD and OPTIONS methods.
  --help                          Show this message and exit.

run

Run a local development server.

This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers.

The reloader and debugger are enabled by default with the '--debug' option.

Usage:

cli run [OPTIONS]

Options:

  --debug / --no-debug            Set debug mode.
  -h, --host TEXT                 The interface to bind to.
  -p, --port INTEGER              The port to bind to.
  --cert PATH                     Specify a certificate file to use HTTPS.
  --key FILE                      The key file to use when specifying a
                                  certificate.
  --reload / --no-reload          Enable or disable the reloader. By default
                                  the reloader is active if debug is enabled.
  --debugger / --no-debugger      Enable or disable the debugger. By default
                                  the debugger is active if debug is enabled.
  --with-threads / --without-threads
                                  Enable or disable multithreading.
  --extra-files PATH              Extra files that trigger a reload on change.
                                  Multiple paths are separated by ';'.
  --exclude-patterns PATH         Files matching these fnmatch patterns will
                                  not trigger a reload on change. Multiple
                                  patterns are separated by ';'.
  --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:

cli scan [OPTIONS] LANG PATH

Options:

  --help  Show this message and exit.

shell

Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration.

This is useful for executing small snippets of management code without having to manually configure the application.

Usage:

cli shell [OPTIONS]

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:

cli 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:

cli update [OPTIONS]

Options:

  -o, --out-dir DIRECTORY  Output results in DIRECTORY instead of the
                           installed directory (c:\users\joanise\sandboxes\g2p
                           \g2p\mappings\langs).
  -i, --in-dir DIRECTORY   Scan DIRECTORY for mappings instead of the
                           installed directory (c:\users\joanise\sandboxes\g2p
                           \g2p\mappings\langs).
  --help                   Show this message and exit.

Comments