word_db: add random-pick methods
This commit is contained in:
parent
695813d35f
commit
62bb8076e9
1 changed files with 23 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
|
import secrets
|
||||||
import typing as t
|
import typing as t
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -12,17 +13,32 @@ class Genre(Enum):
|
||||||
FEM = "féminin"
|
FEM = "féminin"
|
||||||
INV = "invariable" # pour les noms uniquement
|
INV = "invariable" # pour les noms uniquement
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pick(cls) -> "Genre":
|
||||||
|
"""random-pick (avoids inv)"""
|
||||||
|
return secrets.choice([cls.masc, cls.fem])
|
||||||
|
|
||||||
|
|
||||||
class Nombre(Enum):
|
class Nombre(Enum):
|
||||||
SING = "singulier"
|
SING = "singulier"
|
||||||
PLUR = "pluriel"
|
PLUR = "pluriel"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pick(cls) -> "Nombre":
|
||||||
|
"""random-pick"""
|
||||||
|
return secrets.choice(list(cls))
|
||||||
|
|
||||||
|
|
||||||
class Temps(Enum):
|
class Temps(Enum):
|
||||||
PRESENT = "present"
|
PRESENT = "present"
|
||||||
FUTUR = "futur"
|
FUTUR = "futur"
|
||||||
IMPARFAIT = "imparfait"
|
IMPARFAIT = "imparfait"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pick(cls) -> "Temps":
|
||||||
|
"""random-pick"""
|
||||||
|
return secrets.choice(list(cls))
|
||||||
|
|
||||||
|
|
||||||
class Nom(t.NamedTuple):
|
class Nom(t.NamedTuple):
|
||||||
"""Nom commun"""
|
"""Nom commun"""
|
||||||
|
@ -38,6 +54,13 @@ class Nom(t.NamedTuple):
|
||||||
"""Accorde en nombre"""
|
"""Accorde en nombre"""
|
||||||
return getattr(self, nombre.name.lower())
|
return getattr(self, nombre.name.lower())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def genre_or_pick(self) -> Genre:
|
||||||
|
"""Genre of the noun, or random-pick if invariable"""
|
||||||
|
if self.genre == Genre.INV:
|
||||||
|
return Genre.pick()
|
||||||
|
return self.genre
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def serialized(self):
|
def serialized(self):
|
||||||
return {"genre": self.genre.name, "sing": self.sing, "plur": self.plur}
|
return {"genre": self.genre.name, "sing": self.sing, "plur": self.plur}
|
||||||
|
|
Loading…
Reference in a new issue