Parser

Parses verbs

Attributes:

  • _ALPHABET (dict) –

    maps "chars" to a list of characters in the alphabet

  • _SUFFIXES (dict) –

    maps suffix types to lists of suffixes of that type and their properties

  • _SUFFIX_TYPES (dict) –

    maps integers to suffix types (in order that they appear in _SUFFIXES)

  • _VOWELS (dict) –

    maps vowel types (length and tone) to lists of vowels

  • _CONSONANTS (dict) –

    maps consonant types (short and long) to list of consonants

  • _REPLACE_MAP (dict) –

    maps common variations of diacritics to the correct ones

  • _VOWEL_MAP (dict) –

    maps long vowels to short vowels

  • _VOICING_MAP (dict) –

    maps voiced consonants to unvoiced

__init__

__init__()

Create parser and initialize data

_load_json

_load_json(filename: str) -> dict

Read json from a file in the package

Parameters:

  • filename (str) –

    file to read

Returns:

  • dict –

    contents of file

_normalize_word

_normalize_word(word: str) -> str

Return a normalized form of the verb

Removes whitespace and accents that are not considered during parsing. Also normalizes diacritics and capitalization.

Parameters:

  • word (str) –

    a verb

Returns:

  • str –

    normalized version of word

_parse_ending

_parse_ending(
    word: Verb, ending_list: list[str]
) -> list[Verb]

Parse an substring ("ending") from the right of the verb

Parameters:

  • word (Verb) –

    verb to start with

  • ending_list (list[str]) –

    list of endings to try and parse

Returns:

  • list[Verb] –

    list of parsings with any one of the endings from the list parsed, empty if none can be parsed

_parse_last_CV

_parse_last_CV(word: Verb) -> list[Verb]

Parse a CV or CVV syllable from the right of the verb

Parameters:

  • word (Verb) –

    verb to start with

Returns:

  • list[Verb] –

    list of parsings with last syllable parsed, empty if verb does not end with a CV/CVV syllable

_parse_last_CVC

_parse_last_CVC(word: Verb) -> list[Verb]

Parse an CVC or CVVC syllable from the right of the verb

Parameters:

  • word (Verb) –

    verb to start with

Returns:

  • list[Verb] –

    list of parsings with last syllable parsed, empty if verb does not end with a CVC/CVVC syllable

_parse_last_consonant

_parse_last_consonant(word: Verb) -> list[Verb]

Parse rightmost consonant

Parameters:

  • word (Verb) –

    verb to start with

Returns:

  • list[Verb] –

    list of parsings with any one consonant parsed, empty if verb does not end with a consonant

_parse_last_vowel

_parse_last_vowel(word: Verb) -> list[Verb]

Parse rightmost vowel

Parameters:

  • word (Verb) –

    verb to start with

Returns:

  • list[Verb] –

    list of parsings with any one vowel parsed, empty if verb does not end with a vowel

_parse_suffix

_parse_suffix(
    word: Verb, suffix_list: list[dict[str, str]]
) -> list[Verb]

Parse a rightmost suffix from a list

Parameters:

  • word (Verb) –

    verb to start with

  • suffix_list (list[dict[str, str]]) –

    list of suffixes to try and parse

Returns:

  • list[Verb] –

    list of parsings with any one of the suffixes from the list parsed, empty if verb doesn't end with any of them

_parse_suffixes

_parse_suffixes(word: Verb) -> list[Verb]

Parse all possible suffixes

Considers at most one suffix of each type, in the order of _SUFFIX_TYPES. Uses depth first search to go through parse tree.

Parameters:

  • word (Verb) –

    verb to start with

Returns:

  • list[Verb] –

    list of parsings with all suffixes parsed, empty if the verb does not have a suffix (from the dataset)

_recover_root

_recover_root(word: Verb) -> list[Verb]

Undo stem changes to recover possible roots

Removes tones and changes long vowels to their corresponding short vowel. Adds possible roots before ablaut, if applicable

Parameters:

  • word (Verb) –

    parsed verb to recover root from

Returns:

  • list[Verb] –

    list of parsed verbs with the root attribute set

parse_word

parse_word(
    word: str, no_display: bool = False
) -> list[tuple[str, str, str]]

Get possible parsings of a given verb

Parameters:

  • word (str) –

    the verb, as a string

  • no_display (bool, default: False ) –

    whether the results should be printed ("displayed") in addition to being returned

Returns:

  • list[tuple[str, str, str]] –

    Possible parsings in format (prefixes, root, suffixes)

Verb

Represent verb parsings

Represents verb as prefix, stem, suffix. Also includes the parsed root and information like form, tone, phonetic/orthographic changes, etc.

Attributes:

  • prefix (str) –

    un-parsed part of the verb

  • stem (str) –

    part of the verb that corresponds to the root

  • suffix (str) –

    parsed suffixes

  • root (str) –

    stem after removing changes such as tone and vowel length

  • root_form (str) –

    whether the root is CV or CVC, based on suffixes

  • ablaut (bool) –

    whether the root may have been ablaut-ed, based on suffixes

__init__

__init__(
    prefix_or_full: str,
    stem: str = "",
    suffix: str = "",
    root: str = "",
)

Initializes verb object

If one argument is given, it is set as the prefix. If stem or suffix are given, they are set accordingly.

Parameters:

  • prefix_or_full (str) –

    prefix or the entire verb

  • stem (str, default: '' ) –

    stem

  • suffix (str, default: '' ) –

    suffixes as one string

  • root (str, default: '' ) –

    the root, if known

__str__

__str__() -> str

Simple string representation

Returns:

  • str –

    prefix, stem, and suffix concatenated

to_string

to_string(sep_char: str = '|') -> str

Fancy string representation

Parameters:

  • sep_char (str, default: '|' ) –

    character to indicate each part of the verb

Returns:

  • str –

    prefix, stem, and suffix separated by sep_char

to_tuple_root

to_tuple_root() -> tuple[str, str, str]

Tuple representation with root as 2nd item

Returns:

  • tuple[str, str, str] –

    (prefix, root, suffix) tuple

to_tuple_stem

to_tuple_stem() -> tuple[str, str, str]

Tuple representation with stem as 2nd item

Returns:

  • tuple[str, str, str] –

    (prefix, stem, suffix) tuple