2013-10-17 5 views
1

나는 여러 번 인터넷 검색을했지만 답변을 찾을 수 없습니다. 그리고 여전히 형식화 된 종속성을 사용하여 시도했지만 솔루션을 얻는 것으로 충분하지 않았습니다. stanford core nlp v.3.0을 사용하여 문장의 붕괴 된 종속성을 추출하려고합니다. 하지만 난 할 수 없었고 매번 종속성 예제와 데모를 입력했습니다. 누군가가이 api를 사용하여 문장에서 붕괴 된 의존성을 얻는 것을 돕는다면 나는 매우 감사 할 것입니다.스탠포드 코어 nlp와 collpased 종속성

Java 및 형식화 된 종속성을 사용하여 프로젝트에 충분하지 않습니다. 모든 종류의 조언과 참고 자료도 좋습니다.

답변

1

다른 구문에서와 같이 문장을 구문 분석하여 주석을 얻은 다음에는 문장의 목록이 비어 있지 않은지 확인하기위한 추가 코드가 있습니다.

List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 
CoreMap sentence = (CoreMap) sentences.get(0); 
SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class); 
System.out.println(graph.toString("plain")); 
7

매우 간단합니다.

텍스트와 함께 파이프 라인을 실행 한 후 아래 패키지를 가져옵니다. 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를 얻을 수 있습니다 ...

+0

루트 요소를 제공하지 않습니다. 어떻게 구할 수 있니? – alienCoder

+0

dependencies1.getFirstRoot() 메서드로 루트 요소를 얻을 수 있습니다 (여기 coreNLP 1.3.5를 사용하고 있습니다) –

+0

고마워요. 그러나 나는 이미 그것을 풀었다. :) – alienCoder

관련 문제