示例#1
0
def apply_noun_specific_1_2(func, i):  # export
    p = i.parts  # local

    if _.contains(i.rest_index, ['%(1%)', '①']):
        if i.stem.base_type == '1-hard':
            if i.gender == 'm': p.endings['nom-pl'] = 'а'  # end
            if i.gender == 'n': p.endings['nom-pl'] = 'ы'  # end
        # end
        if i.stem.base_type == '2-soft':
            if i.gender == 'm': p.endings['nom-pl'] = 'я'  # end
            if i.gender == 'n': p.endings['nom-pl'] = 'и'  # end
        # end
        if _.equals(i.stem.type,
                    ['3-velar', '4-sibilant']):  # Replace "ы" to "и"
            if i.gender == 'n': p.endings['nom-pl'] = 'и'  # end
        # end
    # end

    if _.contains(i.rest_index, ['%(2%)', '②']):
        if i.stem.base_type == '1-hard':
            if i.gender == 'm': p.endings['gen-pl'] = ['', '']  # end
            if i.gender == 'n': p.endings['gen-pl'] = ['ов', 'ов']  # end
            if i.gender == 'f': p.endings['gen-pl'] = {'ей', 'ей'}  # end
        # end
        if i.stem.base_type == '2-soft':
            if i.gender == 'm': p.endings['gen-pl'] = ['ь', 'ь']  # end
            if i.gender == 'n': p.endings['gen-pl'] = ['ев', 'ёв']  # end
            if i.gender == 'f': p.endings['gen-pl'] = {'ей', 'ей'}  # end
        # end
        if _.equals(
                i.stem.type,
            ['4-sibilant', '5-letter-ц']):  # Replace unstressed "о" to "е"
            if i.gender == 'n': p.endings['gen-pl'][unstressed] = 'ев'  # end
        # end

#        # Possibly we don't need this:
#            # Replace "ов", "ев", "ёв" and null to "ей"
#            if i.stem.type = {'4-sibilant'}}
#                if i.gender == 'n': p.endings['gen-pl'] = ['ей', 'ей']
#                if i.gender == 'm': p.endings['gen-pl'][stressed] = 'ей'
#            # end
#            # Replace "ь" to "й"
#            if i.stem.type = ['6-vowel', '7-letter-и']}
#                if i.gender == 'm': p.endings['gen-pl'][stressed] = ['й', 'й']
#            # end
#            # Replace "ей" to "ев/ёв", and "ь,ей" to "й"
#            if i.stem.type = ['6-vowel', '7-letter-и']}
#                if i.gender == 'f': p.endings['gen-pl'][unstressed] = ['ев', 'ёв']
#                if i.gender == 'm': p.endings['gen-pl'][stressed] = ['й', 'й']
#            # end
#        #
# end

    _.ends(module, func)
示例#2
0
def extract_stress_type(func, i):  # export
    #    OLD: Старая версия кода:
    #    # local stress_regexp = "([abcdef][′']?[′']?)"
    #    # local stress_regexp2 = '(' + stress_regexp + '.*//.*' + stress_regexp + ')'
    #    stress_regexp = '(' + stress_regexp + '(% ?.*))'
    #    i.stress_type = _.extract(i.rest_index, stress_regexp2)
    #    if not i.stress_type:
    #        i.stress_type = _.extract(i.rest_index, stress_regexp)
    #    # end
    # local stress_type, allowed_stress_types

    # INFO: Извлечение ударения из оставшейся части индекса:
    i.stress_type = _.extract(i.rest_index,
                              "([abcdef][′']?[′']?[/]?[abc]?[′']?[′']?)")

    # INFO: Замена особых апострофов в ударении на обычные:
    if i.stress_type:
        i.stress_type = _.replaced(i.stress_type, '′', "'")
    # end

    # INFO: Список допустимых схем ударений:
    allowed_stress_types = {  # todo: special variables for that?
        'a', "a'", 'b', "b'", 'c', 'd', "d'", 'e', 'f', "f'", "f''",
        'a/a', 'a/b', 'a/c', "a/a'", "a/b'", "a/c'", "a/c''",
        'b/a', 'b/b', 'b/c', "b/a'", "b/b'", "b/c'", "b/c''",
    }

    # INFO: Если ударение есть и оно не из допустимого списка -- это ошибка
    if i.stress_type and not _.equals(i.stress_type, allowed_stress_types):
        e.add_error(i, 'Ошибка: Неправильная схема ударения: ' + i.stress_type)
    # end

    _.ends(module, func)
