Esempio n. 1
0
def cols_to_word_phone_table(cols: List[str], xhe_transformer, zrm_transformer) -> WordPhoneTable:
    if len(cols) == 1:
        word = cols[0]
        priority = 1
        full = get_full(word)
    elif len(cols) == 2:
        word = cols[0]
        priority = cols[1]
        full = get_full(word)
    elif len(cols) == 2 + len(cols[0]):
        word = cols[0]
        priority = cols[1]
        full = list(filter(lambda e: len(e) > 0, [e.strip() for e in cols[2:]]))
    else:
        raise RuntimeError("word item should be: 你好 [priority n i h ao]")

    return WordPhoneTable(
        word=word, 
        full=''.join(full),
        xhe=''.join([full_to_two(e, xhe_transformer) for e in full]),
        zrm=''.join([full_to_two(e, zrm_transformer) for e in full]),
        lu="",
        priority=priority, 
        updatedt=datetime.now()
    )
Esempio n. 2
0
def cols_to_tangshi_item(cols: List[str], xhe_transformer, zrm_transformer,
                         bingji_transformer, lu_transformer) -> TangshiTable:
    if len(cols) == 1:
        word = cols[0]
        priority = 100
        full = get_full(word)
    elif len(cols) == 2:
        word = cols[0]
        priority = cols[1]
        full = get_full(word)
    elif len(cols) == 2 + len(cols[0]):
        word = cols[0]
        priority = cols[1]
        full = list(filter(lambda e: len(e) > 0,
                           [e.strip() for e in cols[2:]]))
    else:
        raise RuntimeError("word item should be: 你好 [priority ni hao]")

    item = TangshiTable(
        word=word,
        full=' '.join(full),
        xhe=''.join([full_to_two(e, xhe_transformer) for e in full]),
        zrm=''.join([full_to_two(e, zrm_transformer) for e in full]),
        lu=''.join([full_to_two(e, lu_transformer) for e in full]),
        priority=priority,
        updatedt=datetime.now(),
        bingji=''.join(
            full_to_two(e, bingji_transformer, bingji=True) for e in full))
    print("add ", item)
    return item
Esempio n. 3
0
def is_diff_s_same_y_full(item: CharPhoneTable,
                          transformer: Dict[str, str]) -> bool:
    two = full_to_two(item.full, transformer)
    if two[0] != item.phones[0] and two[1] == item.phones[1]:
        return True
    else:
        return False
Esempio n. 4
0
def cols_to_word_phone_table(cols: List[str], xhe_transformer, zrm_transformer,
                             bingji_transformer,
                             lu_transformer) -> Union[WordPhoneTable, None]:
    if len(cols) == 1:
        word = cols[0]
        priority = 100
        try:
            full = get_full(word)
        except Exception as e:
            print(e)
            return None
    # elif len(cols) == 2:
    #     word = cols[0]
    #     priority = cols[1]
    #     full = get_full(word)
    elif len(cols) == 1 + len(cols[0]):
        word = cols[0]
        priority = 100
        full = list(filter(lambda e: len(e) > 0,
                           [e.strip() for e in cols[1:]]))
    elif len(cols) == 2 + len(cols[0]):
        word = cols[0]
        priority = int(cols[-1])
        full = list(
            filter(lambda e: len(e) > 0,
                   [e.strip() for e in cols[1:len(cols)]]))
    else:
        raise RuntimeError("word item should be: 你好 [ni hao 100]")

    item = WordPhoneTable(
        word=word,
        full=' '.join(full),
        xhe=''.join([full_to_two(e, xhe_transformer) for e in full]),
        zrm=''.join([full_to_two(e, zrm_transformer) for e in full]),
        lu=''.join([full_to_two(e, lu_transformer) for e in full]),
        priority=priority,
        updatedt=datetime.now(),
        bingji=''.join(
            full_to_two(e, bingji_transformer, bingji=True) for e in full))
    print("add ", item)
    return item
Esempio n. 5
0
        list,
    )
    if len(null_full_items) != 0:
        print(f"null full items is {len(null_full_items)}")
        pipe(
            null_full_items,
            map(lambda e: (e, ''.join(get_full(e.char)))),
            map(lambda e: update_full(e[0], e[1])),
            for_each(lambda e: e.save()),
        )
    del null_full_items

    full_to_xhe_transformer = get_full_to_xhe_transformer()
    xhe_full_neq_items = pipe(
        CharPhoneTable.select(),
        filter(lambda e: e.phones != full_to_two(e.full,
                                                 full_to_xhe_transformer)),
        list,
    )
    if len(xhe_full_neq_items) != 0:
        print(f"xhe full not equal len is {len(xhe_full_neq_items)}")

        pipe(
            xhe_full_neq_items,
            filter(
                lambda e: is_diff_s_same_y_full(e, full_to_xhe_transformer)),
            map(fix_diff_s_same_y_full),
            for_each(lambda e: e.save()),
        )

        xhe_to_full_transformer = get_xhe_to_full_transformer()
        pipe(