I'm trying to use breadth_first to search for (first) a specific leaf word and then a certain label (NP) in a ParentedTree. I'd really rather not implement it myself if there's already a method for it. This is what I've tried (including how I made the tree, in case that's where I messed up):
import nltk
from nltk.util import breadth_first
grammar = nltk.data.load("/path/to/grammar.cfg")
parser = nltk.parse.EarleyChartParser(grammar)
sent = "They are happy people"
parse1 = list(parser.parse(sent.split()))
tree1 = nltk.tree.ParentedTree.convert(parse1[0])
bf = breadth_first(tree1)
This gives me a generator object, but I'm not sure how to use it to search for what I want (the pronoun "They"). I tried doing a simple "for node in bf: print(node)" and it printed every single letter of the string on a line by itself, repeating forever, until I had to close the window.
I've read the docs and I've done a lot of googling, but I can't find an example of it actually being used for searching. What am I doing wrong?