refactor: Switch annotation away from dataclass
To ease employing getters and setters, we switch the dataclass to a normal python undecorated class.
This commit is contained in:
parent
f4a26292a0
commit
67bfc30396
2 changed files with 25 additions and 14 deletions
|
@ -29,18 +29,25 @@ class Annotation:
|
||||||
Contains all information necessary for the annotation itself, content and metadata.
|
Contains all information necessary for the annotation itself, content and metadata.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
file: str
|
def __init__(
|
||||||
color: tuple[float, float, float]
|
self,
|
||||||
content: str = ""
|
file: str,
|
||||||
note: str = ""
|
color: tuple[float, float, float] = (0.0, 0.0, 0.0),
|
||||||
page: int = 0
|
content: str = "",
|
||||||
tag: str = ""
|
note: str = "",
|
||||||
type: str = "Highlight"
|
page: int = 0,
|
||||||
minimum_similarity_color: float = 1.0
|
tag: str = "",
|
||||||
|
type: str = "Highlight",
|
||||||
def __post_init__(self):
|
minimum_similarity_color: float = 1.0,
|
||||||
self._color = self.color or field(default_factory=lambda: (0.0, 0.0, 0.0))
|
) -> None:
|
||||||
self.tag = self.tag or self._tag_from_colorname(self.colorname or "")
|
self.minimum_similarity_color = minimum_similarity_color
|
||||||
|
self.file = file
|
||||||
|
self.color = color
|
||||||
|
self.content = content
|
||||||
|
self.note = note
|
||||||
|
self.page = page
|
||||||
|
self.tag = tag
|
||||||
|
self.type = type
|
||||||
|
|
||||||
def format(self, formatting: str, doc: Document = Document()):
|
def format(self, formatting: str, doc: Document = Document()):
|
||||||
"""Return a formatted string of the annotation.
|
"""Return a formatted string of the annotation.
|
||||||
|
@ -89,7 +96,11 @@ class Annotation:
|
||||||
nearest = name
|
nearest = name
|
||||||
return nearest
|
return nearest
|
||||||
|
|
||||||
def _color_similarity_ratio(self, color_one, color_two):
|
def _color_similarity_ratio(
|
||||||
|
self,
|
||||||
|
color_one: tuple[float, float, float],
|
||||||
|
color_two: tuple[float, float, float],
|
||||||
|
) -> float:
|
||||||
"""Return the similarity of two colors between 0 and 1.
|
"""Return the similarity of two colors between 0 and 1.
|
||||||
|
|
||||||
Takes two rgb color tuples made of floats between 0 and 1,
|
Takes two rgb color tuples made of floats between 0 and 1,
|
||||||
|
|
2
poetry.lock
generated
2
poetry.lock
generated
|
@ -1084,4 +1084,4 @@ whoosh = ["whoosh"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "02d5ac314a19f14103372c7ceccdaec080df3fdc2fdb1381f2f6343cd6d17db4"
|
content-hash = "273c651cac44163ca183313ce3c7384577f090fd98fa6d28e6a3496cb28254ac"
|
||||||
|
|
Loading…
Reference in a new issue