include optional verbs
This commit is contained in:
parent
b8b8e42b8e
commit
67d6e4322f
27
main.py
27
main.py
@ -25,11 +25,11 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
|
||||
@app.get("/allwords/", response_model=list[str])
|
||||
def words():
|
||||
with Session(engine) as session:
|
||||
results = session.exec(select(Word.word)).all()
|
||||
return results
|
||||
# @app.get("/allwords/", response_model=list[str])
|
||||
# def words():
|
||||
# with Session(engine) as session:
|
||||
# results = session.exec(select(Word.word)).all()
|
||||
# return results
|
||||
|
||||
|
||||
@app.get("/randomword/", response_model=str)
|
||||
@ -48,11 +48,21 @@ def random_char():
|
||||
@app.get("/phrases/", response_model=list[str])
|
||||
def phrases(n: int = 4, nouns: int = 1, adjs: int = 2, pw: bool = False):
|
||||
n, nouns, adjs = map(abs, [n, nouns, adjs])
|
||||
nouns = nouns if nouns <= 4 else 16
|
||||
adjs = adjs if adjs <= 4 else 16
|
||||
verbs = verbs if verbs <= 4 else 4
|
||||
adjs = adjs if adjs <= 4 else 4
|
||||
nouns = nouns if nouns <= 4 else 4
|
||||
n = n if n <= 200 else 200
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(Sense.word)
|
||||
.where(Sense.word_class == "verb")
|
||||
.where(text("sense.word !~ '\s|-'"))
|
||||
.order_by(text("random()"))
|
||||
.limit(n * adjs)
|
||||
)
|
||||
l_verbs = session.exec(stmt).all()
|
||||
|
||||
stmt = (
|
||||
select(Sense.word)
|
||||
.where(Sense.word_class == "adjective")
|
||||
@ -71,7 +81,8 @@ def phrases(n: int = 4, nouns: int = 1, adjs: int = 2, pw: bool = False):
|
||||
)
|
||||
l_nouns = session.exec(stmt).all()
|
||||
phrases = [
|
||||
l_adjectives[i * adjs : (i + 1) * adjs]
|
||||
l_verbs[i * verbs : (i + 1) * verbs]
|
||||
+ l_adjectives[i * adjs : (i + 1) * adjs]
|
||||
+ l_nouns[i * nouns : (i + 1) * nouns]
|
||||
for i in range(n)
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user