Parses the chunk tag, role and relation id from the token relation tag. - VP => VP, [], [] - VP-1 => VP, [1], [None] - NP-SBJ-1 => NP, [1], [SBJ] - NP-OBJ-1*NP-OBJ-2 => NP, [1,2], [OBJ,OBJ] - NP-SBJ;NP-
(self, tag)
| 735 | return p[WORD], p[LEMMA], p[POS], p[CHUNK], p[ROLE], p[REL], p[PNP], p[ANCHOR], p[IOB], custom |
| 736 | |
| 737 | def _parse_relation(self, tag): |
| 738 | """ Parses the chunk tag, role and relation id from the token relation tag. |
| 739 | - VP => VP, [], [] |
| 740 | - VP-1 => VP, [1], [None] |
| 741 | - NP-SBJ-1 => NP, [1], [SBJ] |
| 742 | - NP-OBJ-1*NP-OBJ-2 => NP, [1,2], [OBJ,OBJ] |
| 743 | - NP-SBJ;NP-OBJ-1 => NP, [1,1], [SBJ,OBJ] |
| 744 | """ |
| 745 | chunk, relation, role = None, [], [] |
| 746 | for s in tag.split("*"): |
| 747 | if ";" in s: |
| 748 | id = ([None]+s.split("-"))[-1] # NP-SBJ;NP-OBJ-1 => 1 relates to both SBJ and OBJ. |
| 749 | id = id is not None and "-"+id or "" |
| 750 | s = s.replace(";", id+";") |
| 751 | s = s.split(";") |
| 752 | else: |
| 753 | s = [s] |
| 754 | for s in s: |
| 755 | s = s.split("-") |
| 756 | if len(s) == 1: chunk = s[0] |
| 757 | if len(s) == 2: chunk = s[0]; relation.append(s[1]); role.append(None) |
| 758 | if len(s) >= 3: chunk = s[0]; relation.append(s[2]); role.append(s[1]) |
| 759 | for i, x in enumerate(relation): |
| 760 | if x is not None: |
| 761 | try: relation[i] = int(x) |
| 762 | except: # Correct ADJP-PRD => ADJP, [PRD], [None] to ADJP, [None], [PRD]. |
| 763 | relation[i], role[i] = None, x |
| 764 | return chunk, relation, role |
| 765 | |
| 766 | def _do_word(self, word, lemma=None, type=None): |
| 767 | """ Adds a new Word to the sentence. |
no test coverage detected