Example #1
0
def inflect(singular, options):
    """ Returns array of inflected forms, starting with nominative, singular."""
    # Get inflection as is, without alternate forms.
    normal = [generate_case(singular, options, x) for x in EXTENSIONS]
    # Check if we have extra info required for alternate forms.
    a_plural = options.get('a_plural')
    a_p_gender = options.get('a_p_gender')
    if a_plural == None or a_p_gender == None:
        return normal

    if a_p_gender == defs.Gender.F:
        # Pretend our plural is singular for 4th group.
        # Also skip first returned result, since it won't match the pattern.
        group_f_c_result = f_c.inflect(a_plural)
        return normal[:7] + [a_plural] + group_f_c_result[8:]

    # For cases we didn't cover.
    return normal
Example #2
0
def inflect_noun(singular, options):
    """ Takes singular nominative of the noun and additional options.
        Returns an array with cases in singular followed by plural.
    """
    try:
        # Try exceptions list first.
        result = exceptions.return_exception(singular)
        if result != None:
            return result
        # Otherwise try to classify noun type and call appropriate handler.
        group = classify_noun(singular, options)
        if group == defs.DeclinationGroup.GROUP_MN_COE:
            print('MN_COE')
        elif group == defs.DeclinationGroup.GROUP_N_E_NT:
            return group_n_e_nt.inflect(singular, options)
        elif group == defs.DeclinationGroup.GROUP_MFN_A:
            return group_mfn_a.inflect(singular)
        else:
            return group_f_c.inflect(singular)
    except:
        # Let caller decide whether to bail or to continue.
        raise
Example #3
0
 def test_group_f_c_1(self):
     self.assertEqual([
         "ствар", "ствари", "ствари", "ствар", "стварју", "ствари",
         "ствари", "ствари", "ствари", "стварима", "ствари", "ствари",
         "стварима", "стварима"
     ], f_c.inflect("ствар"))
Example #4
0
 def test_group_f_c_6(self):
     self.assertEqual([
         "младост", "младости", "младости", "младост", "младошћу",
         "младости", "младости", "младости", "младости", "младостима",
         "младости", "младости", "младостима", "младостима"
     ], f_c.inflect("младост"))
Example #5
0
 def test_group_f_c_5(self):
     self.assertEqual([
         "памет", "памети", "памети", "памет", "памећу", "памети", "памети",
         "памети", "памети", "паметима", "памети", "памети", "паметима",
         "паметима"
     ], f_c.inflect("памет"))
Example #6
0
 def test_group_f_c_4(self):
     self.assertEqual([
         "љубав", "љубави", "љубави", "љубав", "љубављу", "љубави",
         "љубави", "љубави", "љубави", "љубавима", "љубави", "љубави",
         "љубавима", "љубавима"
     ], f_c.inflect("љубав"))
Example #7
0
 def test_group_f_c_3(self):
     self.assertEqual([
         "пећ", "пећи", "пећи", "пећ", "пећу", "пећи", "пећи", "пећи",
         "пећи", "пећима", "пећи", "пећи", "пећима", "пећима"
     ], f_c.inflect("пећ"))
Example #8
0
 def test_group_f_c_2(self):
     self.assertEqual([
         "чађ", "чађи", "чађи", "чађ", "чађу", "чађи", "чађи", "чађи",
         "чађи", "чађима", "чађи", "чађи", "чађима", "чађима"
     ], f_c.inflect("чађ"))