From c0fca119e73564ebadb48af06c181496bb8f4510 Mon Sep 17 00:00:00 2001 From: Christoph Eder Date: Mon, 15 Dec 2025 16:35:54 +0100 Subject: [PATCH 1/3] Changes in phrase.py Added from_noembeddingphrase to Phrase --- anansyTypes/structures/phrase.py | 48 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/anansyTypes/structures/phrase.py b/anansyTypes/structures/phrase.py index 0e77307..e752a2f 100644 --- a/anansyTypes/structures/phrase.py +++ b/anansyTypes/structures/phrase.py @@ -5,6 +5,26 @@ from .lexeme import Lexeme from .embedding import Embedding import numpy as np + +class NoEmbeddingPhrase(Lexeme): + def __init__(self, id: int, content: str): + self.id = id + self._content = content + self._embedding = np.array([]) # Placeholder to avoid attribute errors + + @property + def content(self) -> str: + return self._content + + @property + def embedding(self) -> Embedding: + return self._embedding + + @classmethod + def from_dict(cls, data: dict) -> "NoEmbeddingPhrase": + return cls(id=data["id"], content=data["content"]) + + class Phrase(Lexeme): def __init__(self, id: int, content: str, embedding: Embedding): self.id = id @@ -18,6 +38,7 @@ class Phrase(Lexeme): @property def embedding(self) -> Embedding: return self._embedding + @classmethod def from_dict(cls, data: dict) -> "Phrase": return cls( @@ -25,24 +46,13 @@ class Phrase(Lexeme): content=data["content"], embedding=Embedding.from_dict(data["embedding"]), ) - - -class NoEmbeddingPhrase(Lexeme): - def __init__(self, id: int, content: str): - self.id = id - self._content = content - self._embedding=np.array([]) # Placeholder to avoid attribute errors - @property - def content(self) -> str: - return self._content - - @property - def embedding(self) -> Embedding: - return self._embedding - + @classmethod - def from_dict(cls, data: dict) -> "NoEmbeddingPhrase": + def from_noembeddingphrase( + cls, phrase: NoEmbeddingPhrase, embedding: Embedding + ) -> "Phrase": return cls( - id=data["id"], - content=data["content"] - ) \ No newline at end of file + id=phrase.id, + content=phrase.content, + embedding=embedding, + ) From 4a6187b7c1ca6f5234dfde8cace32711fe9d973b Mon Sep 17 00:00:00 2001 From: Christoph Eder Date: Mon, 15 Dec 2025 16:47:10 +0100 Subject: [PATCH 2/3] Changes in schemas.py Made return of None possible, instead of throwing 404 --- anansyTypes/schemas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anansyTypes/schemas.py b/anansyTypes/schemas.py index 9ccd72a..dbc1e20 100644 --- a/anansyTypes/schemas.py +++ b/anansyTypes/schemas.py @@ -49,13 +49,13 @@ class GetSimilarWordRequest(ModifiedBaseModel): embedding: Embedding class GetAllPhrasesResponse(ModifiedBaseModel): - phrases: List[NoEmbeddingPhrase] + phrases: Optional[List[NoEmbeddingPhrase]] class GetFullPhrasesRequest(ModifiedBaseModel): phrases: List[NoEmbeddingPhrase] class GetFullPhrasesResponse(ModifiedBaseModel): - phrases: List[Phrase] + phrases: Optional[List[Phrase]] class GetTranscriptionRequest(ModifiedBaseModel): audio_data: bytes From 701952c309edebce566380ee9538a13a07b9f7ed Mon Sep 17 00:00:00 2001 From: Christoph Eder Date: Mon, 15 Dec 2025 17:04:59 +0100 Subject: [PATCH 3/3] Changes in enums.py Added ResourceType for word and symbol --- anansyTypes/enums.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/anansyTypes/enums.py b/anansyTypes/enums.py index cf6c1dd..be54d38 100644 --- a/anansyTypes/enums.py +++ b/anansyTypes/enums.py @@ -38,3 +38,8 @@ class Language(Enum): NORWEGIAN = "norwegian" ENGLISH = "english" DEFAULT = "norwegian" + + +class ResourceType(Enum): + WORD = "word" + SYMBOL = "symbol"