-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_structure.py
More file actions
71 lines (55 loc) · 1.89 KB
/
Copy pathdata_structure.py
File metadata and controls
71 lines (55 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from xml.etree import ElementTree
kinds = ['formula', 'figure', 'table']
class FileData:
def __init__(self):
self.page_lines = []
self.filename = ''
self.img_path = ''
def set_image_path(self, img_path):
self.img_path = img_path
def get_txt_name(self):
return self.filename.split('\\')[-1]
def get_img_name(self):
return self.imgpath.split('\\')[-1]
def read_txt(self, txt_path):
self.filename = txt_path
self.page_lines = []
root = ElementTree.parse(txt_path)
for name in ['figureRegion', 'formulaRegion', 'tableRegion']:
p = root.findall(name)
for line in p:
coords = line.getchildren()
line = coords[0].attrib['points']
line = line.split(' ')
kinds = name.split('Region')[0]
region = Rect(10000, 0, 10000, 0)
for xy in line:
x, y = xy.split(',')
region.update(int(x), int(y))
self.page_lines.append(PageLine(region, kinds))
class PageLine:
def __init__(self, rect, kind):
self.kind = kind
self.rect = rect
self.comp_list = []
self.prob = 0
def add_comp(self, comp):
self.compList.append(comp)
def show_comp(self):
for comp_region in self.comp_list:
print(comp_region.tostr(), ',')
def show(self):
print(self.rect.tostr()+'\t'+self.kind)
def get_kind(self):
return self.kind
class Rect:
def __init__(self, l, r, u, d):
self.l = int(l)
self.r = int(r)
self.u = int(u)
self.d = int(d)
def update(self, x, y):
self.l = min(self.l, x)
self.r = max(self.r, x)
self.u = min(self.u, y)
self.d = max(self.d, y)