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:
JavaScript
x
5
1
def find_root(docu):
2
for token in docu:
3
if token.head is token:
4
return token
5
To then navigate the tree, the tokens have API to get through the children