示例#3
0
def process(func, i):  # export
    _.log_info('Извлечение информации об ударении (stress_type)')
    stress.extract_stress_type(i)  # todo: move to `parse`
    _.log_value(i.stress_type, 'i.stress_type')

    if e.has_error(i):
        return _.returns(module, func, i)
    # end

    if not i.stress_type:  # если ударение не указано
        if _.contains(i.rest_index, '0'):  # если несклоняемая схема
            i.stress_type = ''
        else:
            # INFO: Если при этом есть какой-то индекс, это явно ОШИБКА
            if _.has_value(i.rest_index):
                e.add_error(i, 'Нераспознанная часть индекса: ' + i.rest_index)
                return _.returns(module, func, i)
            # end

            # INFO: Если же индекса вообще нет, то и формы просто не известны:
            i.has_index = False
            return _.returns(module, func, i)
        # end
    # end

    _.log_info('Вычисление схемы ударения')
    stress.get_stress_schema(i)

    _.log_info('Определение типа основы (stem_type)')
    stem_type.get_stem_type(i)
    _.log_value(i.stem.type, 'i.stem.type')
    _.log_value(i.stem.base_type, 'i.stem.base_type')

    # INFO: Итак, ударение мы получили.

    # INFO: Добавление ударения для `stem.stressed` (если его не было)
    # INFO: Например, в слове только один слог, или ударение было на окончание
    if not _.contains(i.stem.stressed, '[́ ё]'):  # and not i.absent_stress ??
        if _.equals(i.stress_type, ["f", "f'"]):
            i.stem.stressed = _.replaced(i.stem.stressed,
                                         '^({consonant}*)({vowel})', '%1%2́ ')
        elif _.contains(i.rest_index, '%*'):
            pass  # *** поставим ударение позже, после чередования
        else:
            i.stem.stressed = _.replaced(i.stem.stressed,
                                         '({vowel})({consonant}*)$', '%1́ %2')
        # end
    # end

    _.log_value(i.stem.stressed, 'i.stem.stressed')

    _.log_info('Инициализируем `i.result`')
    init_result.init_result(i)

    return _.returns(module, func, i)
示例#4
0
def get_stem_base_type(func, i):
    # INFO: Выбор подходящего из двух типов

    if _.equals(i.stem.type,
                ['1-hard', '3-velar', '4-sibilant', '5-letter-ц']):
        return _.returns(module, func, '1-hard')
    # end

    if _.equals(i.stem.type, ['2-soft', '6-vowel', '7-letter-и']):
        return _.returns(module, func, '2-soft')
    # end

    if _.equals(i.stem.type, {'8-third'}):
        if i.gender == 'n':
            return _.returns(module, func, '1-hard')
        # end
        if i.gender == 'm' or i.gender == 'f':
            return _.returns(module, func, '2-soft')
        # end
    # end

    return _.returns(module, func, '?')
示例#5
0
def generate_pronoun_stress_schemas(func):  # INFO: Вычисление схемы ударения
    stress_types = ['a', 'b']  # local
    res = dict()  # dict

    for j, stress_type in enumerate(stress_types):
        stress_schema = dict()  # dict
        stress_schema['stem'] = dict()  # dict
        stress_schema['ending'] = dict()  # dict

        # общий подход следующий:
        # если схема среди перечисленных, значит, элемент под ударением (stressed), иначе — нет (unstressed)
        stress_schema['stem']['sg'] = _.equals(stress_type, "a")
        stress_schema['stem']['pl'] = _.equals(stress_type, "a")
        stress_schema['ending']['sg'] = _.equals(stress_type, "b")
        stress_schema['ending']['pl'] = _.equals(stress_type, "b")

        types = ['stem', 'ending']
        sg_cases = ['nom-sg', 'gen-sg', 'dat-sg', 'acc-sg', 'ins-sg', 'prp-sg']  # list
        pl_cases = ['nom-pl', 'gen-pl', 'dat-pl', 'acc-pl', 'ins-pl', 'prp-pl']  # list
        for j, type in enumerate(types):
            sg_value = stress_schema[type]['sg']
            for j, case in enumerate(sg_cases):
                stress_schema[type][case] = sg_value
            # end
            del stress_schema[type]['sg']

            pl_value = stress_schema[type]['pl']
            for j, case in enumerate(pl_cases):
                stress_schema[type][case] = pl_value
            # end
            del stress_schema[type]['pl']
        # end
        res[stress_type] = stress_schema
    # end

    dump_data('pronoun', res)

    return _.returns(module, func, res)
