매우 간단합니다.
텍스트와 함께 파이프 라인을 실행 한 후 아래 패키지를 가져옵니다. 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());
}
아래 스크립트
는 ... 마찬가지로이이 문제를 해결할 수
SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
SemanticGraph dependencies2 = sentence.get(BasicDependenciesAnnotation.class);
희망 .. 아래 라인을 변경하여 기본 및 ccprocessed dependecies를 얻을 수 있습니다 ...
루트 요소를 제공하지 않습니다. 어떻게 구할 수 있니? – alienCoder
dependencies1.getFirstRoot() 메서드로 루트 요소를 얻을 수 있습니다 (여기 coreNLP 1.3.5를 사용하고 있습니다) –
고마워요. 그러나 나는 이미 그것을 풀었다. :) – alienCoder