72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
import secrets
|
|
|
|
from . import word_db
|
|
|
|
wdb = word_db.WordDb.autoload()
|
|
|
|
|
|
def gen_phrase4() -> str:
|
|
"""Generates a sentence with four words, of structure Adjective Noun Verb Adverb"""
|
|
nombre = word_db.Nombre.pick()
|
|
temps = word_db.Temps.pick()
|
|
|
|
adj = secrets.choice(wdb.adjectifs)
|
|
nom = secrets.choice(wdb.noms)
|
|
verbe = secrets.choice(wdb.verbes)
|
|
adverbe = secrets.choice(wdb.adverbes)
|
|
|
|
return " ".join(
|
|
[
|
|
adj.accord(nom.genre_or_pick, nombre),
|
|
nom.accord(nombre),
|
|
verbe.accord(temps, nombre),
|
|
adverbe.accord(),
|
|
]
|
|
)
|
|
|
|
|
|
def gen_phrase6() -> str:
|
|
"""Generates a sentence with six words, of structure Adjective Noun Verb Adjective
|
|
Noun Adverb"""
|
|
nombres = [word_db.Nombre.pick() for _ in range(2)]
|
|
temps = word_db.Temps.pick()
|
|
|
|
adj0 = secrets.choice(wdb.adjectifs)
|
|
nom0 = secrets.choice(wdb.noms)
|
|
verbe = secrets.choice(wdb.verbes)
|
|
adj1 = secrets.choice(wdb.adjectifs)
|
|
nom1 = secrets.choice(wdb.noms)
|
|
adverbe = secrets.choice(wdb.adverbes)
|
|
|
|
return " ".join(
|
|
[
|
|
adj0.accord(nom0.genre_or_pick, nombres[0]),
|
|
nom0.accord(nombres[0]),
|
|
verbe.accord(temps, nombres[0]),
|
|
adj1.accord(nom1.genre_or_pick, nombres[1]),
|
|
nom1.accord(nombres[1]),
|
|
adverbe.accord(),
|
|
]
|
|
)
|
|
|
|
|
|
def gen_rand(n=4) -> str:
|
|
"""Generates a fully random sequence of n words, without grammatical consistency"""
|
|
out = []
|
|
for _ in range(n):
|
|
word_cat = secrets.choice(list(wdb.CATEGORY_TO_ATTR))
|
|
if word_cat == word_db.Nom:
|
|
nombre = word_db.Nombre.pick()
|
|
out.append(secrets.choice(wdb.noms).accord(nombre))
|
|
elif word_cat == word_db.Adjectif:
|
|
genre = word_db.Genre.pick()
|
|
nombre = word_db.Nombre.pick()
|
|
out.append(secrets.choice(wdb.adjectifs).accord(genre, nombre))
|
|
elif word_cat == word_db.Verbe:
|
|
temps = word_db.Temps.pick()
|
|
nombre = word_db.Nombre.pick()
|
|
out.append(secrets.choice(wdb.verbes).accord(temps, nombre))
|
|
elif word_cat == word_db.Adverbe:
|
|
out.append(secrets.choice(wdb.adverbes).accord())
|
|
|
|
return " ".join(out)
|