示例#6
0
def plus_forms(func, sub_forms):  # export  # todo: rename to `out_args`
    # local keys, out_args, delim

    keys = [
        'nom-sg',
        'gen-sg',
        'dat-sg',
        'acc-sg',
        'ins-sg',
        'prp-sg',
        'nom-pl',
        'gen-pl',
        'dat-pl',
        'acc-pl',
        'ins-pl',
        'prp-pl',
        'ins-sg2',
        'зализняк1',
        'зализняк',
        'error',
    ]  # list
    out_args = sub_forms[0]  # todo: rename to `out_args`
    for j, forms2 in enumerate(sub_forms):  # todo: rename to `out_args`
        if j != 0:
            for j, key in enumerate(keys):
                if not out_args[key] and forms2[
                        key]:  # INFO: Если out_args[key] == None
                    out_args[key] = forms2[key]
                elif out_args[key] != forms2[key] and forms2[key]:
                    delim = '-'
                    if _.equals(key, ['зализняк1', 'зализняк']):
                        delim = ' + '
                    # end
                    out_args[key] = out_args[key] + delim + forms2[key]
                # end
                if not out_args[key]:  # INFO: Если out_args[key] == None
                    out_args[key] = ''
                # end
            # end
        # end
    # end

    return _.returns(module, func, out_args)
示例#7
0
def add_comparative(func, i):  # export
    # todo: move to `modify` (и сделать через основы и окончания)
    r = i.result  # local

    if _.contains(i.rest_index, '~'):
        r['comparative'] = '-'
        return _.ends(module, func)
    # end

    if i.stem.type == '3-velar':
        new_stem = i.stem.unstressed
        if _.endswith(new_stem, 'к'):
            new_stem = _.replaced(new_stem, 'к$', 'ч')
        elif _.endswith(new_stem, 'г'):
            new_stem = _.replaced(new_stem, 'г$', 'ж')
        elif _.endswith(new_stem, 'х'):
            new_stem = _.replaced(new_stem, 'х$', 'ш')
        else:
            pass  # todo: some error here
        # end

        # ударение на предпоследний слог:
        new_stem = _.replaced(new_stem, '({vowel})({consonant}*)$', '%1́ %2')

        r['comparative'] = new_stem + 'е'
    else:
        if _.contains(i.rest_index, ['%(2%)', '②']):  # todo: special variable for this
            r['comparative'] = i.parts.stems['nom-pl'] + 'ее'
            r['comparative2'] = i.parts.stems['nom-pl'] + 'ей'
        else:
            if _.equals(i.stress_type, ['a', 'a/a']):
                r['comparative'] = i.stem.stressed + 'ее'
                r['comparative2'] = i.stem.stressed + 'ей'
            else:
                r['comparative'] = i.stem.unstressed + 'е́е'
                r['comparative2'] = i.stem.unstressed + 'е́й'
            # end
        # end
    # end

    _.ends(module, func)
