@@ -20,10 +20,11 @@ def __init__(self, df, caption=None, figure_id=None, annotations=None):
20
20
self .df = df .applymap (lambda x : Cell (value = x ))
21
21
if annotations is not None :
22
22
self .gold_tags = annotations .gold_tags .strip ()
23
- rows , cols = annotations .matrix_gold_tags .shape
24
- for r in range (rows ):
25
- for c in range (cols ):
26
- self .df .iloc [r ,c ].gold_tags = annotations .matrix_gold_tags .iloc [r ,c ].strip ()
23
+ tags = annotations .matrix_gold_tags
24
+ if self .df .shape != (0 ,0 ):
25
+ for r , row in enumerate (tags ):
26
+ for c , cell in enumerate (row ):
27
+ self .df .iloc [r ,c ].gold_tags = cell .strip ()
27
28
else :
28
29
self .gold_tags = ''
29
30
@@ -33,10 +34,14 @@ def from_file(cls, path, metadata, annotations=None):
33
34
df = pd .read_csv (path , header = None , dtype = str ).fillna ('' )
34
35
except pd .errors .EmptyDataError :
35
36
df = pd .DataFrame ()
36
- return cls (df , metadata .get ('caption' ), metadata .get ('figure_id' ), annotations )
37
+ if annotations is not None :
38
+ table_ann = annotations .table_set .filter (name = metadata ['filename' ]) + [None ]
39
+ table_ann = table_ann [0 ]
40
+ else :
41
+ table_ann = None
42
+ return cls (df , metadata .get ('caption' ), metadata .get ('figure_id' ), table_ann )
37
43
38
44
def display (self ):
39
-
40
45
display_table (self .df .applymap (lambda x : x .value ).values , self .df .applymap (lambda x : x .gold_tags ).values )
41
46
42
47
def read_tables (path , annotations ):
0 commit comments