在类型化依赖中,Stanford Parser还会显示单词出现的位置,例如"love-2“。现在它显示“爱”在"2“的地方。
nsubj(love-2, I-1)
poss(country-4, my-3)
dobj(love-2, country-4)现在,我如何使用斯坦福解析器API以编程方式找到单词的位置?API中有什么功能吗?
发布于 2012-07-22 14:40:48
如果想要获取句子中特定单词的索引,可以选择直接对其进行标记化,并将位置设置为indexOf(token)+1
TypedDependency format >>> abbreviated_form_reln (调控器,从属)
如果想要访问TypedDependency中特定单词的索引(或任何其他属性),只需使用
例如:
比方说,爱td表示nsubj ( TypedDepency -2,I-1)
td.gov(); //gives the governer (of type TreeGraphNode)
td.dep(); //gives the dependent (")
td.reln(); //gives the relation (of type GrammaticalRelation)然后,您可以使用TreeGraphNode的方法来检索更多详细信息
例如,TreeGraphNode tgn = td.gov();
tgn.index(); //yields the required index (for the above case, 2)请随意参考javadoc http://nlp.stanford.edu/nlp/javadoc/javanlp/。
发布于 2011-07-16 15:44:22
你肯定已经给了它一个句子,所以我不确定为什么你还不知道这个单词在其中的位置。
相反,如果您试图理解为什么有多个依赖关系提到同一个单词,那么这是因为单词可以从一个依赖关系传播到另一个依赖关系。
发布于 2011-08-26 11:47:24
您可以执行类似于下面的操作。wordIndex就是你想要的。
import edu.stanford.nlp.ling.CoreAnnotations.IndexAnnotation;
...
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
List<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
TypedDependency td = tdl.get(0);
CoreLabel cl = td.dep().label();
int wordIndex = cl.get(IndexAnnotation.class);https://stackoverflow.com/questions/6716009
复制相似问题