示例#8
0
def transform(func, i):  # export
    # local stem_stress_schema
    p = i.parts  # local

    # apply special cases (1) or (2) in index
    if i.adj:
        adj_circles.apply_adj_specific_1_2(i)
    # end

    #    *** для случая с расстановкой ударения  (см. ниже)
    #    # local orig_stem = i.stem.unstressed
    #    if _.contains(i.rest_index, ['%(2%)', '②']):
    #        orig_stem = _.replaced(p.stems['gen-pl'], '́ ', '')  -- удаляем ударение для случая "сапожок *d(2)"
    #        mw.log('> Another `orig_stem`: ' + str(orig_stem))
    #    # end

    # reducable
    i.rest_index = degree.apply_specific_degree(i)
    reducable.apply_specific_reducable(i, i.gender, i.rest_index, False)
    if not _.equals(i.stress_type, ["f", "f'"]) and _.contains(
            i.rest_index, '%*'):
        _.log_info(
            'Обработка случая на препоследний слог основы при чередовании')
        orig_stem = i.stem.unstressed
        if i.forced_stem:
            orig_stem = i.forced_stem
        # end
        for key, stem in p.stems.items():
            # mw.log(' - ' + key + ' -> ' + stem)
            # mw.log('Ударение на основу?')
            # mw.log(i.stress_schema['stem'][key])
            stem_stress_schema = i.stress_schema['stem']
            if not _.contains(stem, '[́ ё]') and _.has_key(
                    stem_stress_schema, key) and stem_stress_schema[key]:
                # *** случай с расстановкой ударения  (см. выше)
                # "Дополнительные правила об ударении", стр. 34
                old_value = p.stems[key]
                # mw.log('> ' + key + ' (old): ' + str(old_value))
                if p.stems[
                        key] != orig_stem:  # попытка обработать наличие беглой гласной (не знаю, сработает ли всегда)
                    p.stems[key] = _.replaced(
                        stem,
                        '({vowel})({consonant}*)({vowel})({consonant}*)$',
                        '%1́ %2%3%4')
                    if not _.contains(
                            p.stems[key],
                            '[́ ё]'):  # если предпоследнего слога попросту нет
                        # сделаем хоть последний ударным
                        p.stems[key] = _.replaced(stem,
                                                  '({vowel})({consonant}*)$',
                                                  '%1́ %2')
                    # end
                else:
                    p.stems[key] = _.replaced(stem, '({vowel})({consonant}*)$',
                                              '%1́ %2')
                # end
                # mw.log('> ' + key + ' (new): ' + str(p.stems[key]))
                mw.log('  - ' + key + ': "' + str(old_value) + '" -> "' +
                       str(p.stems[key]) + '"')
            # end
        # end
    # end

    if i.calc_pl:
        # Специфика по "ё"
        if _.contains(i.rest_index, 'ё') and not _.contains(
                p.endings['gen-pl'], '{vowel+ё}') and not _.contains(
                    p.stems['gen-pl'], 'ё'):
            p.stems['gen-pl'] = _.replaced(p.stems['gen-pl'], 'е́?([^е]*)$',
                                           'ё%1')
            i.rest_index = i.rest_index + 'ё'  # ???
        # end
    # end

    _.ends(module, func)
示例#9
0
def generate_adj_stress_schemas(func):  # INFO: Вычисление схемы ударения
    stress_types = [  # todo: special variables for that?
        'a',
        "a'",
        'b',
        "b'",
        'c',
        'a/a',
        'a/b',
        'a/c',
        "a/a'",
        "a/b'",
        "a/c'",
        "a/c''",
        'b/a',
        'b/b',
        'b/c',
        "b/a'",
        "b/b'",
        "b/c'",
        "b/c''",
    ]
    res = dict()  # dict

    for j, stress_type in enumerate(stress_types):
        stress_schema = dict()  # dict
        stress_schema['stem'] = dict()  # dict
        stress_schema['ending'] = dict()  # dict

        # local cases
        cases = [
            'nom-sg',
            'gen-sg',
            'dat-sg',
            'acc-sg',
            'ins-sg',
            'prp-sg',
            'nom-pl',
            'gen-pl',
            'dat-pl',
            'acc-pl',
            'ins-pl',
            'prp-pl',
        ]  # list

        # пустышки в падежи, чтобы они шли раньше кратких форм в результате
        types = ['stem', 'ending']  # local
        for j, type in enumerate(types):
            for j, case in enumerate(cases):
                stress_schema[type][case] = '...'
            # end
        # end

        # общий подход следующий:
        # если схема среди перечисленных, значит, элемент под ударением (stressed), иначе — нет (unstressed)
        stress_schema['stem']['full'] = _.startswith(stress_type, ["a", "a/"])
        stress_schema['stem']['srt-sg-m'] = True
        stress_schema['stem']['srt-sg-f'] = _.endswith(
            stress_type, ["/a", "/a'"]) or _.equals(stress_type, ['a', "a'"])
        stress_schema['stem']['srt-sg-n'] = _.endswith(
            stress_type, ["/a", "/c", "/a'", "/c'", "/c''"]) or _.equals(
                stress_type, ['a', "a'"])
        stress_schema['stem']['srt-pl'] = _.endswith(
            stress_type, ["/a", "/c", "/a'", "/b'", "/c'", "/c''"
                          ]) or _.equals(stress_type, ['a', "a'", "b'"])
        stress_schema['ending']['full'] = _.startswith(stress_type,
                                                       ["b", "b/"])
        stress_schema['ending']['srt-sg-m'] = False
        stress_schema['ending']['srt-sg-f'] = _.endswith(
            stress_type, ["/b", "/c", "/a'", "/b'", "/c'", "/c''"
                          ]) or _.equals(stress_type, ['b', "a'", "b'"])
        stress_schema['ending']['srt-sg-n'] = _.endswith(
            stress_type, ["/b", "/b'", "/c''"]) or _.equals(
                stress_type, ['b', "b'"])
        stress_schema['ending']['srt-pl'] = _.endswith(
            stress_type, ["/b", "/b'", "/c'", "/c''"]) or _.equals(
                stress_type, ['b', "b'"])

        types = ['stem', 'ending']  # local
        for j, type in enumerate(types):
            value = stress_schema[type]['full']  # local
            for j, case in enumerate(cases):
                stress_schema[type][case] = value
            # end
            del stress_schema[type]['full']
        # end
        res[stress_type] = stress_schema
    # end

    dump_data('adj', res)

    return _.returns(module, func, res)
