Nicolas Joseph Nicolas Joseph - 1 year ago 180
Python Question

How to get the dependency tree with SpaCy?

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.

There is information on how to navigate the tree.


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download