Created
February 21, 2019 19:09
-
-
Save mrdrozdov/e0d370fd13a0eb913b1c9d6ed748b9eb to your computer and use it in GitHub Desktop.
detect-seq.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mytree = """(ROOT | |
(S | |
(NP (NN Trouble)) | |
(VP | |
(VBD was) | |
(, ,) | |
(SBAR (S (NP (NN nobody)) (VP (VBD thought) (SBAR (S (NP (PRP they)) (VP (VBD looked) (ADJP (RB right))))))))) | |
(. .) | |
) | |
)""" | |
tree = nltk.tree.Tree(mytree) | |
def recursive_tree_search(tr): | |
assert len(tr) == 3 | |
seq = ['NP', 'VP', 'NP'] | |
for tt, ss in zip(tr, seq): | |
assert tt == ss | |
for node in tr: | |
print(node.label()) | |
recursive_tree_search(node) | |
recursive_tree_search(tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment