Пример #1
0
def pluralize_word(word, number):
    """
    Согласует слово с числом
    """
    assert isinstance(number, six.integer_types)

    parsed = morph.parse(word)
    if isinstance(parsed, list):
        pluralized = parsed[0].make_agree_with_number(number)
        if pluralized is not None:
            return restore_capitalization(pluralized.word, word)

    return word
Пример #2
0
def pluralize_word(word, number):
    """
    Pluralize a word according to a given number.
    """
    assert isinstance(number, six.integer_types)

    parsed = morph.parse(word)
    if isinstance(parsed, list):
        pluralized = parsed[0].make_agree_with_number(number)
        if pluralized is not None:
            return restore_capitalization(pluralized.word, word)

    return word
Пример #3
0
def inflect_word(word, forms, specifying_forms=None):
    """
    Converts a word into a given form.
    """
    parsed = morph.parse(word)

    for p in parsed:
        if p.tag.POS in DONT_INFLECT_FORMS:
            return word
        else:
            if isinstance(specifying_forms,
                          set) and specifying_forms not in p.tag:
                continue

            parsed_word = p.inflect(forms)
            if parsed_word is not None:
                return restore_capitalization(parsed_word.word, word)

    return word
Пример #4
0
def inflect_word(word, forms, specifying_forms=None):
    """
    Склоняет одно слово в переданную форму
    """
    parsed = morph.parse(word)

    for p in parsed:
        if p.tag.POS in DONT_INFLECT_FORMS:
            return word
        else:
            # Нам необходима определенная словоформа. Остальные пропускаем

            if isinstance(specifying_forms, set) and specifying_forms not in p.tag:
                continue

            parsed_word = p.inflect(forms)
            if parsed_word is not None:
                return restore_capitalization(parsed_word.word, word)

    return word
Пример #5
0
def inflect_word(word, forms, specifying_forms=None):
    """
    Склоняет одно слово в переданную форму
    """
    parsed = morph.parse(word)

    for p in parsed:
        if p.tag.POS in DONT_INFLECT_FORMS:
            return word
        else:
            # Нам необходима определенная словоформа. Остальные пропускаем

            if isinstance(specifying_forms, set) and specifying_forms not in p.tag:
                continue

            parsed_word = p.inflect(forms)
            if parsed_word is not None:
                return restore_capitalization(parsed_word.word, word)

    return word
Пример #6
0
def inflect_word_from_nomn(word, forms, *args, **kwargs):
    parsed = morph.parse(word)

    forms_cache = []
    for p in parsed:
        if p.tag.POS not in DONT_INFLECT_FORMS:
            if (forms in p.tag
                    and (p.normal_form == p.word or 'NOUN' not in p.tag)):
                return restore_capitalization(p.word, word)

            if 'nomn' not in p.tag:
                continue

            forms_cache.append(p)

    if len(forms_cache) > 0:
        p = forms_cache[0]
        parsed_word = p.inflect(forms)

        if parsed_word is not None:
            return restore_capitalization(parsed_word.word, word)

    return word
Пример #7
0
def inflect_word_from_nomn(word, forms, *args, **kwargs):
    parsed = morph.parse(word)

    forms_cache = []
    for p in parsed:
        if p.tag.POS not in DONT_INFLECT_FORMS:
            # Нам необходима определенная словоформа. Остальные пропускаем
            if (forms in p.tag and (p.normal_form == p.word or 'NOUN' not in p.tag)):
                return restore_capitalization(p.word, word)

            if 'nomn' not in p.tag:
                continue

            forms_cache.append(p)

    if len(forms_cache) > 0:
        p = forms_cache[0]
        parsed_word = p.inflect(forms)

        if parsed_word is not None:
            return restore_capitalization(parsed_word.word, word)

    return word