示例#10
0
def generate_noun_stress_schemas(func):  # INFO: Вычисление схемы ударения
    # todo: special variable for this?
    stress_types = ['a', 'b', 'c', 'd', 'e', 'f', "b'", "d'", "f'",
                    "f''"]  # local
    res = dict()  # dict

    for j, stress_type in enumerate(stress_types):
        stress_schema = dict()  # dict
        stress_schema['stem'] = dict()  # dict
        stress_schema['ending'] = dict()  # dict

        # общий подход следующий:
        # если схема среди перечисленных, значит, элемент под ударением (stressed), иначе — нет (unstressed)
        stress_schema['stem']['sg'] = _.equals(stress_type, ["a", "c", "e"])
        stress_schema['stem']['nom-sg'] = '...'
        stress_schema['stem']['gen-sg'] = '...'
        stress_schema['stem']['dat-sg'] = '...'
        stress_schema['stem']['acc-sg'] = _.equals(stress_type,
                                                   ["a", "c", "e", "d'", "f'"])
        stress_schema['stem']['ins-sg'] = _.equals(
            stress_type, ["a", "c", "e", "b'", "f''"])
        stress_schema['stem']['prp-sg'] = '...'
        stress_schema['stem']['pl'] = _.equals(stress_type, ["a", "d", "d'"])
        stress_schema['stem']['nom-pl'] = _.equals(
            stress_type, ["a", "d", "d'", "e", "f", "f'", "f''"])
        stress_schema['stem']['gen-pl'] = '...'
        stress_schema['stem']['dat-pl'] = '...'
        stress_schema['stem']['ins-pl'] = '...'
        stress_schema['stem']['prp-pl'] = '...'
        stress_schema['ending']['sg'] = _.equals(
            stress_type, ["b", "b'", "d", "d'", "f", "f'", "f''"])
        stress_schema['ending']['nom-sg'] = '...'
        stress_schema['ending']['gen-sg'] = '...'
        stress_schema['ending']['dat-sg'] = '...'
        stress_schema['ending']['acc-sg'] = _.equals(
            stress_type, ["b", "b'", "d", "f", "f''"])
        stress_schema['ending']['ins-sg'] = _.equals(
            stress_type, ["b", "d", "d'", "f", "f'"])
        stress_schema['ending']['prp-sg'] = '...'
        stress_schema['ending']['pl'] = _.equals(
            stress_type, ["b", "b'", "c", "e", "f", "f'", "f''"])
        stress_schema['ending']['nom-pl'] = _.equals(stress_type,
                                                     ["b", "b'", "c"])
        stress_schema['ending']['gen-pl'] = '...'
        stress_schema['ending']['dat-pl'] = '...'
        stress_schema['ending']['ins-pl'] = '...'
        stress_schema['ending']['prp-pl'] = '...'

        types = ['stem', 'ending']  # local
        for j, type in enumerate(types):
            sg_value = stress_schema[type]['sg']  # local
            stress_schema[type]['nom-sg'] = sg_value
            stress_schema[type]['gen-sg'] = sg_value
            stress_schema[type]['dat-sg'] = sg_value
            stress_schema[type]['prp-sg'] = sg_value
            del stress_schema[type]['sg']

            pl_value = stress_schema[type]['pl']  # local
            stress_schema[type]['gen-pl'] = pl_value
            stress_schema[type]['dat-pl'] = pl_value
            stress_schema[type]['ins-pl'] = pl_value
            stress_schema[type]['prp-pl'] = pl_value
            del stress_schema[type]['pl']
        # end

        res[stress_type] = stress_schema
    # end

    dump_data('noun', res)

    return _.returns(module, func, res)
