2015-01-09 9 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のデフォルト設定では、パーサーを実行する前に品詞(POS)タグャーが実行され、場合によっては異なる結果につながるPOS情報が組み込まれます。補題、NERとdcorefアノテーターは、すべてのPOSタグを必要とすることあなたので、しかし、

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

注:アノテーターのリストを変更することにより、POSタガーを無効にすることができ、同じ結果を得るために

注釈の順序を変更する必要があります。

CoreNLP demoもあり、コードと同じ出力を常に生成する必要があります。

+0

ありがとうございます。あなたが言及したアノテーターを使用して、私が言及した例のオンラインデモのものとまったく同じように、依存解析出力を得ることができたことを確認しました。私はこれを正解としています。 –

関連する問題