Beispiel #1
0
def add_spec_info_to_bg():
    """
    8. Для всех ЗС групп из док-та Добавить группы в БС. Прил-ные.txt
    сделать следующее:
    8.1. скопировать ВСЮ спец. информацию у такого ЗС группы,
    8.2. найти такое слово в док-те БГ 24.01.21.txt и
    8.3. добавить скопированную спец. информацию к найденному слову.
    """
    socket_group_word_form_list = list(
        read_src_socket_bs('src_dict/БГ 24.01.21.txt'))

    adjectives = list(
        read_src_bs('src_dict/Добавить группы в БС. Прил-ные.txt',
                    encoding='utf-8'))

    for adj in adjectives:
        title_word_form = adj.title_word_form
        idf = title_word_form.idf
        info = title_word_form.info
        for socket_group_word_form in socket_group_word_form_list:
            for socket_word_form in socket_group_word_form.socket_word_forms:
                s_socket_name = socket_word_form.name.replace('*', '').strip()
                s_title_name = title_word_form.name.replace('*', '').strip()
                if s_socket_name == s_title_name:
                    print(socket_word_form.name)
                    socket_word_form.idf = idf
                    socket_word_form.info = info

    save_socket_bs_dicts_to_txt(socket_group_word_form_list,
                                'out/БГ 27.01.21.txt')
Beispiel #2
0
def remove_from_bg():
    """
    9. Для всех слов из док-та "Удалить из БГ.txt" сделать следующее:
    9.1. найти такое слово в док-те "БГ 27.01.21.txt" и,
    9.2.1. если оно является ЗС ПОДгруппы - вставить его
    в отдельно созданный док-т "ЗС подгруппы.txt"
    9.2.2. если оно НЕ является ЗС ПОДгруппы - удалить его
    из док-та "БГ 27.01.21.txt"
    """
    remove_bg_list = get_string_list_from_file('src_dict/Удалить из БГ.txt')
    socket_group_word_form_list = list(
        read_src_socket_bs('src_dict/БГ 27.01.21.txt'))

    title_form_list = []
    deleted_list = []

    for remove_bg in sorted(remove_bg_list):
        for group in socket_group_word_form_list:
            for sub_group in group.sub_groups:
                title_word_form = sub_group.title_word_form
                for word_form in sub_group.socket_word_forms[:]:
                    if remove_bg == word_form.name:
                        print(word_form)
                        if remove_bg == title_word_form.name:
                            title_form_list.append(str(word_form))
                        else:
                            deleted_list.append(str(word_form))
                            sub_group.socket_word_forms.remove(word_form)

    save_list_to_file(sorted(title_form_list, key=str.lower),
                      'out/ЗС подгруппы.txt')
    save_list_to_file(sorted(deleted_list, key=str.lower),
                      'out/удалённые из БГ.txt')
    save_socket_bs_dicts_to_txt(socket_group_word_form_list,
                                'out/БГ 28.01.21.txt')
Beispiel #3
0
def add_spec_info_to_bg():
    """
    5. Для всех ЗС групп из док-тов
    Добавить группы в БС. Сущ-ные изм.txt
    и Добавить группы в БС. Сущ-ные 2.txt:
    5.1. скопировать ВСЮ спец. информацию у такого ЗС группы,
    5.2. найти такое слово в док-те БГ 08.01.21.txt и
    5.3. добавить скопированную спец. информацию к найденному слову.
    """
    socket_group_word_form_list = list(
        read_src_socket_bs('src_dict/БГ 08.01.21.txt'))

    modified_nouns = list(read_src_bs(
        'src_dict/Добавить группы в БС. Сущ-ные изм.txt'))
    nouns_2 = list(read_src_bs('src_dict/Добавить группы в БС. Сущ-ные 2.txt',
                               encoding='utf-8'))
    group_word_form_list = modified_nouns + nouns_2

    for group_word_form in group_word_form_list:
        title_word_form = group_word_form.title_word_form
        idf = title_word_form.idf
        info = title_word_form.info
        for socket_group_word_form in socket_group_word_form_list:
            for socket_word_form in socket_group_word_form.socket_word_forms:
                s_socket_name = socket_word_form.name.replace('*', '').strip()
                s_title_name = title_word_form.name.replace('*', '').strip()
                if s_socket_name == s_title_name:
                    print(socket_word_form.name)
                    socket_word_form.idf = idf
                    socket_word_form.info = info

    save_socket_bs_dicts_to_txt(socket_group_word_form_list,
                                'out/БГ 23.01.21.txt')
