2015-01-09 1 views
5

어떻게 온라인 데모에서 볼 수 있듯이 stanford corenlp를 사용하여 프로그래밍 방식으로 동일한 종속성 구문을 구할 수 있습니까?의존성 분석 출력을 온라인 데모처럼 정확하게 얻으려면 어떻게해야합니까?

corenlp 패키지를 사용하여 다음 문장에 대한 종속성 구문 분석을 얻고 있습니다.

텍사스에서 2 번째 건강 관리 종사자가 에볼라에 양성 반응을 보인다고 당국이 밝혔습니다.

내가 프로그래밍 나는 스탠포드 corenlp에게 3.5.0 패키지를 사용하여 다음과 같은 출력을 얻을

  Properties props = new Properties(); 
      props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); 
      StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

      String text = "Second healthcare worker in Texas tests positive for Ebola , authorities say ."; // Add your text here! 
      Annotation document = new Annotation(text); 
      pipeline.annotate(document); 
      String[] myStringArray = {"SentencesAnnotation"}; 
      List<CoreMap> sentences = document.get(SentencesAnnotation.class); 
      for(CoreMap sentence: sentences) { 
       SemanticGraph dependencies = sentence.get(BasicDependenciesAnnotation.class); 
       IndexedWord root = dependencies.getFirstRoot(); 
       System.out.printf("root(ROOT-0, %s-%d)%n", root.word(), root.index()); 
       for (SemanticGraphEdge e : dependencies.edgeIterable()) { 
        System.out.printf ("%s(%s-%d, %s-%d)%n", e.getRelation().toString(), e.getGovernor().word(), e.getGovernor().index(), e.getDependent().word(), e.getDependent().index()); 
       } 
      } 

    } 

아래의 코드를 사용하여 구문 분석을 얻으려고.

root(ROOT-0, worker-3) 
amod(worker-3, Second-1) 
nn(worker-3, healthcare-2) 
prep(worker-3, in-4) 
amod(worker-3, positive-7) 
dep(worker-3, say-12) 
pobj(in-4, tests-6) 
nn(tests-6, Texas-5) 
prep(positive-7, for-8) 
pobj(for-8, ebola-9) 
nsubj(say-12, authorities-11) 

온라인 데모에서는 루트로 말하면서 구문 분석의 단어 사이에 ccomp와 같은 다른 관계가있는 다른 대답을 제공합니다.

amod(worker-3, Second-1) 
nn(worker-3, healthcare-2) 
nsubj(tests-6, worker-3) 
prep(worker-3, in-4) 
pobj(in-4, Texas-5) 
ccomp(say-12, tests-6) 
acomp(tests-6, positive-7) 
prep(positive-7, for-8) 
pobj(for-8, Ebola-9) 
nsubj(say-12, authorities-11) 
root(ROOT-0, say-12) 

출력물을 온라인 데모와 일치하도록 어떻게 해결합니까?

+0

나는 파서가 결정 론적이라고 믿는다. 온라인 데모와 동일한 버전의 CoreNLP를 실행하고 동일한 모델을 사용하고 있는지 확인하십시오. 스탠포드 팀에 이메일을 보내야하고 웹 사이트에서 실행중인 버전/모델을 물어볼 수도 있습니다. 실제로 언급했는지는 확실하지 않습니다. – mbatchkarov

답변

9

출력이 다른 이유는 parser demo을 사용하면 독립 실행 형 파서 배포가 사용되고 코드가 전체 CoreNLP 배포를 사용하기 때문입니다. 두 모델 모두 동일한 파서 및 동일한 모델을 사용하지만 CoreNLP의 기본 구성에서는 파서를 실행하기 전에 PAL (part-of-speech) 태그 지정자를 실행하고 파서는 POS 정보를 통합하여 어떤 경우에는 다른 결과를 초래할 수 있습니다. 보조 정리 넬과 dcoref 주석 자 모든 POS 태그를 필요로하는 당신, 그래서, 그러나,

props.put("annotators", "tokenize, ssplit, parse, lemma, ner, dcoref"); 

참고 : 주석 자 목록을 변경하여 POS 술래을 해제 할 수 있습니다 동일한 결과를 얻기 위해

주석 자의 순서를 변경해야합니다.

항상 코드와 동일한 출력을 생성해야하는 CoreNLP demo도 있습니다.

+0

설명해 주셔서 감사합니다. 필자가 언급 한 주석자를 사용하여 필자가 언급 한 예제의 온라인 데모 에서처럼 종속성 구문 분석 출력을 정확히 얻을 수 있다는 것을 확인했습니다. 나는 이것을 올바른 답으로 표시하고있다. –

관련 문제