Adds a new Chunk to the sentence, or adds the last word to the previous chunk. The word is attached to the previous chunk if both type and relation match, and if the word's chunk tag does not start with "B-" (i.e., iob != BEGIN). Punctuation marks (or other "O" c
(self, type, role=None, relation=None, iob=None)
| 773 | self.words.append(Word(self, word, lemma, type, index=len(self.words))) |
| 774 | |
| 775 | def _do_chunk(self, type, role=None, relation=None, iob=None): |
| 776 | """ Adds a new Chunk to the sentence, or adds the last word to the previous chunk. |
| 777 | The word is attached to the previous chunk if both type and relation match, |
| 778 | and if the word's chunk tag does not start with "B-" (i.e., iob != BEGIN). |
| 779 | Punctuation marks (or other "O" chunk tags) are not chunked. |
| 780 | """ |
| 781 | O = (None, OUTSIDE) |
| 782 | if type in O and relation in O and role in O: |
| 783 | return |
| 784 | if len(self.chunks) > 0 \ |
| 785 | and self.chunks[-1].type == type \ |
| 786 | and self._relation == (relation, role) \ |
| 787 | and not iob == BEGIN \ |
| 788 | and not self.words[-2].chunk is None: # "As for me, I'm off" => "me" & "I" are different chunks |
| 789 | self.chunks[-1].append(self.words[-1]) |
| 790 | else: |
| 791 | ch = Chunk(self, [self.words[-1]], type, role, relation) |
| 792 | self.chunks.append(ch) |
| 793 | self._relation = (relation, role) |
| 794 | |
| 795 | def _do_relation(self): |
| 796 | """ Attaches subjects, objects and verbs. |