* Add children and subtree methods to Token, which are generators to assist parse-tree navigation.

This commit is contained in:
Matthew Honnibal 2015-03-03 04:18:41 -05:00
parent 827a2337b0
commit dbe26f5793
1 changed files with 13 additions and 0 deletions

View File

@ -386,6 +386,19 @@ cdef class Token:
else:
ptr -= 1
property children:
def __get__(self):
yield from self.lefts
yield from self.rights
property subtree:
def __get__(self):
for word in self.lefts:
yield from word.subtree
yield self
for word in self.rights:
yield from word.subtree
property head:
def __get__(self):
"""The token predicted by the parser to be the head of the current token."""