This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
generated from childmindresearch/template-python-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add synonym/jeopardy/antonym endpoints (#6)
* Add synonym/jeopardy/antonym endpoints * online postgres debug * online postgres debug * Fix faulty ID * Refactor text task endpoints and schemas
- Loading branch information
1 parent
79f13c8
commit 68d83c5
Showing
11 changed files
with
282 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,55 @@ | ||
"""Models for the text router.""" | ||
from typing import Any | ||
|
||
import sqlalchemy | ||
from sqlalchemy import orm | ||
from sqlalchemy import orm, types | ||
|
||
from linguaweb_api.core import models | ||
|
||
|
||
class CommaSeparatedList(types.TypeDecorator): | ||
"""A custom SQLAlchemy for comma separated lists.""" | ||
|
||
impl = sqlalchemy.String(1024) | ||
|
||
def process_bind_param(self, value: Any | None, dialect: Any) -> str | None: # noqa: ANN401, ARG002 | ||
"""Converts a list of strings to a comma separated string. | ||
Args: | ||
value: The list of strings or a comma separated string. | ||
dialect: The dialect. | ||
Returns: | ||
str | None: The comma separated string. | ||
""" | ||
if value is None: | ||
return None | ||
if isinstance(value, list): | ||
return ",".join(value) | ||
return value | ||
|
||
def process_result_value(self, value: Any | None, dialect: Any) -> list[str] | None: # noqa: ARG002, ANN401 | ||
"""Converts a comma separated string to a list of strings. | ||
Args: | ||
value: The comma separated string. | ||
dialect: The dialect. | ||
Returns: | ||
list[str]: The list of strings. | ||
""" | ||
if value is None: | ||
return None | ||
return value.split(",") | ||
|
||
|
||
class TextTask(models.BaseTable): | ||
"""Table for text tasks.""" | ||
|
||
__tablename__ = "text_tasks" | ||
|
||
word: orm.Mapped[str] = orm.mapped_column(sqlalchemy.String(64), unique=True) | ||
description: orm.Mapped[str] = orm.mapped_column( | ||
sqlalchemy.String(1024), | ||
nullable=True, | ||
) | ||
description: orm.Mapped[str] = orm.mapped_column(sqlalchemy.String(1024)) | ||
synonyms: orm.Mapped[str] = orm.mapped_column(CommaSeparatedList) | ||
antonyms: orm.Mapped[str] = orm.mapped_column(CommaSeparatedList) | ||
jeopardy: orm.Mapped[str] = orm.mapped_column(sqlalchemy.String(1024)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.