I have been trying to find how to get the dependency tree with spaCy but I can’t find anything on how to get the tree, only on how to navigate the tree.
Advertisement
Answer
It turns out, the tree is available through the tokens in a document.
Would you want to find the root of the tree, you can just go though the document:
def find_root(docu): for token in docu: if token.head is token: return token
To then navigate the tree, the tokens have API to get through the children