Question

How to create dependency graph (parse tree) for random sentences. Is there any predined grammer to parse english sentences using nltk.

Example:

I want to make a parse tree for the sentence

“A large company needs a sustainable business model.”   which should look like this.

enter image description here

Please suggest me how this can be done.

Was it helpful?

Solution

This question is a near-duplicate of 3125926. But I'll elaborate just a little on the answer given there.

I don't have personal experience with dependency parsing under NLTK, but according to the accepted answer, the integration with MaltParser is documented at http://nltk.googlecode.com/svn/trunk/doc/api/nltk.parse.malt.MaltParser-class.html

If for some reason MaltParser doesn't suit your needs, you might also take a look at MSTParser and the Stanford Parser. I think those three options are the best-known, and I expect one (or all) of them will work for you.

Note that the Stanford Parser includes routines to convert from constituency trees and between several of the standard dependency representations, so if you need a specific format, you might look at the format-conversion arguments to the edu.stanford.nlp.trees.EnglishGrammaticalStructure class.

e.g., to convert from constituency trees to basic dependencies:

java -cp stanford-parser.jar edu.stanford.nlp.trees.EnglishGrammaticalStructure -treeFile <input trees> -basic

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top