Beispiel #1
0
    def test_hints_defaults(self):
        case = 'Титову'.upper()

        self.assertEqualRu(lastnames_ru.normalize(morph_ru, case, ''),
            lastnames_ru.normalize(morph_ru, case, 'мр'))
        self.assertNotEqualRu(lastnames_ru.normalize(morph_ru, case, ''),
            lastnames_ru.normalize(morph_ru, case, 'жр'))
Beispiel #2
0
def inflect_female(morph, lemma, grams):
    """
    Приводит существительное (фамилию/отчество) к женскому роду, если необходимо
    """
    if u"жр" in grams:
        result = lastnames_ru.normalize(morph, lemma, u"жр")
        if result:
            return result
    return lemma
Beispiel #3
0
def inflect_female(morph, lemma, grams):
    """
    Приводит существительное (фамилию/отчество) к женскому роду, если необходимо
    """
    if u"жр" in grams:
        result = lastnames_ru.normalize(morph, lemma, u"жр")
        if result:
            return result
    return lemma
Beispiel #4
0
    def normalize_name(self, morph, save=True):
        from pymorphy.contrib import lastnames_ru
        # имя
        if not self.first_name:
            first_name = morph.normalize(self.first_name_inflated.upper()).pop()
            self.first_name = firstcaps(first_name)

        sex = morph.get_graminfo(self.first_name_inflated.upper())[0]['info'].split(',', 1)[0]
        # отчество
        if not self.patronymic:
            patronymic = morph.inflect_ru(self.patronymic_inflated.upper(), u'им')
            self.patronymic = firstcaps(patronymic)

        # фамилия
        if not self.last_name:
            last_name = lastnames_ru.normalize(morph, self.last_name_inflated.upper(), sex)
            self.last_name = firstcaps(last_name)

        if save:
            self.save()
Beispiel #5
0
	def lastname_normal_form(self, word, gender_tag):
		'''Returns normal form of last name'''
		return lastnames_ru.normalize(self.morph, morph_word(word), gender_tag)
Beispiel #6
0
 def test_misoperations(self):
     for word, gender_tag, wrong in self.testcase:
         res = lastnames_ru.normalize(morph_ru, word.upper(), gender_tag)
         self.assertNotEqual(res.capitalize(), wrong)
Beispiel #7
0
 def test_improper_guess(self):
     res = lastnames_ru.normalize(morph_ru, u'Ильвесом'.upper(), u'мр')
     self.assertEqualRu(res.capitalize(), u'Ильвес')
Beispiel #8
0
 def test_normal_form(self):
     for lastname, gender_tag, expected_lastname in self.testcase:
         res = lastnames_ru.normalize(morph_ru, lastname.upper(), gender_tag)
         self.assertEqualRu(res.capitalize(), expected_lastname)
Beispiel #9
0
 def test_misoperations(self):
     for word, gender_tag, wrong in self.testcase:
         res = lastnames_ru.normalize(morph_ru, word.upper(), gender_tag)
         self.assertNotEqual(res.capitalize(), wrong)
Beispiel #10
0
 def test_improper_guess(self):
     res = lastnames_ru.normalize(morph_ru, u'Ильвесом'.upper(), u'мр')
     self.assertEqualRu(res.capitalize(), u'Ильвес')
Beispiel #11
0
 def test_normal_form(self):
     for lastname, gender_tag, expected_lastname in self.testcase:
         res = lastnames_ru.normalize(morph_ru, lastname.upper(),
                                      gender_tag)
         self.assertEqualRu(res.capitalize(), expected_lastname)