示例#11
0
def apply_specific_reducable(func, i, gender, rest_index, only_sg):  # export
    # local reduced, reduced_letter, f8_third, prev
    # local case_2_a, case_2_b, case_2_c, case_3_a, case_3_b
    # local skip_b_1, skip_b_2, skip_b_3, force_b
    # local case

    p = i.parts  # local

    if _.contains(rest_index, '%*'):

        reduced = '?'
        if i.adj:
            if gender == 'm':
                if _.contains(rest_index, ['%(1%)', '①']):
                    if gender == 'm' and i.adj and _.endswith(
                            i.word.unstressed, 'ний'
                    ) and p.endings[
                            'srt-sg'] == 'ь':  # fixme: temporary duplicated with the same code at the ending of function...
                        p.endings['srt-sg'] = ''  # вместо `ь` для `2*a`
                    # end
                    return _.ends(module, func)
                # end
                if _.contains(rest_index, ['%(2%)', '②']):
                    return _.ends(module, func)
                # end
                reduced = 'B'
            else:
                return _.ends(module, func)
            # end
        elif gender == 'm' or i.pronoun:
            reduced = 'A'
        elif gender == 'n':
            reduced = 'B'
        elif gender == 'f':
            if i.stem.type == '8-third':
                reduced = 'A'
            else:
                reduced = 'B'
            # end
        # end

        _.log_info('Случай чередования: ' + str(reduced))

        if reduced == 'A':
            reduced_letter = _.extract(i.word.unstressed,
                                       '({vowel+ё}){consonant}+$')
            f8_third = gender == 'f' and i.stem.type == '8-third'

            _.log_value(reduced_letter, 'reduced_letter')

            if reduced_letter == 'о':
                _.replace(p.stems, 'all-sg', '(.)о́ ?([^о]+)$', '%1%2')

                #                # local stem_gen_pl
                #                # У этих имён последняя гласная основы исходной формы заменяется на нуль, о или й во всех формах, не совпадающих с исходной (кроме Т. ед. на -ью).
                #                # if p.endings['gen-pl'] == '':  -- ботинок, глазок
                #                if _.contains(rest_index, ['%(2%)', '②']):
                #                    stem_gen_pl = p.stems['gen-pl']
                #                # end

                if not only_sg:
                    _.replace(p.stems, 'all-pl', '(.)о́ ?([^о]+)$', '%1%2')
                # end