Beispiel #4
0
def check_bg_islower():
    socket_group_list = read_src_socket_bs('src_dict/БГ 16.03.21 изм.txt')

    bg_islower_name_list = []
    bg_islower_note_list = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if not word_form.invisible:

                    if not word_form.name.islower():
                        print(word_form)
                        bg_islower_name_list.append(str(word_form))

                    note_form = ' '.join(
                        filter(None, [
                            word_form.note,
                            word_form.etml_note,
                            word_form.spec_note,
                        ]))

                    if any(map(lambda x: x in CYRILLIC, note_form)):
                        print(note_form)
                        bg_islower_note_list.append(str(word_form))

    save_list_to_file(bg_islower_name_list,
                      'out/БГ ЕСТЬ большие буквы СЛОВО.txt')
    save_list_to_file(bg_islower_note_list,
                      'out/БГ ЕСТЬ большие буквы ПРИМЕЧАНИЯ.txt')
Beispiel #5
0
def get_bg_abbreviation():
    socket_group_list = read_src_socket_bs('src_dict/БГ 09.03.21.txt')

    abbreviation_bg = []
    capital_letter_bg = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if not word_form.invisible:
                    form_name = word_form.name.replace('*', '')
                    chars = set(form_name[:2])
                    if all(map(lambda x: x in CYRILLIC, chars)):
                        abbreviation_bg.append(str(word_form))
                    elif form_name[0] in CYRILLIC:
                        capital_letter_bg.append(str(word_form))

    save_list_to_file(
        sorted(abbreviation_bg, key=lambda x: x.replace('*', '')),
        'out/Аббревиатура. БГ.txt'
    )

    save_list_to_file(
        sorted(capital_letter_bg, key=lambda x: x.replace('*', '')),
        'out/Большая буква. БГ.txt'
    )
Beispiel #6
0
def add_spec_info_to_bg():
    """
    12. Для всех ЗС групп из док-та Добавить группы в БС. Глаголы изм.txt
    сделать следующее:
    12.1. скопировать ВСЮ спец. информацию у такого ЗС группы,
    12.2. найти такое слово в док-те БГ 30.01.21.txt и
    12.3. добавить скопированную спец. информацию к найденному слову.
    """
    socket_group_word_form_list = list(
        read_src_socket_bs('src_dict/БГ 30.01.21.txt'))

    verbs = list(read_src_bs(
        'src_dict/Добавить группы в БС. Глаголы изм.txt', encoding='utf-8'))

    for verb in verbs:
        title_word_form = verb.title_word_form
        idf = title_word_form.idf
        info = title_word_form.info
        for socket_group_word_form in socket_group_word_form_list:
            for socket_word_form in socket_group_word_form.socket_word_forms:
                s_socket_name = socket_word_form.name.replace('*', '').strip()
                s_title_name = title_word_form.name.replace('*', '').strip()
                if s_socket_name == s_title_name:
                    print(socket_word_form.name)
                    socket_word_form.idf = idf
                    socket_word_form.info = info

    save_socket_bs_dicts_to_txt(socket_group_word_form_list,
                                'out/БГ 03.02.21.txt')
Beispiel #7
0
def get_bg_abbreviation_homonyms():
    abbreviation_bg = get_string_list_from_file('out/Аббревиатура. БГ.txt')
    abbreviation_bg = sorted(list(set(abbreviation_bg)))

    socket_group_list = list(read_src_socket_bs('src_dict/БГ 13.03.21.txt'))

    bg_abbreviation_homonyms = []

    for abbreviation in abbreviation_bg:
        abbreviation_name = get_socket_word_form(abbreviation).name
        word_form_list = []
        for socket_group in socket_group_list:
            for sub_group in socket_group.sub_groups:
                for word_form in sub_group.socket_word_forms:
                    if not word_form.invisible:
                        form_name = word_form.name.replace('*', '')
                        if form_name == abbreviation_name.lower():
                            print(form_name)
                            word_form_list.append(str(word_form))
        if word_form_list:
            bg_abbreviation_homonyms.append(abbreviation)
            bg_abbreviation_homonyms += word_form_list
            bg_abbreviation_homonyms.append('')

    save_list_to_file(bg_abbreviation_homonyms[:-1],
                      'out/Аббревиатура. БГ. Омонимы.txt')
