dra*_*ght 1 java nlp stanford-nlp
我用google搜索了很多次,但我找不到答案.我仍然尝试使用类型化的依赖项,但这还不足以获得解决方案.我想用stanford core nlp v.3.0提取一个句子的折叠依赖.但我无法,每次我得到类型依赖示例和演示.如果有人帮助使用这个API在一个句子中使用折叠的依赖关系,我将非常感激.
我使用java和类型化的依赖项对我的项目来说还不够.任何建议和参考也都很好.
它非常简单.
在使用文本执行管道之后,导入以下包edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation;
用下面的脚本......
// create an empty Annotation just with desired text
Annotation document = new Annotation(text);
// run all Annotators on this text
pipeline.annotate(document);
//for each sentence you can get a list of collapsed dependencies as follows
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
SemanticGraph dependencies1 = sentence.get(CollapsedDependenciesAnnotation.class);
dep_type = "CollapsedDependenciesAnnotation";
System.out.println(dep_type+" ===>>");
System.out.println("Sentence: "+sentence.toString());
System.out.println("DEPENDENCIES: "+dependencies1.toList());
System.out.println("DEPENDENCIES SIZE: "+dependencies1.size());
Set<SemanticGraphEdge> edge_set1 = dependencies1.getEdgeSet();
int j=0;
for(SemanticGraphEdge edge : edge_set1){
j++;
System.out.println("------EDGE DEPENDENCY: "+j);
Iterator<SemanticGraphEdge> it = edge_set1.iterator();
IndexedWord dep = edge.getDependent();
String dependent = dep.word();
int dependent_index = dep.index();
IndexedWord gov = edge.getGovernor();
String governor = gov.word();
int governor_index = gov.index();
GrammaticalRelation relation = edge.getRelation();
System.out.println("No:"+j+" Relation: "+relation.toString()+" Dependent ID: "+dependent.index()+" Dependent: "+dependent.toString()+" Governor ID: "+governor.index()+" Governor: "+governor.toString());
}
Run Code Online (Sandbox Code Playgroud)
同样,您可以通过更改以下行来获得基本和ccprocessed dependecies.
SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
SemanticGraph dependencies2 = sentence.get(BasicDependenciesAnnotation.class);
Run Code Online (Sandbox Code Playgroud)
希望这能解决你的问题......
| 归档时间: |
|
| 查看次数: |
3837 次 |
| 最近记录: |