| 96 | |
| 97 | |
| 98 | def find_triplet(tags, aspect_spans, opinion_spans): |
| 99 | triplets = [] |
| 100 | for al, ar in aspect_spans: |
| 101 | for pl, pr in opinion_spans: |
| 102 | tag_num = [0]*6 |
| 103 | for i in range(al, ar+1): |
| 104 | for j in range(pl, pr+1): |
| 105 | if al < pl: |
| 106 | tag_num[int(tags[i][j])] += 1 |
| 107 | else: |
| 108 | tag_num[int(tags[j][i])] += 1 |
| 109 | if sum(tag_num[3:]) == 0: continue |
| 110 | sentiment = -1 |
| 111 | if tag_num[5] >= tag_num[4] and tag_num[5] >= tag_num[3]: |
| 112 | sentiment = 5 |
| 113 | elif tag_num[4] >= tag_num[3] and tag_num[4] >= tag_num[5]: |
| 114 | sentiment = 4 |
| 115 | elif tag_num[3] >= tag_num[5] and tag_num[3] >= tag_num[4]: |
| 116 | sentiment = 3 |
| 117 | if sentiment == -1: |
| 118 | print('wrong!!!!!!!!!!!!!!!!!!!!') |
| 119 | input() |
| 120 | triplets.append([al, ar, pl, pr, sentiment]) |
| 121 | return triplets |
| 122 | |
| 123 | |
| 124 | def score_uniontags(args, predicted, golden, lengths, ignore_index=-1): |