#                if stem_gen_pl:  # ботинок, глазок
#                    p.stems['gen-pl'] = stem_gen_pl
#                # end

                if not f8_third:
                    _.replace(p.stems, 'ins-sg', '(.)о́ ?([^о]+)$', '%1%2')
                # end

            elif reduced_letter == 'и':  # бывает только в подтипе мс 6*
                _.replace(p.stems, 'all-sg', '(.)и́ ?([^и]+)$', '%1ь%2')
                if not only_sg:
                    _.replace(p.stems, 'all-pl', '(.)и́ ?([^и]+)$', '%1ь%2')
                # end

            elif _.In(reduced_letter, ['е', 'ё']):
                prev = _.extract(i.word.unstressed, '(.)[её][^её]+$')

                case_2_a = i.stem.type == '6-vowel'  # 2) а).
                case_2_b = i.stem.type == '3-velar' and _.contains(
                    prev, '[^аеёиоуыэюяшжчщц]')  # 2) б).
                case_2_c = not _.equals(
                    i.stem.type,
                    ['6-vowel', '3-velar']) and prev == 'л'  # 2) в).

                if _.contains(prev, '{vowel+ё}'):  # 1).
                    _.log_info('Подслучай A.1).')
                    _.replace(p.stems, 'all-sg', '[её]́ ?([^её]+)$', 'й%1')
                    if not f8_third:
                        _.replace(p.stems, 'ins-sg', '[её]́ ?([^её]+)$', 'й%1')
                    # end
                    if not only_sg:
                        _.replace(p.stems, 'all-pl', '[её]́ ?([^её]+)$', 'й%1')
                    # end

                elif case_2_a or case_2_b or case_2_c:  # 2).

                    _.log_info('Подслучай A.2).')
                    _.replace(p.stems, 'all-sg', '[её]́ ?([^её]*)$', 'ь%1')
                    if not f8_third:
                        _.replace(p.stems, 'ins-sg', '[её]́ ?([^её]*)$', 'ь%1')
                    # end
                    if not only_sg:
                        _.replace(p.stems, 'all-pl', '[её]́ ?([^её]*)$', 'ь%1')
                    # end

                else:  # 3).
                    _.log_info('Подслучай A.3).')
                    _.replace(p.stems, 'all-sg', '[её]́ ?([^её]*)$', '%1')
                    if not f8_third:
                        _.replace(p.stems, 'ins-sg', '[её]́ ?([^её]*)$', '%1')
                    # end
                    if not only_sg:
                        _.replace(p.stems, 'all-pl', '[её]́ ?([^её]*)$', '%1')
                    # end
                # end
            # end
        # end  # reduced A

        if only_sg:
            return _.ends(
                module, func
            )  # ниже всё равно обрабатывается только множественное число уже
        # end

        # we should ignore asterix for 2*b and 2*f (so to process it just like 2b or 2f)
        skip_b_1 = i.stem.type == '2-soft' and _.In(i.stress_type, ['b', 'f'])

        # and also the same for (2)-specific and 3,5,6 stem-types
        skip_b_2 = _.contains(rest_index, ['%(2%)', '②']) and (
            _.In(i.stem.type, {'2-soft'})  # '2-soft' из сходня 2*a(2)

            # TODO: Разобраться, почему это нужно было на самом деле?
            #            _.In(i.stem.type, ['3-velar', '5-letter-ц', '6-vowel'])  # так было раньше, без прочих skip
        )

        # TODO: Разобраться, почему это нужно на самом деле?
        skip_b_3 = _.contains(rest_index,
                              ['%(2%)', '②']) and gender == 'n'  # temp fix

        stem = i.stem.unstressed  # local

        force_b = False
        if _.contains(rest_index, ['%(2%)', '②']):
            gender = 'n'  # fixme: ????
            i.forced_stem = p.stems['gen-pl']
            stem = p.stems['gen-pl']
            _.log_info('New force stem (gen-pl): ' + str(stem))
            force_b = True
        # end

        # TODO: б) в словах прочих схем ударения — на последний слог основы, если основа не содержит беглой гласной, и на предпоследний слог основы, если основа содержит беглую гласную, на¬пример: величина, тюрьма, полотно (схема d) — И.мн. величины, тюрьмы, полотна, Р.мн. ве¬личин, тюрем, полотен.
        # это для глАзок

        if (reduced == 'B'
                or force_b) and not skip_b_1 and not skip_b_2 and not skip_b_3:
            if i.adj:
                case = 'srt-sg'
            else:
                case = 'gen-pl'
            # end

            _.log_info('Зашли в случай чередования B')
            if i.stem.type == '6-vowel':  # 1).
                _.log_info('Подслучай B.1).')
                if _.In(i.stress_type, {
                        'b', 'c', 'e', 'f', "f'", "b'"
                }):  # gen-pl ending stressed  -- TODO: special vars for that
                    _.replace(p.stems, case, 'ь$', 'е́')
                else:
                    _.replace(p.stems, case, 'ь$', 'и')
                # end
            elif _.contains(stem, '[ьй]{consonant}$'):  # 2).
                _.log_info('Подслучай B.2).')
                if i.adj:
                    e = i.stem.type == '5-letter-ц' or not _.contains(
                        i.stress_type, 'b') or _.endswith(
                            i.stress_type,
                            ['/b', "/b'"])  # todo: fix only "b" for srt...
                else:
                    e = i.stem.type == '5-letter-ц' or _.equals(
                        i.stress_type, ['a', 'd', "d'"]
                    )  # gen_pl ending unstressed  -- TODO: special vars for that
                # end
                if e:
                    _.replace(p.stems, case, '[ьй]({consonant})$', 'е%1')
                else:
                    _.replace(p.stems, case, '[ьй]({consonant})$', 'ё%1')
                # end
            else:  # 3).
                prev = _.extract(stem, '(.){consonant}$')
                case_3_a = i.stem.type == '3-velar' and _.contains(
                    prev, '[^жшчщц]')  # 3). а).
                case_3_b = _.contains(prev, '[кгх]')  # 3). б).
                if case_3_a or case_3_b:
                    _.log_info('Подслучай B.3). а,б).')
                    _.replace(p.stems, case, '(.)({consonant})$', '%1о%2')
                else:  # 3). в).
                    _.log_info('Подслучай B.3). в).')
                    if i.stem.type == '5-letter-ц':
                        _.log_info('i.stem.type == "letter-ц"')
                        _.replace(p.stems, case, '(.)({consonant})$', '%1е%2')
                    else:
                        if i.adj:
                            e = _.equals(i.stress_type, 'b') or _.endswith(
                                i.stress_type,
                                ['/b', "/b'"])  # TODO: special vars for that
                        else:
                            e = _.In(
                                i.stress_type,
                                {'b', 'c', 'e', 'f', "f'", "b'"}
                            )  # gen_pl ending stressed  -- TODO: special vars for that
                        # end
                        if e:
                            _.log_info('в `' + case +
                                       '` ударение на окончание')
                            p.stems[case] = stem
                            if _.contains(prev, '[жшчщ]'):
                                _.log_info('предыдущая [жшчщ]')
                                _.replace(p.stems, case, '(.)({consonant})$',
                                          '%1о́%2')
                            else:
                                _.log_info('предыдущая не [жшчщ]')
                                _.replace(p.stems, case, '(.)({consonant})$',
                                          '%1ё%2')
                            # end
                        else:
                            _.log_info('ударение на основу в ["' + case +
                                       '"] ')
                            _.replace(p.stems, case, '(.)({consonant})$',
                                      '%1е%2')
                        # end
                    # end
                # end
            # end
            if i.stem.type == '2-soft' and _.endswith(
                    i.word.unstressed, 'ня'
            ) and i.stress_type == 'a' and p.endings['gen-pl'] == 'ь':
                p.endings['gen-pl'] = ''  # вместо `ь` для `2*a`
            # end
            if gender == 'm' and i.adj and _.endswith(
                    i.word.unstressed, 'ний') and p.endings['srt-sg'] == 'ь':
                p.endings['srt-sg'] = ''  # вместо `ь` для `2*a`