Beispiel #8
0
def get_capital_letter_bg():
    capital_letter_bg = list(
        get_string_list_from_file('out/Большая буква. БГ.txt'))
    socket_group_list = list(read_src_socket_bs('src_dict/БГ 13.03.21.txt'))

    capital_letter_bg_homonyms = []

    for capital_word in capital_letter_bg:
        capital_word_name = get_socket_word_form(capital_word).name
        word_form_list = []
        for socket_group in socket_group_list:
            for sub_group in socket_group.sub_groups:
                for word_form in sub_group.socket_word_forms:
                    if not word_form.invisible:
                        form_name = word_form.name.replace('*', '')
                        if form_name == capital_word_name.lower():
                            print(word_form)
                            word_form_list.append(str(word_form))

        if word_form_list:
            capital_letter_bg_homonyms.append(capital_word)
            capital_letter_bg_homonyms += word_form_list
            capital_letter_bg_homonyms.append('')

    save_list_to_file(capital_letter_bg_homonyms[:-1],
                      'out/Большая буква. БГ. Омонимы.txt')
Beispiel #9
0
def get_homonymous_multi_rooted():
    multi_root_words = get_dicts_from_csv_file(
        'src_dict/Многокорневые слова.csv')

    multi_root_names = []
    for multi_root_word in multi_root_words:
        for root_index_key in list(multi_root_word):
            if multi_root_word[root_index_key]:
                multi_root_names.append(
                    get_socket_word_form(multi_root_word[root_index_key]).name)

    socket_group_list = list(read_src_socket_bs('src_dict/БГ 10.04.21.txt'))

    homonymous_multi_rooted = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            title_word_form = sub_group.title_word_form
            for word_form in sub_group.socket_word_forms:
                if (not word_form.invisible and not word_form.root_index):
                    if word_form.name in multi_root_names:
                        print(word_form)
                        if str(word_form) == str(title_word_form):
                            homonymous_multi_rooted.append(str(word_form))
                        else:
                            homonymous_multi_rooted.append(' < '.join([
                                str(word_form),
                                str(title_word_form),
                            ]))

    homonymous_multi_rooted = sorted(
        homonymous_multi_rooted,
        key=lambda x: x.replace('*', '').strip().lower())
    save_list_to_file(homonymous_multi_rooted,
                      'out/Слова, омонимичные многокорневым словам.txt')
Beispiel #10
0
def get_replays_in_groups():
    socket_group_list = read_src_socket_bs('src_dict/БГ 16.02.21.txt')

    replays_in_groups = []

    for socket_group in socket_group_list:
        socket_word_forms = socket_group.socket_word_forms
        socket_word_forms = [x for x in socket_word_forms if not x.invisible]
        socket_names = [x.name for x in socket_word_forms]
        replays_names = sorted(
            list(set([x for x in socket_names if socket_names.count(x) > 1])))

        if replays_names:
            replays_in_groups.append(str(socket_group.socket_word_forms[0]))
            for sub_group in socket_group.sub_groups:
                flag = True
                for word_form in sub_group.socket_word_forms:
                    if word_form.name in replays_names:
                        if flag:
                            replays_in_groups.append(' '.join([
                                '!',
                                str(sub_group.title_word_form),
                            ]))
                            flag = False
                        replays_in_groups.append(str(word_form))

            replays_in_groups.append('')

    save_list_to_file(replays_in_groups, 'out/Повторы в группах.txt')
