@@ -93,14 +93,20 @@ def get_benchmark_cols(
9393 sorted (range_res .items (), key = lambda x : x [0 ], reverse = True )
9494 )
9595 for k , v in sorted_res .items ():
96- if not all (v ):
97- continue
98-
99- longest_x = np .insert (longest_x , v [1 ], cur_row [k ])
100- longest_col_points = np .insert (
101- longest_col_points , v [1 ], polygons [row_value [k ]], axis = 0
102- )
103-
96+ # bugfix: https://github.com/RapidAI/TableStructureRec/discussions/55
97+ # 最长列不包含第一列和最后一列的场景需要兼容
98+ if all (v ) or v [1 ] == 0 :
99+ longest_x = np .insert (longest_x , v [1 ], cur_row [k ])
100+ longest_col_points = np .insert (
101+ longest_col_points , v [1 ], polygons [row_value [k ]], axis = 0
102+ )
103+ elif v [0 ] and v [0 ] + 1 == len (longest_x ):
104+ longest_x = np .append (longest_x , cur_row [k ])
105+ longest_col_points = np .append (
106+ longest_col_points ,
107+ polygons [row_value [k ]][np .newaxis , :, :],
108+ axis = 0 ,
109+ )
104110 # 求出最右侧所有cell的宽,其中最小的作为最后一列宽度
105111 rightmost_idxs = [v [- 1 ] for v in rows .values ()]
106112 rightmost_boxes = polygons [rightmost_idxs ]
0 commit comments