Lynten / stanford-corenlp

Python wrapper for Stanford CoreNLP.
MIT License
919 stars 200 forks source link

Depth of Constituency Tree #59

Open amiref opened 6 years ago

amiref commented 6 years ago

Is there any way to find the depth of constituency tree?

Lnna commented 5 years ago

maybe you can use nltk.corpus.BracketParseCorpusReader, nltk.tree ,this two library, to get what you want. just like this: `from nltk.tree import Tree

from stanfordcorenlp.corenlp import StanfordCoreNLP

nlp=StanfordCoreNLP(r'/home/.../Documents/postag/stanford-corenlp-full-2016-10-31/', lang='zh')

parser=nlp.parse('这样的言判也得到了证实,被害人的脑部有两处重击,脑浆外溢。')

print(parser)

tree=Tree.fromstring(parser.str())

print(tree.height())

nlp.close()`

class Tree has many other methods about the tree structure. hope that can help you.