Returns the indices of tokens in the sentence where the given token tag equals the string. The string can contain a wildcard "*" at the end (this way "NN*" will match "NN" and "NNS"). The tag can be WORD, LEMMA, POS, CHUNK, PNP, RELATION, ROLE, ANCHOR or a custom word tag.
(self, value, tag=WORD)
| 891 | yield tuple([self.get(i, tag=tag) for tag in tags]) |
| 892 | |
| 893 | def indexof(self, value, tag=WORD): |
| 894 | """ Returns the indices of tokens in the sentence where the given token tag equals the string. |
| 895 | The string can contain a wildcard "*" at the end (this way "NN*" will match "NN" and "NNS"). |
| 896 | The tag can be WORD, LEMMA, POS, CHUNK, PNP, RELATION, ROLE, ANCHOR or a custom word tag. |
| 897 | For example: Sentence.indexof("VP", tag=CHUNK) |
| 898 | returns the indices of all the words that are part of a VP chunk. |
| 899 | """ |
| 900 | match = lambda a, b: a.endswith("*") and b.startswith(a[:-1]) or a==b |
| 901 | indices = [] |
| 902 | for i in range(len(self.words)): |
| 903 | if match(value, unicode(self.get(i, tag))): |
| 904 | indices.append(i) |
| 905 | return indices |
| 906 | |
| 907 | def slice(self, start, stop): |
| 908 | """ Returns a portion of the sentence from word start index to word stop index. |