first commit

This commit is contained in:
stuart committed 2025-12-07 15:05:18 +01:00
1 parent 5037a09608
commit 94815b7918
10 files changed
+181

No files matched your search

View File
Whitespace-only changes.
+18
View File
@@ -0,0 +1,18 @@
from __future__ import annotations
from dataclasses import dataclass
import torch
@dataclass(frozen=True)
class Embedding:
data: torch.Tensor
def __post_init__(self):
if not isinstance(self.data, torch.Tensor):
raise TypeError(f"data must be a torch.Tensor, got {type(self.data)}")
def compare(self, other: Embedding) -> float:
"""
Compare this embedding with another embedding.
"""
raise NotImplementedError("compare method must be implemented")
+22
View File
@@ -0,0 +1,22 @@
from abc import ABC, abstractmethod
from typing import List, Union
from dataclasses import dataclass
from .embedding import Embedding
@dataclass
class Lexeme(ABC):
id: int
@property
@abstractmethod
def content(self) -> Union[str, List[str]]:
"""Text content of the lexeme."""
pass
@property
@abstractmethod
def embedding(self) -> Embedding:
"""Embedding(s) associated with the lexeme."""
pass
+26
View File
@@ -0,0 +1,26 @@
from typing import List
from .lexeme import Lexeme
from .embedding import Embedding
from .word import Word
class Phrase(Lexeme):
def __init__(self, id: int, content: str, embedding: Embedding):
self.id = id
self._content = content
self._embedding = embedding
@property
def content(self) -> List[str]:
return self._content
@property
def embedding(self) -> Embedding:
return self._embedding
def __str__(self):
return self.content
def __repr__(self):
return self.__str__()
+10
View File
@@ -0,0 +1,10 @@
from dataclasses import dataclass
from typing import Optional
from PIL import Image
@dataclass
class Symbol:
id: int
label: str
image: Optional[Image.Image]
+23
View File
@@ -0,0 +1,23 @@
from .lexeme import Lexeme
from .embedding import Embedding
class Word(Lexeme):
def __init__(self, word_id: int, content: str, embedding: Embedding):
self.id = word_id
self._content = content
self._embedding = embedding
@property
def content(self) -> str:
return self._content
@property
def embedding(self) -> Embedding:
return self._embedding
def __str__(self):
return self.content
def __repr__(self):
return self.__str__()