How to draw the dependency tree from the CoreNLPClient parsing result?

752 views Asked by At

I wanted a dependency tree for the parsing result. I did the parsing using the code given on the GitHub repo of Stanford Core NLP.

I got the result as follows.[jupyter notebook result screenshot][1]

I have seen other answers mentioning graphviz and todoformat(), but these methods require semanticgraph format input(todoformat does, as far as I know). I have been able to convert the result of parsing to the following format, but it is a list of strings. [the new format of result][2] As I saw other result formats like this. What can I do to get the dependency tree graph? Is the result that I am getting be changed in a form that works for todoformat?

I am new to this. I would really appreciate your help. [1]: https://i.stack.imgur.com/qma9n.png [2]: https://i.stack.imgur.com/Xjhwh.png

Code:

text='(The allied forces of America and Britain attack Iraq'
with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner','parse','depparse','coref'], timeout=60000, memory='16G') as client:
    # submit the request to the server
    ann = client.annotate(text)
    sentence = ann.sentence[0]
    print('dependency parse of first sentence')
    dependency_parse = sentence.basicDependencies
    print(dependency_parse)

1

There are 1 answers

0
dman On
from stanza.server import CoreNLPClient
client = CoreNLPClient(
        annotators=['tokenize','ssplit','pos','lemma','ner', 'parse', 'openie','depparse','coref'],
        timeout=30000,
        memory='16G')

test ="A man and a woman came into the store."
matches = client.tregex(text, 'S')
print(matches['sentences'][0]['0']['match'])