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_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)
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