Beispiel #11
0
def get_homonyms_bg():
    socket_group_list = list(read_src_socket_bs(
        'src_dict/БГ 16.02.21.txt'))

    socket_names = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if (
                        not word_form.invisible
                        and not word_form.root_index
                ):
                    socket_names.append(
                        word_form.name.replace('*', '').strip()
                    )

    socket_names = [x for x, y in Counter(socket_names).items() if y > 1]
    socket_names = sorted(list(set(socket_names)))

    homonyms = []

    for socket_group in socket_group_list:
        group_names = [
            x.name.replace('*', '').strip()
            for x in socket_group.socket_word_forms if not x.invisible
        ]

        for sub_group in socket_group.sub_groups:
            title_word_form = sub_group.title_word_form
            for word_form in sub_group.socket_word_forms:
                if (
                        not word_form.invisible
                        and not word_form.root_index
                ):
                    raw_name = word_form.name.replace('*', '').strip()
                    if (
                            group_names.count(raw_name) == 1
                            and raw_name in socket_names):
                        if str(word_form) == str(title_word_form):
                            homonyms.append(str(word_form))
                        else:
                            homonyms.append(' < '.join([
                                str(word_form),
                                str(title_word_form),
                            ]))

    sort_homonyms = sorted(homonyms,
                           key=lambda x: x.replace('*', '').strip().lower())
    save_list_to_file(sort_homonyms, 'out/Омонимы БГ.txt')

    loner_names = [x.split()[0] for x in sort_homonyms]
    loner_homonyms = [x for x in sort_homonyms
                      if loner_names.count(x.split()[0]) == 1]
    save_list_to_file(loner_homonyms, 'out/Единичные омонимы.txt')
Beispiel #12
0
def get_root_index_data_set():
    socket_group_word_form_list = read_src_socket_bs(
        'src_dict/БГ 16.02.21.txt')

    root_index_ds = {
        '2': [],
        '2!': [],
        '2*': [],
        '3': [],
        '3!': [],
        '3*': [],
        '3**': [],
        '4': [],
        '4!': [],
        '4*': [],
        '4**': [],
        '5': [],
        '5!': [],
        '5*': [],
        '5**': [],
        '6': [],
        '6!': [],
        '6*': [],
        '6**': [],
        '7': [],
        '7!': [],
        '7*': [],
        '7**': [],
    }

    for socket_group_word_form in socket_group_word_form_list:
        for socket_word_form in socket_group_word_form.socket_word_forms:
            root_index = socket_word_form.root_index
            if root_index and not socket_word_form.invisible:
                root_index_ds[root_index].append(str(socket_word_form))

    for k in root_index_ds:
        root_index_ds[k] = sorted(
            list(set(root_index_ds[k])),
            key=lambda x: x.replace('*', '').lower().strip())

    ds = []
    for k in root_index_ds:
        for word_form in root_index_ds[k]:
            ds.append({
                'root_index': k,
                'word_form': word_form,
            })

    df = pd.DataFrame(ds)
    res_df = (df.assign(idx=df.groupby("root_index").cumcount()).pivot_table(
        index="idx", columns="root_index", values="word_form",
        aggfunc="first"))
    res_df.to_csv('out/Многокорневые слова.csv')
Beispiel #13
0
def get_bg_note():
    socket_group_list = read_src_socket_bs('src_dict/БГ 17.02.21.txt')

    bg_notes = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms[1:]:
                if word_form.note:
                    print(word_form)
                    bg_notes.append(str(word_form))

    save_list_to_file(bg_notes, 'out/Пояснительные примечания.txt')
Beispiel #14
0
def get_bg_note():
    socket_group_list = read_src_socket_bs('src_dict/БГ 23.02.21.txt')

    bg_notes = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms[1:]:
                if word_form.note:
                    print(word_form)
                    bg_notes.append(str(word_form))

    save_list_to_file(
        sorted(bg_notes, key=lambda x: x.replace('*', '').strip().lower()),
        'out/Пояснительные примечания БГ, не-ЗС.txt')
Beispiel #15
0
def change_template_bg():
    socket_group_list = list(read_src_socket_bs('src_dict/БГ 15.05.21.txt'))

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if all([
                    word_form.idf == '.СеИ',
                    word_form.name.endswith('ий'),
                    word_form.name not in ('вий', 'змий', 'кий'),
                ]):
                    for count, identifier in enumerate(word_form.info):
                        if identifier == 'мнI2':
                            word_form.info[count] = 'мнI2**'

    save_socket_bs_dicts_to_txt(socket_group_list, 'out/БГ 17.05.21.txt')
