如何使用stanford nlp解析器从集合tdl获取特定元素

如何使用stanford nlp解析器从集合tdl获取特定元素,nlp,stanford-nlp,Nlp,Stanford Nlp,我使用的是nlp解析器stanord。 我想从Collectiontdl中提取一些元素,如nsubj等。 我的代码是: TreebankLanguagePack tlp = new PennTreebankLanguagePack(); GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);

我使用的是
nlp解析器stanord
。 我想从
Collection
tdl中提取一些元素,如nsubj等。 我的代码是:

TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
Collection tdl = gs.typedDependenciesCollapsed();
但我的问题是我不知道如何比较我从收藏中得到的元素


非常感谢你的帮助

它是TypedDependence的集合,然后可以用所有常用的Java方法检查或操作它。例如,此代码仅打印nsubj关系:

  Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed(true);
  for (TypedDependency td : tdl) {
    if (td.reln().equals(EnglishGrammaticalRelations.NOMINAL_SUBJECT)) {
      System.out.println("Nominal Subj relation: " + td);
    }
  }
Collection tdl=gs.typedDependenciescpProcessed(true);
用于(类型依赖性td:tdl){
if(td.reln().equals(英语语法关系.名词性主语)){
System.out.println(“名义主体关系:+td”);
}
}