Ejemplo n.º 1
0
def init_result(func, i):  # export
    r = i.result  # local

    r['stem_type'] = i.stem.type  # for testcases
    r['stress_type'] = i.stress_type  # for categories   -- is really used?

    r['dev'] = dev_prefix

    index.get_zaliznyak(i)

    additional_arguments(i)

    if i.noun:
        forward_gender_animacy(i)
    # end

    if i.adj:
        if _.contains(i.rest_index, ['⊠', '%(x%)', '%(х%)', '%(X%)', '%(Х%)']):
            r['краткая'] = '⊠'
        elif _.contains(i.rest_index, ['✕', '×', 'x', 'х', 'X', 'Х']):
            r['краткая'] = '✕'
        elif _.contains(i.rest_index, ['%-', '—', '−']):
            r['краткая'] = '−'
        else:
            r['краткая'] = '1'
        # end
    # end

    if not _.has_key(r, 'error_category') and i.word.cleared != i.base:
        r['error_category'] = 'Ошибка в шаблоне "сущ-ru" (слово не совпадает с заголовком статьи)'
    # end

    forward.forward_args(i)

    _.ends(module, func)
Ejemplo n.º 2
0
def choose_endings_stress(func, i):
    p = i.parts  # local

    keys = [  # local
        'nom-sg',
        'gen-sg',
        'dat-sg',
        'acc-sg',
        'ins-sg',
        'prp-sg',  # 'srt-sg',
        'nom-pl',
        'gen-pl',
        'dat-pl',
        'acc-pl',
        'ins-pl',
        'prp-pl',  # 'srt-pl',
    ]  # list
    for j, key in enumerate(keys):
        if _.has_key(p.endings, key) and type(p.endings[key]) == list:  # type
            stress = i.stress_schema['ending'][
                key] and stressed or unstressed  # local
            p.endings[key] = p.endings[key][stress]
        # end
    # end

    if i.adj and i.gender == 'n':
        stress = i.stress_schema['ending'][
            'srt-sg-n'] and stressed or unstressed  # local
        p.endings['srt-sg'] = p.endings['srt-sg'][stress]
    # end

    _.ends(module, func)
Ejemplo n.º 3
0
def forward_args(func, i):  # export
    # INFO: Используется дважды -- при инициализации, и потом в самом конце

    # local keys, args
    r = i.result  # local

    args = i.args
    keys = [
        'nom-sg',  'gen-sg',  'dat-sg',  'acc-sg',  'ins-sg',  'prp-sg',
        'nom-sg2', 'gen-sg2', 'dat-sg2', 'acc-sg2', 'ins-sg2', 'prp-sg2',
        'nom-pl',  'gen-pl',  'dat-pl',  'acc-pl',  'ins-pl',  'prp-pl',
        'nom-pl2', 'gen-pl2', 'dat-pl2', 'acc-pl2', 'ins-pl2', 'prp-pl2',
        'voc-sg',  'loc-sg',  'prt-sg', 'srt-sg-m', 'srt-sg-f', 'srt-sg-n',
        'srt-pl', 'comparative', 'comparative2'
    ]  # list
    for j, key in enumerate(keys):
        if _.has_value(args, key):
            if args[key] == '-':
                r[key] = args[key]
            else:
                r[key] = args[key] + '<sup>△</sup>'
            # end
        # end
    # end

    keys = [
        'П', 'Пр', 'Сч',
        'hide-text', 'зачин', 'слоги', 'дореф',
        'скл', 'зализняк', 'зализняк1', 'чередование',
        'pt', 'st', 'затрудн', 'клитика',
        'коммент', 'тип', 'степень',
    ]  # list
    for j, key in enumerate(keys):
        if _.has_value(args, key):
            r[key] = args[key]
        # end
    # end

    if _.has_key(r, 'слоги'):
        if not _.contains(r['слоги'], '%<'):
            r['слоги'] = syllables.get_syllables(r['слоги'])
        # end
    else:
        r['слоги'] = i.word.unstressed  # fixme: может всё-таки stressed?
    # end

    _.ends(module, func)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)