Beispiel #16
0
def change_bg_abbreviation():
    abbreviation_bg = sorted(
        list(set(get_string_list_from_file('src_dict/Аббревиатура. БГ.txt'))))
    capital_letter_bg = sorted(
        list(set(get_string_list_from_file('src_dict/Большая буква. БГ.txt'))))

    socket_group_list = list(read_src_socket_bs('src_dict/БГ 15.03.21.txt'))

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if not word_form.invisible:
                    if (str(word_form) in abbreviation_bg
                            or str(word_form) in capital_letter_bg):
                        word_form.name = word_form.name.lower()

    save_socket_bs_dicts_to_txt(socket_group_list, 'out/БГ 16.03.21.txt')
Beispiel #17
0
def check_root_index():
    socket_group_word_form_list = read_src_socket_bs(
        'src_dict/БГ 11.02.21.txt')

    title_word_root_index_list = []

    for socket_group_form in socket_group_word_form_list:
        for socket_sub_group_form in socket_group_form.sub_groups:
            if len(socket_sub_group_form.socket_word_forms) >= 2:
                form_0, form_1 = socket_sub_group_form.socket_word_forms[:2]
                if form_0.root_index and not form_1.root_index:
                    print(form_0)
                    title_word_root_index_list.append(str(form_0))

    save_list_to_file(
        sorted(title_word_root_index_list, key=lambda x: x.lower()),
        'out/ЗС корневой индекс.txt'
    )
Beispiel #18
0
def get_adjusted_participles_bg():
    socket_group_word_form_list = read_src_socket_bs(
        'src_dict/БГ 28.01.21.txt')

    adjusted_participles_list = []

    for group in socket_group_word_form_list:
        for sub_group in group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if (word_form.name.startswith('*')
                        and not word_form.name.startswith('* ')):
                    adjusted_participles_list.append(str(word_form))
                    print(word_form)

    save_list_to_file(
        sorted(adjusted_participles_list,
               key=lambda x: x.replace('*', '').strip().lower()),
        'out/Адъектированные причастия БГ.txt')
Beispiel #19
0
def get_mismatched_notes():
    socket_group_word_form_list = list(read_src_socket_bs(
        'src_dict/БГ 11.02.21.txt'))
    word_forms_bases = read_src_bs('src_dict/БС 03.02.21.txt')

    mismatched_notes = []

    for group_word_form in word_forms_bases:
        title_form = group_word_form.title_word_form

        for socket_group_form in socket_group_word_form_list:
            for socket_sub_group_form in socket_group_form.sub_groups:
                for socket_form in socket_sub_group_form.socket_word_forms:
                    if (
                            title_form.name == socket_form.name
                            and title_form.idf == socket_form.idf
                            and ' '.join(title_form.info) == ' '.join(socket_form.info)
                            and title_form.note.replace('.* ', '') != socket_form.note.replace('* ', '')
                    ):
                        mismatched_notes.append(str(title_form))

    save_list_to_file(mismatched_notes, 'out/Несовпадающие примечания.txt')
Beispiel #20
0
def check_bg_islower():
    socket_group_list = read_src_socket_bs('out/БГ 16.03.21.txt')

    bg_islower_list = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                check_form = ' '.join(
                    filter(None, [
                        word_form.invisible,
                        word_form.name,
                        word_form.root_index,
                        word_form.note,
                        word_form.etml_note,
                        word_form.spec_note,
                    ]))
                check_form = check_form.replace('I', '')
                check_form = check_form.replace('V', '')
                if not check_form.islower():
                    print(check_form)
                    bg_islower_list.append(str(word_form))

    save_list_to_file(bg_islower_list, 'out/БГ ЕСТЬ большие буквы.txt')
