开发者

how to get specific elements from Collection tdl with stanford nlp parser

I am using the nlp parser stanord. I want to extract some elements like nsubj and more from Collection tdl. My code is:

TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
Collection tdl = gs.typedDependenciesCollapsed();

but my problem is I don't know how to compare the elements.that I get from the Collection.

Thanks a lot fo开发者_JAVA百科r helping!


It is a collection of TypedDependency and can then be examined or manipulated in all the usual Java ways. For example, this code prints out just the nsubj relations:

  Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(true);
  for (TypedDependency td : tdl) {
    if (td.reln().equals(EnglishGrammaticalRelations.NOMINAL_SUBJECT)) {
      System.out.println("Nominal Subj relation: " + td);
    }
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