def test_conjugate(self): # Assert different tenses with different conjugations. for (v1, v2, tense) in ( (u"être", u"être", fr.INFINITIVE), (u"être", u"suis", (fr.PRESENT, 1, fr.SINGULAR)), (u"être", u"es", (fr.PRESENT, 2, fr.SINGULAR)), (u"être", u"est", (fr.PRESENT, 3, fr.SINGULAR)), (u"être", u"sommes", (fr.PRESENT, 1, fr.PLURAL)), (u"être", u"êtes", (fr.PRESENT, 2, fr.PLURAL)), (u"être", u"sont", (fr.PRESENT, 3, fr.PLURAL)), (u"être", u"étant", (fr.PRESENT + fr.PARTICIPLE)), (u"être", u"été", (fr.PAST + fr.PARTICIPLE)), (u"être", u"étais", (fr.IMPERFECT, 1, fr.SINGULAR)), (u"être", u"étais", (fr.IMPERFECT, 2, fr.SINGULAR)), (u"être", u"était", (fr.IMPERFECT, 3, fr.SINGULAR)), (u"être", u"étions", (fr.IMPERFECT, 1, fr.PLURAL)), (u"être", u"étiez", (fr.IMPERFECT, 2, fr.PLURAL)), (u"être", u"étaient", (fr.IMPERFECT, 3, fr.PLURAL)), (u"être", u"fus", (fr.PRETERITE, 1, fr.SINGULAR)), (u"être", u"fus", (fr.PRETERITE, 2, fr.SINGULAR)), (u"être", u"fut", (fr.PRETERITE, 3, fr.SINGULAR)), (u"être", u"fûmes", (fr.PRETERITE, 1, fr.PLURAL)), (u"être", u"fûtes", (fr.PRETERITE, 2, fr.PLURAL)), (u"être", u"furent", (fr.PRETERITE, 3, fr.PLURAL)), (u"être", u"serais", (fr.CONDITIONAL, 1, fr.SINGULAR)), (u"être", u"serais", (fr.CONDITIONAL, 2, fr.SINGULAR)), (u"être", u"serait", (fr.CONDITIONAL, 3, fr.SINGULAR)), (u"être", u"serions", (fr.CONDITIONAL, 1, fr.PLURAL)), (u"être", u"seriez", (fr.CONDITIONAL, 2, fr.PLURAL)), (u"être", u"seraient", (fr.CONDITIONAL, 3, fr.PLURAL)), (u"être", u"serai", (fr.FUTURE, 1, fr.SINGULAR)), (u"être", u"seras", (fr.FUTURE, 2, fr.SINGULAR)), (u"être", u"sera", (fr.FUTURE, 3, fr.SINGULAR)), (u"être", u"serons", (fr.FUTURE, 1, fr.PLURAL)), (u"être", u"serez", (fr.FUTURE, 2, fr.PLURAL)), (u"être", u"seront", (fr.FUTURE, 3, fr.PLURAL)), (u"être", u"sois", (fr.PRESENT, 2, fr.SINGULAR, fr.IMPERATIVE)), (u"être", u"soyons", (fr.PRESENT, 1, fr.PLURAL, fr.IMPERATIVE)), (u"être", u"soyez", (fr.PRESENT, 2, fr.PLURAL, fr.IMPERATIVE)), (u"être", u"sois", (fr.PRESENT, 1, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"sois", (fr.PRESENT, 2, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"soit", (fr.PRESENT, 3, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"soyons", (fr.PRESENT, 1, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"soyez", (fr.PRESENT, 2, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"soient", (fr.PRESENT, 3, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"fusse", (fr.PAST, 1, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"fusses", (fr.PAST, 2, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"fût", (fr.PAST, 3, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"fussions", (fr.PAST, 1, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"fussiez", (fr.PAST, 2, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"fussent", (fr.PAST, 3, fr.PLURAL, fr.SUBJUNCTIVE))): self.assertEqual(fr.conjugate(v1, tense), v2) print("pattern.fr.conjugate()")
def test_conjugate(self): # Assert different tenses with different conjugations. for (v1, v2, tense) in ( (u"être", u"être", fr.INFINITIVE), (u"être", u"suis", (fr.PRESENT, 1, fr.SINGULAR)), (u"être", u"es", (fr.PRESENT, 2, fr.SINGULAR)), (u"être", u"est", (fr.PRESENT, 3, fr.SINGULAR)), (u"être", u"sommes", (fr.PRESENT, 1, fr.PLURAL)), (u"être", u"êtes", (fr.PRESENT, 2, fr.PLURAL)), (u"être", u"sont", (fr.PRESENT, 3, fr.PLURAL)), (u"être", u"étant", (fr.PRESENT + fr.PARTICIPLE)), (u"être", u"été", (fr.PAST + fr.PARTICIPLE)), (u"être", u"étais", (fr.IMPERFECT, 1, fr.SINGULAR)), (u"être", u"étais", (fr.IMPERFECT, 2, fr.SINGULAR)), (u"être", u"était", (fr.IMPERFECT, 3, fr.SINGULAR)), (u"être", u"étions", (fr.IMPERFECT, 1, fr.PLURAL)), (u"être", u"étiez", (fr.IMPERFECT, 2, fr.PLURAL)), (u"être", u"étaient", (fr.IMPERFECT, 3, fr.PLURAL)), (u"être", u"fus", (fr.PRETERITE, 1, fr.SINGULAR)), (u"être", u"fus", (fr.PRETERITE, 2, fr.SINGULAR)), (u"être", u"fut", (fr.PRETERITE, 3, fr.SINGULAR)), (u"être", u"fûmes", (fr.PRETERITE, 1, fr.PLURAL)), (u"être", u"fûtes", (fr.PRETERITE, 2, fr.PLURAL)), (u"être", u"furent", (fr.PRETERITE, 3, fr.PLURAL)), (u"être", u"serais", (fr.CONDITIONAL, 1, fr.SINGULAR)), (u"être", u"serais", (fr.CONDITIONAL, 2, fr.SINGULAR)), (u"être", u"serait", (fr.CONDITIONAL, 3, fr.SINGULAR)), (u"être", u"serions", (fr.CONDITIONAL, 1, fr.PLURAL)), (u"être", u"seriez", (fr.CONDITIONAL, 2, fr.PLURAL)), (u"être", u"seraient", (fr.CONDITIONAL, 3, fr.PLURAL)), (u"être", u"serai", (fr.FUTURE, 1, fr.SINGULAR)), (u"être", u"seras", (fr.FUTURE, 2, fr.SINGULAR)), (u"être", u"sera", (fr.FUTURE, 3, fr.SINGULAR)), (u"être", u"serons", (fr.FUTURE, 1, fr.PLURAL)), (u"être", u"serez", (fr.FUTURE, 2, fr.PLURAL)), (u"être", u"seront", (fr.FUTURE, 3, fr.PLURAL)), (u"être", u"sois", (fr.PRESENT, 2, fr.SINGULAR, fr.IMPERATIVE)), (u"être", u"soyons", (fr.PRESENT, 1, fr.PLURAL, fr.IMPERATIVE)), (u"être", u"soyez", (fr.PRESENT, 2, fr.PLURAL, fr.IMPERATIVE)), (u"être", u"sois", (fr.PRESENT, 1, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"sois", (fr.PRESENT, 2, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"soit", (fr.PRESENT, 3, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"soyons", (fr.PRESENT, 1, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"soyez", (fr.PRESENT, 2, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"soient", (fr.PRESENT, 3, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"fusse", (fr.PAST, 1, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"fusses", (fr.PAST, 2, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"fût", (fr.PAST, 3, fr.SINGULAR, fr.SUBJUNCTIVE)), (u"être", u"fussions", (fr.PAST, 1, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"fussiez", (fr.PAST, 2, fr.PLURAL, fr.SUBJUNCTIVE)), (u"être", u"fussent", (fr.PAST, 3, fr.PLURAL, fr.SUBJUNCTIVE))): self.assertEqual(fr.conjugate(v1, tense), v2) print "pattern.fr.conjugate()"
def correct_grammar(string, mot, pos, lemma): # maybe we can just use the original string # print('Mot: ' + mot.encode('utf-8') + \ # ', pos: ' + pos.encode('utf-8') + \ # ', lem: ' + lemma.encode('utf-8') + \ # ', str: ' + string.encode('utf-8')) # if specials[string]: string = specials[string] if pos == 'PUN': string = mot elif string.lower() == mot.lower() or \ pos not in pos_tt or \ mot.lower() in { 'l', 'ne', 'le', 'la', 'les', 'd', 'n'}: string = mot else: # we need to inflect # print('Str: ' + string.encode('utf-8') + \ # ', Mot: ' + mot.encode('utf-8') + \ # ', pos: ' + pos.encode('utf-8') + \ # ', lemma: ' + lemma.encode('utf-8')) if (pos == 'NOM' or pos == 'PRO') and mot != lemma: # print(pos.encode('utf-8') + \ # ' string: ' + string.encode('utf-8') + \ # ' mot: ' + mot.encode('utf-8') + \ # ' lemma: ' + lemma.encode('utf-8')) # pprint([ string, mot, pos, lemma ]) if singularize(mot) == lemma: string = pluralize(string) else: string = singularize(string) else: # verbs # pprint([ string, mot, pos, lemma ]) if pos == 'VER:pper': string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=PROGRESSIVE) elif pos == 'VER:ppre': string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=PROGRESSIVE) elif pos == 'VER:impe': if mot.endswith('ez'): string = conjugate(string, tense=PRESENT, mood=IMPERATIVE, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=PRESENT, mood=IMPERATIVE, aspect=IMPERFECTIVE, person=1, number=PL) else: string = conjugate(string, tense=PRESENT, mood=IMPERATIVE, aspect=IMPERFECTIVE, person=2, number=SG) elif pos == 'VER:impf': if mot.endswith('ez'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=IMPERFECTIVE, person=1, number=PL) elif mot.endswith('aient'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=IMPERFECTIVE, person=3, number=PL) elif mot.endswith('ait'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=IMPERFECTIVE, person=3, number=SG) else: string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=IMPERFECTIVE, person=2, number=SG) elif pos == 'VER:cond': if mot.endswith('ez'): string = conjugate(string, tense=PRESENT, mood=CONDITIONAL, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=PRESENT, mood=CONDITIONAL, aspect=IMPERFECTIVE, person=1, number=PL) elif mot.endswith('aient'): string = conjugate(string, tense=PRESENT, mood=CONDITIONAL, aspect=IMPERFECTIVE, person=3, number=PL) elif mot.endswith('ait'): string = conjugate(string, tense=PRESENT, mood=CONDITIONAL, aspect=IMPERFECTIVE, person=3, number=SG) else: string = conjugate(string, tense=PRESENT, mood=CONDITIONAL, aspect=IMPERFECTIVE, person=2, number=SG) elif pos == 'VER:futu': if mot.endswith('ez'): string = conjugate(string, tense=FUTURE, mood=INDICATIVE, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=FUTURE, mood=INDICATIVE, aspect=IMPERFECTIVE, person=1, number=PL) elif mot.endswith('ont'): string = conjugate(string, tense=FUTURE, mood=INDICATIVE, aspect=IMPERFECTIVE, person=3, number=PL) elif mot.endswith('a'): string = conjugate(string, tense=FUTURE, mood=INDICATIVE, aspect=IMPERFECTIVE, person=3, number=SG) else: string = conjugate(string, tense=FUTURE, mood=INDICATIVE, aspect=IMPERFECTIVE, person=2, number=SG) elif pos == 'VER:simp': if mot.endswith('tes'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=PERFECTIVE, person=2, number=PL) elif mot.endswith('mes'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=PERFECTIVE, person=1, number=PL) elif mot.endswith('ent'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=PERFECTIVE, person=3, number=PL) elif mot.endswith('t'): string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=PERFECTIVE, person=3, number=SG) else: string = conjugate(string, tense=PAST, mood=INDICATIVE, aspect=PERFECTIVE, person=2, number=SG) elif pos == 'VER:subi': if mot.endswith('ez'): string = conjugate(string, tense=PRESENT, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=PRESENT, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=1, number=PL) elif mot.endswith('ent'): string = conjugate(string, tense=PRESENT, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=3, number=PL) elif mot.endswith('t'): string = conjugate(string, tense=PRESENT, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=3, number=SG) elif mot.endswith('es'): string = conjugate(string, tense=PRESENT, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=2, number=SG) else: string = conjugate(string, tense=PRESENT, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=1, number=SG) elif pos == 'VER:subp': if mot.endswith('ez'): string = conjugate(string, tense=PAST, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=PAST, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=1, number=PL) elif mot.endswith('ent'): string = conjugate(string, tense=PAST, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=3, number=PL) elif mot.endswith('t'): string = conjugate(string, tense=PAST, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=3, number=SG) elif mot.endswith('es'): string = conjugate(string, tense=PAST, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=2, number=SG) else: string = conjugate(string, tense=PAST, mood=SUBJUNCTIVE, aspect=IMPERFECTIVE, person=1, number=SG) elif pos == 'VER:pres': if mot.endswith('ez'): string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=IMPERFECTIVE, person=2, number=PL) elif mot.endswith('ons'): string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=IMPERFECTIVE, person=1, number=PL) elif mot.endswith('ent'): string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=IMPERFECTIVE, person=3, number=PL) elif mot.endswith('t'): string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=IMPERFECTIVE, person=3, number=SG) elif mot.endswith('es'): string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=IMPERFECTIVE, person=2, number=SG) else: string = conjugate(string, tense=PRESENT, mood=INDICATIVE, aspect=IMPERFECTIVE, person=1, number=SG) # if (word.type in {'VB'}): # if mot[0].isupper(): string = string.capitalize() if mot.isupper(): string = string.upper() elif mot[0].isupper(): string = string[0].upper() + string[1:] return string