Beispiel #21
0
def check_replays():
    multi_root_words = get_dicts_from_csv_file('out/Многокорневые слова.csv')

    socket_group_word_form_list = list(
        read_src_socket_bs('src_dict/БГ 10.04.21.txt'))

    root_index_ds = {
        '2': [],
        '2!': [],
        '2*': [],
        '3': [],
        '3!': [],
        '3*': [],
        '3**': [],
        '4': [],
        '4!': [],
        '4*': [],
        '4**': [],
        '5': [],
        '5!': [],
        '5*': [],
        '5**': [],
        '6': [],
        '6!': [],
        '6*': [],
        '6**': [],
        '7': [],
        '7!': [],
        '7*': [],
        '7**': [],
    }

    count_index = {
        '2': 2,
        '2!': 2,
        '2*': 1,
        '3': 3,
        '3!': 3,
        '3*': 2,
        '3**': 1,
        '4': 4,
        '4!': 4,
        '4*': 3,
        '4**': 2,
        '5': 5,
        '5!': 5,
        '5*': 4,
        '5**': 3,
        '6': 6,
        '6!': 6,
        '6*': 5,
        '6**': 4,
        '7': 7,
        '7!': 7,
        '7*': 6,
        '7**': 5,
    }

    incorrect_replays = []

    for multi_root_word in multi_root_words:
        for root_index_key in list(multi_root_word)[1:]:
            if multi_root_word[root_index_key]:
                root_index_ds[root_index_key].append(
                    multi_root_word[root_index_key])

    for root_index in root_index_ds:
        for multi_root_word in root_index_ds[root_index]:
            count_word = 0
            for socket_group_word_form in socket_group_word_form_list:
                for socket_word_form in socket_group_word_form.socket_word_forms:
                    if multi_root_word == str(socket_word_form):
                        count_word += 1
            if count_word != count_index[root_index]:
                print(multi_root_word)
                incorrect_replays.append(f'{multi_root_word} - {count_word}')

    save_list_to_file(incorrect_replays, 'out/Не корректные повторы.txt')
Beispiel #22
0
def ordinary_words_bg():
    socket_group_list = list(read_src_socket_bs(
        'src_dict/БГ 01.03.21.txt'))

    exclusion_list = []

    # Многокорневые слова
    multi_root_words = get_dicts_from_csv_file(
        'src_dict/Многокорневые слова.csv')
    multi_root_bg_forms = []

    for multi_root_word in multi_root_words:
        for root_index_key in list(multi_root_word):
            if multi_root_word[root_index_key]:
                multi_root_bg_forms.append(multi_root_word[root_index_key])

    exclusion_list += multi_root_bg_forms

    # Повторы в группах
    replays_in_groups = []

    with open('src_dict/Повторы в группах.txt', encoding='utf-8') as f_in:
        groups = (x.strip() for x in f_in.read().split('\n\n'))
        for group in groups:
            for line in group.split('\n')[1:]:
                if not line.startswith('!'):
                    replays_in_groups.append(line)

    exclusion_list += replays_in_groups

    # Омонимы БГ
    homonyms_bg = get_string_list_from_file('src_dict/Омонимы БГ.txt')
    homonyms_bg_str_form = []

    for homonym in homonyms_bg:
        socket_form = get_socket_word_form(homonym)
        string_form = ' '.join(filter(
            None, [
                socket_form.invisible,
                socket_form.name,
                socket_form.root_index,
                socket_form.idf,
                ' '.join(socket_form.info),
                socket_form.note,
                socket_form.etml_note,
            ]
        ))
        homonyms_bg_str_form.append(string_form)

    exclusion_list += homonyms_bg_str_form

    # Слова, омонимичные многокорневым
    homonymous_words = get_string_list_from_file(
        'src_dict/Слова, омонимичные многокорневым словам.txt')
    homonymous_words_str_form = []

    for word in homonymous_words:
        socket_form = get_socket_word_form(word)
        string_form = ' '.join(filter(
            None, [
                socket_form.invisible,
                socket_form.name,
                socket_form.root_index,
                socket_form.idf,
                ' '.join(socket_form.info),
                socket_form.note,
                socket_form.etml_note,
            ]
        ))
        homonymous_words_str_form.append(string_form)

    exclusion_list += homonymous_words_str_form

    # Обычные слова БГ
    ordinary_words_bg_list = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if not word_form.invisible:
                    if str(word_form) not in exclusion_list:
                        ordinary_words_bg_list.append(word_form)

    ordinary_words_bg_list = [str(x) for x in sorted(ordinary_words_bg_list)]

    save_list_to_file(ordinary_words_bg_list, 'out/Обычные слова БГ.txt')
