Beispiel #1
0
def lookup(query):
    """
    Lookup a bit of pronunciation or grammar. Accepts pronunciation fragments,
    IME text, grammar table keys, and string representations of table keys.
    """
    result = []

    if isinstance(query, (list, tuple, set, frozenset)):
        return lookup_key(query)

    # Try to interpret the query as slash-separated key values instead of tuple
    # key values.
    # Do this before adding phonology.
    pieces = query.split('/')
    result.extend(lookup_key(pieces))

    # Try to interpret the query as an affix.
    query = convert_ascii(query)
    for rtable in [
        vr_table_reverse,
        vc_table_reverse,
        ca_table_reverse,
    ]:
        key = rtable.get(query)
        if key is not None:
            result.append(canonical_keys[key])

    return result
 def test(word):
     assert_equal(split_ascii(word), split_word)
     assert_equal(
         [
             convert_ascii_reverse(letter) for letter in
             split_unicode(convert_ascii(word))
         ],
         split_word
     )
Beispiel #3
0
def deconstruct_formative(word):
    """
    Deconstruct a formative into its root and affixes, and lookup the meaning of each.

    Currently only handles the simplified structure:
    Vr+Cr+Vc(+Ci+Vi)+Ca(+Vf(+Cb))[+Tone]
    """
    word = convert_ascii(word).lower()
    parsed_word = parse_formative(word)
    if parsed_word is None:
        return None  # Could not understand word structure.
    tone, vr, cr, vc, civi, ca, vf, cb = parsed_word
    result = []

    version = version_table_reverse[tone]
    result.append(('Tone', unicode_tone_names[tone], version))

    vr_key = vr_table_reverse[vr]
    result.append(('Vr', vr, canonical_keys[vr_key]))

    meaning = lexicon_table[cr.upper()]
    result.append(('Cr', cr, meaning))

    vc_key = vc_table_reverse[vc]
    result.append(('Vc', vc, canonical_keys[vc_key]))

    civi_key = civi_table_reverse[civi]
    result.append(('Ci+Vi', civi, canonical_keys[civi_key]))

    ca_key = ca_table_reverse[ca]
    result.append(('Ca', ca, canonical_keys[ca_key]))

    vf_key = vf_table_reverse[vf]
    result.append(('Vf', vf, canonical_keys[vf_key]))

    cb_key = cb_table_reverse[cb]
    result.append(('Cb', cb, canonical_keys[cb_key]))

    return result
Beispiel #4
0
    return output


if __name__ == '__main__':
    print('Type text to convert, "h" for help, or "q" to quit.')
    while True:
        try:
            typed = input('> ')
        except (EOFError, KeyboardInterrupt):
            break
        if typed == 'q':
            break
        elif typed == 'h':
            print(format_help())
        else:
            text = convert_ascii(typed)
            print(text)
            for word in text.split():
                word = word.strip()
                if word == '':
                    continue
                print()
                print('"{}"'.format(word))
                deconstruction = deconstruct_formative(word)
                if deconstruction is None:
                    print('???')
                else:
                    for slot, value, meaning in deconstruction:
                        if value == '':
                            print('  {} empty'.format(slot))
                        else:
 def test(ascii_word):
     assert_equal(convert_ascii(ascii_word), unicode_word)
Beispiel #6
0
def lookup_lexicon(root):
    root = convert_ascii(root)
    root = root.upper()
    return lexicon_table.get(root)