2011-03-31 23 views
0

我正在使用nlp parser stanord。 我想從Collection tdl中提取一些像nsubj和更多的元素。 我的代碼是:如何從斯坦福nlp解析器的Collection tdl中獲取特定元素

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

但我的問題是我不知道如何比較elements.that我從收集得到。

非常感謝您的幫助!

回答

2

它是TypedDependency的集合,然後可以用所有常用的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); 
    } 
    }