Beispiel #23
0
def check_replays():
    """
    14. Проверить каждое слово из док-та Excel Многокорневые слова.xlsx

    на количество повторов в док-те БГ 12.02.21.txt ,
    используя следующую таблицу:

    корневой индекс 2* / 3** - 1 повтор в БГ;
    корневой индекс 2 / 2! / 3* / 4** - 2 повтора в БГ;
    корневой индекс 3 / 3! / 4* / 5** - 3 повтора в БГ;
    корневой индекс 4 / 4! / 5* / 6** - 4 повтора в БГ;
    корневой индекс 5 / 5! / 6* / 7** - 5 повторов в БГ;
    корневой индекс 6 / 6! / 7* - 6 повторов в БГ;
    корневой индекс 7 / 7! - 7 повторов в БГ;

    и на абсолютную идентичность строки со словом в док-те
    Многокорневые слова.xlsx
    со ВСЕМИ строками с этим словом в док-те БГ 12.02.21.txt .
    Т.е. напр. строка из док-та Многокорневые слова.xlsx
    автобус 3* .СеИ неод мI1 мнII1 * auto(mobile) (omni)bus
    должна ИМЕННО В ТАКОМ виде 2 раза присутствовать в док-те БГ 12.02.21.txt .
    """

    multi_root_words = get_dicts_from_csv_file('out/Многокорневые слова.csv')

    socket_group_word_form_list = list(
        read_src_socket_bs('src_dict/БГ 12.02.21.txt'))

    root_index_ds = {
        '2': [],
        '2!': [],
        '2*': [],
        '3': [],
        '3!': [],
        '3*': [],
        '3**': [],
        '4': [],
        '4!': [],
        '4*': [],
        '4**': [],
        '5': [],
        '5!': [],
        '5*': [],
        '5**': [],
        '6': [],
        '6!': [],
        '6*': [],
        '6**': [],
        '7': [],
        '7!': [],
        '7*': [],
        '7**': [],
    }

    count_index = {
        '2': 2,
        '2!': 2,
        '2*': 1,
        '3': 3,
        '3!': 3,
        '3*': 2,
        '3**': 1,
        '4': 4,
        '4!': 4,
        '4*': 3,
        '4**': 2,
        '5': 5,
        '5!': 5,
        '5*': 4,
        '5**': 3,
        '6': 6,
        '6!': 6,
        '6*': 5,
        '6**': 4,
        '7': 7,
        '7!': 7,
        '7*': 6,
        '7**': 5,
    }

    incorrect_replays = []

    for multi_root_word in multi_root_words:
        for root_index_key in list(multi_root_word)[1:]:
            if multi_root_word[root_index_key]:
                root_index_ds[root_index_key].append(
                    multi_root_word[root_index_key])

    for root_index in root_index_ds:
        for multi_root_word in root_index_ds[root_index]:
            count_word = 0
            for socket_group_word_form in socket_group_word_form_list:
                for socket_word_form in socket_group_word_form.socket_word_forms:
                    if multi_root_word == str(socket_word_form):
                        count_word += 1
            if count_word != count_index[root_index]:
                print(multi_root_word)
                incorrect_replays.append(f'{multi_root_word} - {count_word}')

    save_list_to_file(incorrect_replays, 'out/Не корректные повторы.txt')
