| 88 | return pairs |
| 89 | |
| 90 | def find_triplet(self, tags, aspect_spans, opinion_spans, token_ranges): |
| 91 | triplets = [] |
| 92 | for al, ar in aspect_spans: |
| 93 | for pl, pr in opinion_spans: |
| 94 | tag_num = [0] * 6 |
| 95 | for i in range(al, ar + 1): |
| 96 | for j in range(pl, pr + 1): |
| 97 | a_start = token_ranges[i][0] |
| 98 | o_start = token_ranges[j][0] |
| 99 | if al < pl: |
| 100 | tag_num[int(tags[a_start][o_start])] += 1 |
| 101 | else: |
| 102 | tag_num[int(tags[o_start][a_start])] += 1 |
| 103 | # if tags[i][j] != -1: |
| 104 | # tag_num[int(tags[i][j])] += 1 |
| 105 | # if tags[j][i] != -1: |
| 106 | # tag_num[int(tags[j][i])] += 1 |
| 107 | if sum(tag_num[3:]) == 0: continue |
| 108 | sentiment = -1 |
| 109 | if tag_num[5] >= tag_num[4] and tag_num[5] >= tag_num[3]: |
| 110 | sentiment = 5 |
| 111 | elif tag_num[4] >= tag_num[3] and tag_num[4] >= tag_num[5]: |
| 112 | sentiment = 4 |
| 113 | elif tag_num[3] >= tag_num[5] and tag_num[3] >= tag_num[4]: |
| 114 | sentiment = 3 |
| 115 | if sentiment == -1: |
| 116 | print('wrong!!!!!!!!!!!!!!!!!!!!') |
| 117 | input() |
| 118 | triplets.append([al, ar, pl, pr, sentiment]) |
| 119 | return triplets |
| 120 | |
| 121 | def score_aspect(self): |
| 122 | assert len(self.predictions) == len(self.goldens) |