Skip to content

Commit

Permalink
Catalan WIP, fixed issue with strip-accent and infinitive mood
Browse files Browse the repository at this point in the history
  • Loading branch information
bretttolbert committed Dec 24, 2023
1 parent d0a3026 commit 7cc394d
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- 1.9.5 [24 December 2023]
- Improved Catalan Support
- Added more missing templates (7+)
- TODO: Still missing 11 templates for 35 out of 8616 verbs
- TODO: Still missing 9 templates for 28 out of 8616 verbs
- See `test_inflector_ca.test_all_verbs_have_templates`

- 1.9.4 [23 December 2023]
Expand Down
46 changes: 42 additions & 4 deletions tests/test_inflector_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_all_verbs_have_templates():
verbs = cg.get_verbs()
assert len(verbs) == 8616
template_names = cg.get_template_names()
assert len(template_names) == 60
assert len(template_names) == 61
missing_verbs = []
missing_templates = set()
for verb in verbs:
Expand Down Expand Up @@ -2498,6 +2498,45 @@ def test_find_verb_by_infinitive():
"m",
["surt", "surti", "sortim", "sortiu", "surtin"],
),
(
"témer",
"indicatiu",
"present",
False,
"f",
[
"jo temo",
"tu tems",
"ella tem",
"nosaltres temem",
"vosaltres temeu",
"elles temen",
],
),
(
"témer",
"infinitiu",
"infinitiu-present",
False,
"m",
["témer"],
),
(
"témer",
"gerundi",
"gerundi",
False,
"m",
["tement"],
),
(
"témer",
"particip",
"particip",
False,
"f",
["temut", "temuda", "temuts", "temudes"],
),
],
)
def test_inflector_ca_conjugate_mood_tense(
Expand Down Expand Up @@ -2528,10 +2567,9 @@ def test_inflector_ca_get_conj_obs_2():
def test_inflector_ca_get_conj_obs_3():
co = cg._inflector._get_conj_obs("pertànyer")
assert co.verb.infinitive == "pertànyer"
assert (
co.verb_stem == "pertany"
) # modify-stem="strip-accents" changes "pertàny" to "pertany"
assert co.verb_stem == "pertàny"
assert co.template.name == "pertàny:er"
assert co.template.modify_stem == "strip-accents"


def test_inflector_ca_get_verb_stem_from_template_name():
Expand Down
95 changes: 95 additions & 0 deletions verbecc/data/conjugations-ca.xml
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,101 @@ Note: this verb is only conjugated in the third-person.
</Particip>
</template>

<!-- TODO: Inherit from perdre
Literally exactly the same except for infinitive ending.
-->
<template name="tém:er" modify-stem="strip-accents">
<Indicatiu>
<present>
<p><i>o</i></p>
<p><i>s</i></p>
<p><i></i></p>
<p><i>em</i></p>
<p><i>eu</i></p>
<p><i>en</i></p>
</present>
<imperfet>
<p><i>ia</i></p>
<p><i>ies</i></p>
<p><i>ia</i></p>
<p><i>íem</i></p>
<p><i>íeu</i></p>
<p><i>ien</i></p>
</imperfet>
<passat-simple>
<p><i>í</i></p>
<p><i>eres</i></p>
<p><i>é</i></p>
<p><i>érem</i></p>
<p><i>éreu</i></p>
<p><i>eren</i></p>
</passat-simple>
<futur>
<p><i>é</i></p>
<p><i>às</i></p>
<p><i>à</i></p>
<p><i>em</i></p>
<p><i>eu</i></p>
<p><i>an</i></p>
</futur>
</Indicatiu>
<Subjuntiu>
<present>
<p><i>i</i></p>
<p><i>is</i></p>
<p><i>i</i></p>
<p><i>em</i></p>
<p><i>eu</i></p>
<p><i>in</i></p>
</present>
<imperfet>
<p><i>és</i></p>
<p><i>essis</i></p>
<p><i>és</i></p>
<p><i>éssim</i></p>
<p><i>éssiu</i></p>
<p><i>essin</i></p>
</imperfet>
</Subjuntiu>
<Imperatiu>
<imperatiu-present>
<p><i></i></p>
<p><i>i</i></p>
<p><i>em</i></p>
<p><i>eu</i></p>
<p><i>in</i></p>
</imperatiu-present>
</Imperatiu>
<Condicional>
<present>
<p><i>ria</i></p>
<p><i>ries</i></p>
<p><i>ria</i></p>
<p><i>ríem</i></p>
<p><i>ríeu</i></p>
<p><i>rien</i></p>
</present>
</Condicional>
<Infinitiu>
<infinitiu-present>
<p><i>er</i></p>
</infinitiu-present>
</Infinitiu>
<Gerundi>
<gerundi>
<p><i>ent</i></p>
</gerundi>
</Gerundi>
<Particip>
<particip>
<p><i>ut</i></p>
<p><i>uda</i></p>
<p><i>uts</i></p>
<p><i>udes</i></p>
</particip>
</Particip>
</template>

<!-- TODO: Inherit from perd:re -->
<template name="mou:re" modify-stem="strip-accents">
<Indicatiu>
Expand Down
10 changes: 5 additions & 5 deletions verbecc/data/verbs-ca.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4924,7 +4924,7 @@
<v><i>esprimatxar</i><t>cant:ar</t><en></en></v>
<v><i>esprintar</i><t>cant:ar</t><en></en></v>
<v><i>esprovar</i><t>cant:ar</t><en></en></v>
<v><i>esprémer</i><t>t:émer</t><en></en></v>
<v><i>esprémer</i><t>tém:er</t><en></en></v>
<v><i>espuar</i><t>evacu:ar</t><en></en></v>
<v><i>espuntar</i><t>cant:ar</t><en></en></v>
<v><i>espuntegar</i><t>preg:ar</t><en></en></v>
Expand Down Expand Up @@ -7047,7 +7047,7 @@
<v><i>provenir</i><t>prev:enir</t><en></en></v>
<v><i>provocar</i><t>tren:car</t><en></en></v>
<v><i>pruir</i><t>entrellu:ir</t><en></en></v>
<v><i>prémer</i><t>t:émer</t><en></en></v>
<v><i>prémer</i><t>tém:er</t><en></en></v>
<v><i>pseudomorfitzar</i><t>cant:ar</t><en></en></v>
<v><i>psicoanalitzar</i><t>cant:ar</t><en></en></v>
<v><i>publicar</i><t>tren:car</t><en></en></v>
Expand Down Expand Up @@ -8198,7 +8198,7 @@
<v><i>termofixar</i><t>cant:ar</t><en></en></v>
<v><i>terrabastejar</i><t>enve:jar</t><en></en></v>
<v><i>terraplenar</i><t>cant:ar</t><en></en></v>
<v><i>terratrémer</i><t>t:émer</t><en></en></v>
<v><i>terratrémer</i><t>tém:er</t><en></en></v>
<v><i>terrejar</i><t>enve:jar</t><en></en></v>
<v><i>terrenejar</i><t>enve:jar</t><en></en></v>
<v><i>terrenyar</i><t>cant:ar</t><en></en></v>
Expand Down Expand Up @@ -8416,7 +8416,7 @@
<v><i>trullar</i><t>cant:ar</t><en></en></v>
<v><i>trumfar</i><t>cant:ar</t><en></en></v>
<v><i>truncar</i><t>tren:car</t><en></en></v>
<v><i>trémer</i><t>t:émer</t><en></en></v>
<v><i>trémer</i><t>tém:er</t><en></en></v>
<v><i>tuberculitzar</i><t>cant:ar</t><en></en></v>
<v><i>tudar</i><t>cant:ar</t><en></en></v>
<v><i>tuejar</i><t>enve:jar</t><en></en></v>
Expand All @@ -8428,7 +8428,7 @@
<v><i>tustar</i><t>cant:ar</t><en></en></v>
<v><i>tutejar</i><t>enve:jar</t><en></en></v>
<v><i>tutelar</i><t>cant:ar</t><en></en></v>
<v><i>témer</i><t>perd:re</t><en></en></v>
<v><i>témer</i><t>tém:er</t><en>fear</en></v>
<v><i>tòrcer</i><t>comen:çar</t><en>twist</en></v>
<v><i>ubicar</i><t>tren:car</t><en></en></v>
<v><i>ucar</i><t>tren:car</t><en></en></v>
Expand Down
20 changes: 15 additions & 5 deletions verbecc/inflector.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def _get_conj_obs(self, infinitive: str) -> ConjugationObjects:
verb_stem = self._get_verb_stem_from_template_name(
verb.infinitive, template.name
)
if template.modify_stem == "strip-accents":
verb_stem = strip_accents(verb_stem)
return Inflector.ConjugationObjects(
infinitive, verb, template, verb_stem, is_reflexive
)
Expand Down Expand Up @@ -216,6 +214,9 @@ def _conjugate_mood_tense(
is_reflexive=co.is_reflexive,
alternate=alternate,
gender=gender,
modify_stem_strip_accents=bool(
co.template.modify_stem == "strip-accents"
),
)

def _get_tenses_conjugated_without_pronouns(self) -> List[str]:
Expand All @@ -229,12 +230,18 @@ def _get_auxilary_verb(
def _is_auxilary_verb_inflected(self, auxilary_verb: str):
return False

def _get_infinitive_mood_name(self) -> str:
return "infinitive"

def _get_indicative_mood_name(self) -> str:
return "indicative"

def _get_subjunctive_mood_name(self) -> str:
return "subjunctive"

def _get_conditional_mood_name(self) -> str:
return "conditional"

def _get_participle_mood_name(self) -> str:
return "partiple"

Expand Down Expand Up @@ -288,9 +295,9 @@ def _combine_verb_stem_and_ending(self, verb_stem: str, ending: str) -> str:
modify-stem="strip-accents"
So the stem "pertàny" becomes "pertany"
modify-stem="strip-accents" is applied in the constructor of ConjugationObjects,
and so the verb_stem argument to _conjugate_simple_mood_tense and consequently
this function is presumed to already have applicable modifications applied.
modify-stem="strip-accents" is applied in _conjugate_simple_mood_tense,
so the verb_stem argument to this function is presumed to already have
applicable modifications applied.
Next, the "pertàny:er" template endings will use the new delete operator
to delete one letter from the end of the stem.
Expand All @@ -316,7 +323,10 @@ def _conjugate_simple_mood_tense(
is_reflexive: bool = False,
alternate: bool = False,
gender: str = "m",
modify_stem_strip_accents: bool = False,
) -> List[str]:
if modify_stem_strip_accents and mood_name != self._get_infinitive_mood_name():
verb_stem = strip_accents(verb_stem)
ret = []
tense_name = tense_template.name
if tense_name in self._get_tenses_conjugated_without_pronouns():
Expand Down
12 changes: 12 additions & 0 deletions verbecc/inflector_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def _get_auxilary_verb(
) -> str:
return "haver"

def _get_infinitive_mood_name(self):
return "infinitiu"

def _get_indicative_mood_name(self):
return "indicatiu"

def _get_subjunctive_mood_name(self):
return "subjuntiu"

def _get_conditional_mood_name(self):
return "condicional"

def _get_participle_mood_name(self) -> str:
return "particip"

Expand Down
12 changes: 12 additions & 0 deletions verbecc/inflector_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def _get_auxilary_verb(
) -> str:
return "haber"

def _get_infinitive_mood_name(self):
return "infinitivo"

def _get_indicative_mood_name(self):
return "indicativo"

def _get_subjunctive_mood_name(self):
return "subjuntivo"

def _get_conditional_mood_name(self):
return "condicional"

def _get_participle_mood_name(self) -> str:
return "participo"

Expand Down
9 changes: 9 additions & 0 deletions verbecc/inflector_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,18 @@ def _get_auxilary_verb(
def _is_auxilary_verb_inflected(self, auxilary_verb: str) -> bool:
return auxilary_verb == "être"

def _get_infinitive_mood_name(self) -> str:
return "infinitif"

def _get_indicative_mood_name(self) -> str:
return "indicatif"

def _get_subjunctive_mood_name(self) -> str:
return "subjonctif"

def _get_conditional_mood_name(self) -> str:
return "conditionnel"

def _get_participle_mood_name(self) -> str:
return "participe"

Expand Down
9 changes: 9 additions & 0 deletions verbecc/inflector_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ def _get_tenses_conjugated_without_pronouns(self):
def _get_auxilary_verb(self, co, mood_name, tense_name):
return "avere"

def _get_infinitive_mood_name(self):
return "infinitivo"

def _get_indicative_mood_name(self):
return "indicativo"

def _get_subjunctive_mood_name(self):
return "congiuntivo"

def _get_conditional_mood_name(self):
return "condizionale"

def _get_participle_mood_name(self):
return "participio"

Expand Down
9 changes: 9 additions & 0 deletions verbecc/inflector_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,18 @@ def _get_auxilary_verb(
) -> str:
return "ter"

def _get_infinitive_mood_name(self):
return "infinitivo"

def _get_indicative_mood_name(self):
return "indicativo"

def _get_subjunctive_mood_name(self) -> str:
return "subjuntivo"

def _get_conditional_mood_name(self):
return "condicional"

def _get_participle_mood_name(self) -> str:
return "particípio"

Expand Down
6 changes: 6 additions & 0 deletions verbecc/inflector_ro.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ def _get_auxilary_verb(self, co, mood_name, tense_name):
return co.verb.infinitive
return "avea"

def _get_infinitive_mood_name(self):
return "infinitiv"

def _get_indicative_mood_name(self):
return "indicativ"

def _get_subjunctive_mood_name(self):
return "conjunctiv"

def _get_conditional_mood_name(self):
raise NotImplementedError

def _get_participle_mood_name(self):
return "participiu"

Expand Down

0 comments on commit 7cc394d

Please sign in to comment.