Skip to content

Commit

Permalink
added include_alternates and conjugate_pronouns options
Browse files Browse the repository at this point in the history
  • Loading branch information
bretttolbert committed Jan 5, 2024
1 parent bff30ce commit 15eeaa0
Show file tree
Hide file tree
Showing 7 changed files with 615 additions and 12 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# verbecc Changelog

- 1.9.7 [Jan 5 2024]
- Added option to include alternate conjugations
- Added option to not conjugate pronouns e.g. return _apprends_ rather than _j'apprends_
- Example: `include_alternates=False, conjugate_pronouns=True` (equivalent to classic verbecc behavior)
```json
"condicional": {
"present": [
"jo seria",
"tu series",
"ell seria",
"nosaltres seríem",
"vosaltres seríeu",
"ells serien",
]
},
```
- Example: `include_alternates=True, conjugate_pronouns=False` (observe now a list of one or more conjugations is returned in place of the scalar value)
```json
"condicional": {
"present": [
["seria", "fora"],
["series", "fores"],
["seria", "fora"],
["seríem", "fórem"],
["seríeu", "fóreu"],
["serien", "foren"],
]
},
```

- 1.9.6 [26 December 2023]
- Improved Catalan Support
- Added remaining missing templates for all 8616 verbs
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "verbecc"
version = "1.9.6"
version = "1.9.7"
dependencies = [
"lxml",
"lxml-stubs",
Expand Down
274 changes: 274 additions & 0 deletions tests/test_inflector_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -2985,3 +2985,277 @@ def test_inflector_ca_get_default_pronoun(
cg._inflector._get_default_pronoun(person, gender, is_reflexive=is_reflexive)
== expected_result
)


def test_inflector_conjugate():
assert cg.conjugate("ser") == {
"verb": {
"infinitive": "ser",
"predicted": False,
"pred_score": 1.0,
"template": "és:ser",
"translation_en": "be",
"stem": "",
},
"moods": {
"indicatiu": {
"present": [
"jo sóc",
"tu ets",
"ell és",
"nosaltres som",
"vosaltres sou",
"ells són",
],
"imperfet": [
"jo era",
"tu eres",
"ell era",
"nosaltres érem",
"vosaltres éreu",
"ells eren",
],
"passat-simple": [
"jo fui",
"tu fores",
"ell fou",
"nosaltres fórem",
"vosaltres fóreu",
"ells foren",
],
"futur": [
"jo seré",
"tu seràs",
"ell serà",
"nosaltres serem",
"vosaltres sereu",
"ells seran",
],
},
"subjuntiu": {
"present": [
"jo sigui",
"tu siguis",
"ell sigui",
"nosaltres siguem",
"vosaltres sigueu",
"ells siguin",
],
"imperfet": [
"jo fos",
"tu fossis",
"ell fos",
"nosaltres fóssim",
"vosaltres fóssiu",
"ells fossin",
],
},
"imperatiu": {
"imperatiu-present": ["sigues", "sigui", "siguem", "sigueu", "siguin"]
},
"condicional": {
"present": [
"jo seria",
"tu series",
"ell seria",
"nosaltres seríem",
"vosaltres seríeu",
"ells serien",
]
},
"infinitiu": {"infinitiu-present": ["ser"]},
"gerundi": {"gerundi": ["sent"]},
"particip": {"particip": ["estat", "estada", "estats", "estades"]},
},
}


def test_inflector_conjugate_with_alternates():
assert cg.conjugate("ser", include_alternates=True) == {
"verb": {
"infinitive": "ser",
"predicted": False,
"pred_score": 1.0,
"template": "és:ser",
"translation_en": "be",
"stem": "",
},
"moods": {
"indicatiu": {
"present": [
["jo sóc"],
["tu ets"],
["ell és"],
["nosaltres som"],
["vosaltres sou"],
["ells són"],
],
"imperfet": [
["jo era"],
["tu eres"],
["ell era"],
["nosaltres érem"],
["vosaltres éreu"],
["ells eren"],
],
"passat-simple": [
["jo fui"],
["tu fores"],
["ell fou"],
["nosaltres fórem"],
["vosaltres fóreu"],
["ells foren"],
],
"futur": [
["jo seré"],
["tu seràs"],
["ell serà"],
["nosaltres serem"],
["vosaltres sereu"],
["ells seran"],
],
},
"subjuntiu": {
"present": [
["jo sigui"],
["tu siguis"],
["ell sigui"],
["nosaltres siguem"],
["vosaltres sigueu"],
["ells siguin"],
],
"imperfet": [
["jo fos"],
["tu fossis"],
["ell fos"],
["nosaltres fóssim"],
["vosaltres fóssiu"],
["ells fossin"],
],
},
"imperatiu": {
"imperatiu-present": [
["sigues"],
["sigui"],
["siguem"],
["sigueu"],
["siguin"],
]
},
"condicional": {
"present": [
["jo seria", "jo fora"],
["tu series", "tu fores"],
["ell seria", "ell fora"],
["nosaltres seríem", "nosaltres fórem"],
["vosaltres seríeu", "vosaltres fóreu"],
["ells serien", "ells foren"],
]
},
"infinitiu": {"infinitiu-present": [["ser", "ésser"]]},
"gerundi": {"gerundi": [["sent", "essent"]]},
"particip": {
"particip": [
["estat", "sigut"],
["estada", "siguda"],
["estats", "siguts"],
["estades", "sigudes"],
]
},
},
}

def test_inflector_conjugate_with_alternates_noconjpronouns():
assert cg.conjugate("ser", include_alternates=True, conjugate_pronouns=False) == {
"verb": {
"infinitive": "ser",
"predicted": False,
"pred_score": 1.0,
"template": "és:ser",
"translation_en": "be",
"stem": "",
},
"moods": {
"indicatiu": {
"present": [
["sóc"],
["ets"],
["és"],
["som"],
["sou"],
["són"],
],
"imperfet": [
["era"],
["eres"],
["era"],
["érem"],
["éreu"],
["eren"],
],
"passat-simple": [
["fui"],
["fores"],
["fou"],
["fórem"],
["fóreu"],
["foren"],
],
"futur": [
["seré"],
["seràs"],
["serà"],
["serem"],
["sereu"],
["seran"],
],
},
"subjuntiu": {
"present": [
["sigui"],
["siguis"],
["sigui"],
["siguem"],
["sigueu"],
["siguin"],
],
"imperfet": [
["fos"],
["fossis"],
["fos"],
["fóssim"],
["fóssiu"],
["fossin"],
],
},
"imperatiu": {
"imperatiu-present": [
["sigues"],
["sigui"],
["siguem"],
["sigueu"],
["siguin"],
]
},
"condicional": {
"present": [
["seria", "fora"],
["series", "fores"],
["seria", "fora"],
["seríem", "fórem"],
["seríeu", "fóreu"],
["serien", "foren"],
]
},
"infinitiu": {"infinitiu-present": [["ser", "ésser"]]},
"gerundi": {"gerundi": [["sent", "essent"]]},
"particip": {
"particip": [
["estat", "sigut"],
["estada", "siguda"],
["estats", "siguts"],
["estades", "sigudes"],
]
},
},
}
28 changes: 25 additions & 3 deletions verbecc/conjugator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,34 @@ def __init__(self, lang: str):
else:
raise InvalidLangError

def conjugate(self, infinitive: str):
return self._inflector.conjugate(infinitive)
def conjugate(
self, infinitive: str, include_alternates: bool = False, conjugate_pronouns=True
):
"""
:param include_alterates: if True, a list of one or more possible conjugations is returned
if False, the default conjugation is returned as a scalar string
:param conjugate_prouns: if True, verbecc will conjugate the pronoun together with
its inflected form, e.g. for the French verb apprendre, for the first-person singular
present tense you'd get "j'apprends" if True or "apprends" if False.
E.g. for the Catalan verb "ser"
include_alternates=False, conjugate_pronouns=True -> "jo seria"
include_alternates=True, conjugate_pronouns=False -> ["seria", "fora"]
"""
return self._inflector.conjugate(
infinitive, include_alternates, conjugate_pronouns
)

def conjugate_mood(self, infinitive: str, mood_name: str):
def conjugate_mood(self, infinitive: str, mood_name: str) -> Dict[str, List[str]]:
return self._inflector.conjugate_mood(infinitive, mood_name)

def conjugate_mood_include_alternates(
self, infinitive: str, mood_name: str
) -> Dict[str, List[List[str]]]:
return self._inflector.conjugate_mood_include_alternates(
infinitive, mood_name, conjugate_pronouns=True
)

def conjugate_mood_tense(
self,
infinitive: str,
Expand Down
6 changes: 2 additions & 4 deletions verbecc/data/conjugations-ca.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,12 @@ voler ("to want"), caldre ("must"), dir ("to say") and dur ("to take/get").
</Condicional>
<Infinitiu>
<infinitiu-present>
<p><i>ser</i></p>
<p><i>ésser</i></p>
<p><i>ser</i><i>ésser</i></p>
</infinitiu-present>
</Infinitiu>
<Gerundi>
<gerundi>
<p><i>sent</i></p>
<p><i>essent</i></p>
<p><i>sent</i><i>essent</i></p>
</gerundi>
</Gerundi>
<Particip>
Expand Down
Loading

0 comments on commit 15eeaa0

Please sign in to comment.