From 38733a91b7921c5b0b737fcba55fdb32f1b333c1 Mon Sep 17 00:00:00 2001 From: Nikita Shevtsov <61932814+Travvy88@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:14:10 +0300 Subject: [PATCH] TLDR-473 make BBox class Serializable (#14) Co-authored-by: Nikita Shevtsov --- CHANGELOG.md | 5 +++++ VERSION | 2 +- dedocutils/data_structures/bbox.py | 4 +++- dedocutils/data_structures/serializable.py | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 dedocutils/data_structures/serializable.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 899d4b1..fd0cd2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +v0.3.4 (2023-09-28) +------------------- +* Add `Serializable` class +* Make `BBox` child class of `Serializable` + v0.3.3 (2023-09-28) ------------------- * Update `BBox` class diff --git a/VERSION b/VERSION index 87a0871..448a0fa 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.3 \ No newline at end of file +0.3.4 \ No newline at end of file diff --git a/dedocutils/data_structures/bbox.py b/dedocutils/data_structures/bbox.py index bf69090..310de53 100644 --- a/dedocutils/data_structures/bbox.py +++ b/dedocutils/data_structures/bbox.py @@ -5,9 +5,11 @@ import numpy as np +from dedocutils.data_structures.serializable import Serializable + @dataclass -class BBox: +class BBox(Serializable): """ Bounding box around some page object, the coordinate system starts from top left corner. """ diff --git a/dedocutils/data_structures/serializable.py b/dedocutils/data_structures/serializable.py new file mode 100644 index 0000000..9de5d23 --- /dev/null +++ b/dedocutils/data_structures/serializable.py @@ -0,0 +1,16 @@ +from abc import ABC, abstractmethod + + +class Serializable(ABC): + """ + Base class for the serializable objects which we need convert to dict. + """ + @abstractmethod + def to_dict(self) -> dict: + """ + Convert class data into dictionary representation. + Dictionary key should be string and dictionary value should be json serializable. + + :return: dict with all class data. + """ + pass