0

在类型依赖中,Stanford Parser 还显示了单词出现的地方,例如“love-2”。现在它表明“爱”在“2”的地方。

nsubj(love-2, I-1)
poss(country-4, my-3)
dobj(love-2, country-4)

现在,如何使用斯坦福解析器 API 以编程方式找到单词的位置?API中是否有任何功能?

4

3 回答 3

1

如果要获取句子中特定单词的索引,可以选择直接对其进行分词,获取位置为 indexOf(token)+1
TypedDependency 格式 >>> abbreviated_form_reln (governor,dependent)
如果要访问索引TypedDependency(或任何其他属性)中的特定单词,只需使用 API
例如:
说,TypedDepency td 表示 nsubj (love-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/

于 2012-07-22T06:40:48.430 回答
0

你一定已经给了它一个句子,所以我不确定你为什么还不知道这个词在其中的位置。

如果您试图理解为什么您有多个依赖项提到同一个词,那么这是因为词可以从一个依赖项传播到另一个依赖项。

于 2011-07-16T07:44:21.617 回答
0

你做类似下面的事情。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);
于 2011-08-26T03:47:24.377 回答