Returns a list of Word objects that match the given group. With chunked=True, returns a list of Word + Chunk objects - see Match.constituents(). A group consists of consecutive constraints wrapped in { }, e.g., search("{JJ JJ} NN", Sentence(parse("big black cat")
(self, index, chunked=False)
| 982 | return a |
| 983 | |
| 984 | def group(self, index, chunked=False): |
| 985 | """ Returns a list of Word objects that match the given group. |
| 986 | With chunked=True, returns a list of Word + Chunk objects - see Match.constituents(). |
| 987 | A group consists of consecutive constraints wrapped in { }, e.g., |
| 988 | search("{JJ JJ} NN", Sentence(parse("big black cat"))).group(1) => big black. |
| 989 | """ |
| 990 | if index < 0 or index > len(self.pattern.groups): |
| 991 | raise IndexError, "no such group" |
| 992 | if index > 0 and index <= len(self.pattern.groups): |
| 993 | g = self.pattern.groups[index-1] |
| 994 | if index == 0: |
| 995 | g = self.pattern.sequence |
| 996 | if chunked is True: |
| 997 | return Group(self, self.constituents(constraint=[self.pattern.sequence.index(x) for x in g])) |
| 998 | return Group(self, [w for w in self.words if self.constraint(w) in g]) |
| 999 | |
| 1000 | @property |
| 1001 | def string(self): |