Search code examples
parsingnlpstanford-nlp

How to use StanfordNLP Python package to do dependency parsing?


I am trying to use the new NN-based parser at here to find all adjective phrases in a sentence (e.g., good and extremely good in The weather is extremely good), however, it's very lack of documentation and I could not get it working. My current code is

import stanfordnlp
nlp = stanfordnlp.Pipeline()
doc = nlp("The weather is extremely good")
doc.sentences[0].print_dependencies()

which gives me

('The', '2', 'det')
('weather', '5', 'nsubj')
('is', '5', 'cop')
('extremely', '5', 'advmod')
('good', '0', 'root')

But it is not clear how to extract the information I need, as this does not seem to be a tree structure. Does anyone have an idea?


Solution

  • At this time there is not Python support for constituency parses which is what you want. This is just returning the dependency parses (a different type of parse).

    You can use stanfordnlp to communicate with a Java server and get constituency parses in that manner.

    There is example code here for accessing the constituency parses:

    https://stanfordnlp.github.io/stanfordnlp/corenlp_client.html