Пример #1
0
def main():
    if len(sys.argv) != 2:
        print(f"使用方法: python3 {sys.argv[0]} words.txt", file=sys.stderr)
        print("文件行格式:word [w1_yin w2_yin ... prioroty]")
        print("举例:你好 [ni hao 100]")
        print("中括号内为可选内容")
        sys.exit(1)

    _, words_path = sys.argv

    add_words = load_words(words_path)
    print(add_words)
    with db.atomic():
        WordPhoneTable.bulk_create(add_words, batch_size=100)

    print(f'done, add {len(add_words)} items')
Пример #2
0
                        word_phones.append((word, f"{c1}{c2}"))
            elif len(phones) == 3:
                for c1 in phones[0]:
                    for c2 in phones[1]:
                        for c3 in phones[2]:
                            word_phones.append((word, f"{c1}{c2}{c3}"))
            else:
                print(f"{word} {phones} lenght great than 3, exiting...")
                sys.exit(1)
            
        to_add_items = [] 
        exist_items = set()
        for (word, phones) in word_phones:
            if f"{word}{phones}" in exist_items:
                continue
            if len(phones) != len(word)*2:
                print(f"D: {word} {phones} wrong.")
                continue
            num = WordPhoneTable.select().where(WordPhoneTable.word == word, WordPhoneTable.phones == phones).count()
            if num > 0:
                continue
            to_add_items.append(WordPhoneTable(word=word, phones=phones, priority=1, updatedt=datetime.now()))
            exist_items.add(f"{word}{phones}")
            # WordPhoneTable(word=word, phones=phones, priority=1, updatedt=datetime.now()).save()
        print(f"add length {len(to_add_items)}")
        with db.atomic():
            WordPhoneTable.bulk_create(to_add_items, batch_size=100)
    print('done')
    pass