(gleaf, pleaf)
| 183 | leaf['node']['norm_bbox'] = normalize_bbox(leaf['node']['bounding_box'], ref) |
| 184 | |
| 185 | def leaf_cost(gleaf, pleaf): |
| 186 | is_both_image = (gleaf['node']['tag'] == 'image' and pleaf['node']['tag'] == 'g' and pleaf['ref_group_name'] in ['icon-item', 'image']) |
| 187 | if gleaf['node']['tag'] != pleaf['node']['tag'] and not is_both_image and \ |
| 188 | not (gleaf['node']['tag'] == 'path' and pleaf['node']['tag'] in ['rect', 'circle', 'ellipse', 'polygon']) and \ |
| 189 | not (pleaf['node']['tag'] == 'path' and gleaf['node']['tag'] in ['rect', 'circle', 'ellipse', 'polygon']) and \ |
| 190 | not ('text' in gleaf['node'] and 'text' in pleaf['node']): |
| 191 | return 1e9, [] |
| 192 | |
| 193 | sims = [] |
| 194 | |
| 195 | # deal with images |
| 196 | if is_both_image: |
| 197 | img_sim = image_similarity(gleaf, pleaf) |
| 198 | sims.append(float(img_sim)) |
| 199 | elif gleaf['node']['tag'] == 'text' and 'text' in gleaf['node'] and 'text' in pleaf['node']: |
| 200 | text_sim = text_similarity(gleaf, pleaf) |
| 201 | sims.append(float(text_sim)) |
| 202 | else: |
| 203 | color_sim = color_similarity(gleaf, pleaf) |
| 204 | sims.append(float(color_sim)) |
| 205 | |
| 206 | pos_sim = pos_similarity(gleaf, pleaf) |
| 207 | sims.append(float(pos_sim)) |
| 208 | |
| 209 | return 1 - (sum(sims) / len(sims)), sims |
| 210 | |
| 211 | |
| 212 | def pair_leafs(gt_leafs, pr_leafs, gt_matched_prs, pr_matched_gts, gt_match_costs, gt_match_sims): |
no test coverage detected