Beispiel #24
0
def get_root_index_data_set():
    """
    13.1. найти в док-те БГ 12.02.21.txt все многокорневые слова,
    т.е. слова (кроме невидимок), у которых есть корневой индекс;

    13.2. создать док-т Excel Многокорневые слова.xlsx и заполнить его строками
    с найденными многокорневыми словами с соблюдением следующих правил:
      а. строки приводятся ПОЛНОСТЬЮ;
      б. строки вставляются в тот или иной столбец в зависимости
        от корневого индекса;
      в. уже вставленная строка не должна вставляться второй (и более!) раз!
        Другими словами, в док-те Многокорневые слова.xlsx не должно быть повторов
        абсолютно одинаковых строк

    13.3. по завершении заполнения док-та Многокорневые слова.xlsx
    вставленные строки в столбцах расположить в соответствии
    с алфавитным порядком слов,
    а сами столбцы - в следующем порядке:
    2 2! 2*
    3 3! 3* 3**
    4 4! 4* 4**
    5 5! 5* 5**
    6 6! 6* 6**
    7 7! 7* 7**
    """
    socket_group_word_form_list = read_src_socket_bs(
        'src_dict/БГ 12.02.21.txt')

    root_index_ds = {
        '2': [],
        '2!': [],
        '2*': [],
        '3': [],
        '3!': [],
        '3*': [],
        '3**': [],
        '4': [],
        '4!': [],
        '4*': [],
        '4**': [],
        '5': [],
        '5!': [],
        '5*': [],
        '5**': [],
        '6': [],
        '6!': [],
        '6*': [],
        '6**': [],
        '7': [],
        '7!': [],
        '7*': [],
        '7**': [],
    }

    for socket_group_word_form in socket_group_word_form_list:
        for socket_word_form in socket_group_word_form.socket_word_forms:
            root_index = socket_word_form.root_index
            if root_index and not socket_word_form.invisible:
                root_index_ds[root_index].append(str(socket_word_form))

    for k in root_index_ds:
        root_index_ds[k] = sorted(
            list(set(root_index_ds[k])),
            key=lambda x: x.replace('*', '').lower().strip())

    ds = []
    for k in root_index_ds:
        for word_form in root_index_ds[k]:
            ds.append({
                'root_index': k,
                'word_form': word_form,
            })

    df = pd.DataFrame(ds)
    res_df = (df.assign(idx=df.groupby("root_index").cumcount()).pivot_table(
        index="idx", columns="root_index", values="word_form",
        aggfunc="first"))
    res_df.to_csv('out/Многокорневые слова.csv')
Beispiel #25
0
def get_homonyms_bg():
    socket_group_list = list(read_src_socket_bs('src_dict/БГ 10.04.21.txt'))

    socket_names = []

    for socket_group in socket_group_list:
        for sub_group in socket_group.sub_groups:
            for word_form in sub_group.socket_word_forms:
                if (not word_form.invisible and not word_form.root_index):
                    socket_names.append(
                        word_form.name.replace('*', '').strip())

    socket_names = [x for x, y in Counter(socket_names).items() if y > 1]
    socket_names = sorted(list(set(socket_names)))

    all_homonyms = []

    for socket_group in socket_group_list:
        group_names = [
            x.name.replace('*', '').strip()
            for x in socket_group.socket_word_forms if not x.invisible
        ]

        for sub_group in socket_group.sub_groups:
            title_word_form = sub_group.title_word_form
            for word_form in sub_group.socket_word_forms:
                if (not word_form.invisible and not word_form.root_index):
                    raw_name = word_form.name.replace('*', '').strip()
                    if (group_names.count(raw_name) == 1
                            and raw_name in socket_names):
                        if str(word_form) == str(title_word_form):
                            all_homonyms.append(str(word_form))
                        else:
                            all_homonyms.append(' < '.join([
                                str(word_form),
                                str(title_word_form),
                            ]))

    replays_homonyms = [get_socket_word_form(x).name for x in all_homonyms]
    replays_homonyms = [
        x for x in replays_homonyms if replays_homonyms.count(x) > 1
    ]

    homonyms = []
    homonymous_repetitions = []

    for homonym in all_homonyms:
        if get_socket_word_form(homonym).name in replays_homonyms:
            homonyms.append(homonym)
        else:
            homonymous_repetitions.append(homonym)

    homonyms = sorted(homonyms,
                      key=lambda x: x.replace('*', '').strip().lower())
    homonymous_repetitions = sorted(
        homonymous_repetitions,
        key=lambda x: x.replace('*', '').strip().lower())

    save_list_to_file(homonyms, 'out/Омонимы БГ.txt')
    save_list_to_file(homonymous_repetitions,
                      'out/Слова, омонимичные повторам в группе.txt')