From dbe26f5793f0ca4be5910ecca4f3b346e7579c2d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 3 Mar 2015 04:18:41 -0500 Subject: [PATCH] * Add children and subtree methods to Token, which are generators to assist parse-tree navigation. --- spacy/tokens.pyx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spacy/tokens.pyx b/spacy/tokens.pyx index 58513722f..55ebec770 100644 --- a/spacy/tokens.pyx +++ b/spacy/tokens.pyx @@ -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."""