for BIO tag
(tags)
| 6 | |
| 7 | |
| 8 | def get_spans(tags): |
| 9 | '''for BIO tag''' |
| 10 | tags = tags.strip().split() |
| 11 | length = len(tags) |
| 12 | spans = [] |
| 13 | start = -1 |
| 14 | for i in range(length): |
| 15 | if tags[i].endswith('B'): |
| 16 | if start != -1: |
| 17 | spans.append([start, i - 1]) |
| 18 | start = i |
| 19 | elif tags[i].endswith('O'): |
| 20 | if start != -1: |
| 21 | spans.append([start, i - 1]) |
| 22 | start = -1 |
| 23 | if start != -1: |
| 24 | spans.append([start, length - 1]) |
| 25 | return spans |
| 26 | |
| 27 | |
| 28 | class Instance(object): |