Search code examples
stanford-nlpsentiment-analysis

How to get alignment between sentiment module and constituency parser in CoreNLP


I'm using Stanford coreNLP to both parse a text and get sentiment information. The two models give two Tree objects, but they are not related. Is there an easy way to navigate the two elements at the same time, so having an alignment between the two at a token level?


Solution

  • You can just use the sentiment tree as a model of both the grammatical parse and the sentiment — it's simply the original parse tree with extra annotations.

    Explanation: If you're using the Stanford CoreNLP pipeline, the sentiment annotator draws directly from the parse annotator to build its tree. The tree provided by the sentiment annotator is then just the same binarized parse tree with extra sentiment annotations.