1
+ import copy
1
2
from typing import List , Optional
2
3
3
4
from dedocutils .data_structures import BBox
4
5
5
- from dedoc .data_structures .annotation import Annotation
6
6
from dedoc .data_structures .cell_with_meta import CellWithMeta
7
7
from dedoc .data_structures .line_with_meta import LineWithMeta
8
8
9
9
10
10
class Cell (CellWithMeta ):
11
11
12
12
@staticmethod
13
- def copy_from (cell : "Cell" ,
14
- x_top_left : Optional [int ] = None ,
15
- x_bottom_right : Optional [int ] = None ,
16
- y_top_left : Optional [int ] = None ,
17
- y_bottom_right : Optional [int ] = None ) -> "Cell" :
18
- x_top_left = cell .x_top_left if x_top_left is None else x_top_left
19
- x_bottom_right = cell .x_bottom_right if x_bottom_right is None else x_bottom_right
20
- y_top_left = cell .y_top_left if y_top_left is None else y_top_left
21
- y_bottom_right = cell .y_bottom_right if y_bottom_right is None else y_bottom_right
22
- return Cell (x_top_left = x_top_left ,
23
- x_bottom_right = x_bottom_right ,
24
- y_top_left = y_top_left ,
25
- y_bottom_right = y_bottom_right ,
26
- id_con = cell .id_con ,
27
- lines = cell .lines ,
28
- is_attribute = cell .is_attribute ,
29
- is_attribute_required = cell .is_attribute_required ,
30
- rotated_angle = cell .rotated_angle ,
31
- uid = cell .cell_uid ,
32
- contour_coord = cell .con_coord )
13
+ def copy_from (cell : "Cell" , bbox : Optional [BBox ] = None ) -> "Cell" :
14
+ copy_cell = copy .deepcopy (cell )
15
+ if bbox :
16
+ copy_cell .bbox = bbox
17
+
18
+ return copy_cell
33
19
34
20
def shift (self , shift_x : int , shift_y : int , image_width : int , image_height : int ) -> None :
35
21
if self .lines :
36
22
for line in self .lines :
37
23
line .shift (shift_x = shift_x , shift_y = shift_y , image_width = image_width , image_height = image_height )
38
- self .x_top_left += shift_x
39
- self .x_bottom_right += shift_x
40
- self .y_top_left += shift_y
41
- self .y_bottom_right += shift_y
42
- if self .con_coord :
43
- self .con_coord .shift (shift_x = shift_x , shift_y = shift_y )
44
24
45
- def __init__ ( self , x_top_left : int , x_bottom_right : int , y_top_left : int , y_bottom_right : int , id_con : int = - 1 , lines : Optional [ List [ LineWithMeta ]] = None ,
46
- is_attribute : bool = False , is_attribute_required : bool = False , rotated_angle : int = 0 , uid : str = None ,
47
- contour_coord : Optional [ BBox ] = None ) -> None :
25
+ self . bbox . shift ( shift_x = shift_x , shift_y = shift_y )
26
+ if self . contour_coord :
27
+ self . contour_coord . shift ( shift_x = shift_x , shift_y = shift_y )
48
28
49
- import uuid
29
+ def __init__ (self , bbox : BBox , id_con : int = - 1 , lines : Optional [List [LineWithMeta ]] = None ,
30
+ is_attribute : bool = False , is_attribute_required : bool = False , rotated_angle : int = 0 , uid : Optional [str ] = None ,
31
+ contour_coord : Optional [BBox ] = None , colspan : int = 1 , rowspan : int = 1 , invisible : bool = False ) -> None :
50
32
51
- assert x_top_left <= x_bottom_right
52
- assert y_top_left <= y_bottom_right
33
+ import uuid
53
34
54
- self .lines = [] if lines is None else lines
55
- super ().__init__ (lines )
35
+ super ().__init__ (lines = lines , colspan = colspan , rowspan = rowspan , invisible = invisible )
56
36
57
- self .x_top_left = x_top_left
58
- self .x_bottom_right = x_bottom_right
59
- self .y_top_left = y_top_left
60
- self .y_bottom_right = y_bottom_right
37
+ self .bbox = bbox
61
38
self .id_con = id_con
62
39
self .is_attribute = is_attribute
63
40
self .is_attribute_required = is_attribute_required
64
41
self .rotated_angle = rotated_angle
65
- self .cell_uid = f"cell_{ uuid .uuid1 ()} " if uid is None else uid
66
- self .con_coord = contour_coord or BBox (0 , 0 , 0 , 0 )
67
-
68
- def __str__ (self ) -> str :
69
- return f"Cell((cs={ self .colspan } , rs={ self .rowspan } , { self .get_text ()} )"
70
-
71
- def get_text (self ) -> str :
72
- return "\n " .join ([line .line for line in self .lines ])
73
-
74
- def get_annotations (self ) -> List [Annotation ]:
75
- return LineWithMeta .join (self .lines , delimiter = "\n " ).annotations
42
+ self .uuid = uuid .uuid4 () if uuid is None else uid
43
+ self .contour_coord = contour_coord or BBox (0 , 0 , 0 , 0 )
76
44
77
45
def change_lines_boxes_page_width_height (self , new_page_width : int , new_page_height : int ) -> None :
78
46
from dedoc .data_structures .concrete_annotations .bbox_annotation import BBoxAnnotation
@@ -96,11 +64,3 @@ def change_lines_boxes_page_width_height(self, new_page_width: int, new_page_hei
96
64
97
65
def __repr__ (self ) -> str :
98
66
return self .__str__ ()
99
-
100
- @property
101
- def width (self ) -> int :
102
- return self .x_bottom_right - self .x_top_left
103
-
104
- @property
105
- def height (self ) -> int :
106
- return self .y_bottom_right - self .y_top_left
0 commit comments