示例#12
0
def join_forms(func, out_args_1,
               out_args_2):  # export  # todo: rename to `variations`
    # local keys, out_args, delim

    keys = [
        'nom-sg',
        'gen-sg',
        'dat-sg',
        'acc-sg',
        'ins-sg',
        'prp-sg',
        'nom-pl',
        'gen-pl',
        'dat-pl',
        'acc-pl',
        'ins-pl',
        'prp-pl',
        'nom-sg-m',
        'gen-sg-m',
        'dat-sg-m',
        'acc-sg-m',
        'ins-sg-m',
        'prp-sg-m',
        'nom-sg-n',
        'gen-sg-n',
        'dat-sg-n',
        'acc-sg-n',
        'ins-sg-n',
        'prp-sg-n',
        'nom-sg-f',
        'gen-sg-f',
        'dat-sg-f',
        'acc-sg-f',
        'ins-sg-f',
        'prp-sg-f',
        'srt-sg',
        'srt-sg-m',
        'srt-sg-n',
        'srt-sg-f',
        'srt-pl',
        'acc-sg-m-a',
        'acc-sg-m-n',
        'acc-pl-a',
        'acc-pl-n',
        'ins-sg2',
        'ins-sg2-f',
        'зализняк1',
        'зализняк',
        'error',
    ]  # list

    out_args = out_args_1
    out_args['зализняк-1'] = out_args_1['зализняк']
    out_args['зализняк-2'] = out_args_2['зализняк']
    for j, key in enumerate(keys):
        if not _.has_key(out_args, key) and not _.has_key(out_args_2, key):
            pass
        elif not _.has_key(out_args, key) and _.has_key(
                out_args_2, key):  # INFO: Если out_args[key] == None
            out_args[key] = out_args_2[key]
        elif out_args[key] != out_args_2[key] and out_args_2[key]:
            delim = '<br/>'
            if _.equals(key, ['зализняк1', 'зализняк']):
                delim = '&nbsp;'
            # end
            # TODO: <br/> только для падежей
            out_args[
                key] = out_args[key] + '&nbsp;//' + delim + out_args_2[key]
        # end
        if not _.has_key(
                out_args,
                key) or not out_args[key]:  # INFO: Если out_args[key] == None
            out_args[key] = ''
        # end
    # end

    return _.returns(module, func, out_args)