Dependencies 如何使用Stanford解析器API以数字方式查找单词出现的位置?

Dependencies 如何使用Stanford解析器API以数字方式查找单词出现的位置?,dependencies,stanford-nlp,Dependencies,Stanford Nlp,在类型依赖中,Stanford解析器还显示单词出现的位置,例如“love-2”。现在它显示“爱”在“2”的地方 现在,如何使用Stanford解析器API以编程方式找到word的位置?API中有什么介绍吗?你一定已经给了它一个句子,所以我不确定你为什么还不知道这个词在其中的位置 如果您试图理解为什么有多个依赖项涉及同一个单词,那么这是因为单词可以从一个依赖项传播到另一个依赖项 您可以执行以下操作。wordIndex就是您想要的 import edu.stanford.nlp.ling.CoreA

在类型依赖中,Stanford解析器还显示单词出现的位置,例如“love-2”。现在它显示“爱”在“2”的地方


现在,如何使用Stanford解析器API以编程方式找到word的位置?API中有什么介绍吗?

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


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

您可以执行以下操作。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);
导入edu.stanford.nlp.ling.CoreAnnotations.IndexAnnotation;
...
语法结构gs=gsf.newgrammaticstructure(parse);
List tdl=gs.typedDependenciescpProcessed();
TypedDependence td=tdl.get(0);
CoreLabel cl=td.dep().label();
int-wordIndex=cl.get(IndexAnnotation.class);

如果您想获取句子中某个特定单词的索引,您可以选择直接标记该单词,并将其放置为indexOf(token)+1
TypedDependence格式>>>缩写形式(调控器,从属)
如果要访问TypedDependence(或任何其他属性)中特定单词的索引,只需使用API
例如:
比如说,TypedPency td代表nsubj(love-2,I-1)

然后,您可以使用TreeGraphNode的方法来检索进一步的详细信息
例如,TreeGraphNode tgn=td.gov()


请随意参考javadoc

@Miles。。基本上,我想制作一些获取概念的模式,然后从这些概念中学习本体论…所以在制作模式的过程中,我还需要句子中的单词place…请帮助me@Miles.... 我只想要复合名词(最多3个或4个单词),所以这就是为什么我需要一个单词在句子中的位置。。。
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);
    td.gov();    //gives the governer (of type TreeGraphNode)
    td.dep();    //gives the dependent (")
    td.reln();   //gives the relation (of type GrammaticalRelation)
    tgn.index(); //yields the required index (for the above case, 2)