2017-07-19 14 views
2

法案が上院議員ブラウンバックによって提出された、カンザスCoreNLPスタンフォード依存フォーマットポートと移民の

の 共和党

上記の文章から、私は次の型指定された依存関係を取得するために探しています:

nsubjpass(submitted, Bills) 
auxpass(submitted, were) 
agent(submitted, Brownback) 
nn(Brownback, Senator) 
appos(Brownback, Republican) 
prep_of(Republican, Kansas) 
prep_on(Bills, ports) 
conj_and(ports, immigration) 
prep_on(Bills, immigration) 

このは、Stanford Dependenciesのドキュメントの表1、図1に示すようににする必要があります。私は次の依存関係メイク(コード出力する)を達成することができた以下のコード使用

root(ROOT-0, submitted-7) 
nmod:on(Bills-1, ports-3) 
nmod:on(Bills-1, immigration-5) 
case(ports-3, on-2) 
cc(ports-3, and-4) 
conj:and(ports-3, immigration-5) 
nsubjpass(submitted-7, Bills-1) 
auxpass(submitted-7, were-6) 
nmod:agent(submitted-7, Brownback-10) 
case(Brownback-10, by-8) 
compound(Brownback-10, Senator-9) 
punct(Brownback-10, ,-11) 
appos(Brownback-10, Republican-12) 
nmod:of(Republican-12, Kansas-14) 
case(Kansas-14, of-13) 

質問の - どのように私は上記の所望の出力を達成していますか?

コード

public void processTestCoreNLP() { 
    String text = "Bills on ports and immigration were submitted " + 
      "by Senator Brownback, Republican of Kansas"; 

    Annotation annotation = new Annotation(text); 
    Properties properties = PropertiesUtils.asProperties(
      "annotators", "tokenize,ssplit,pos,lemma,depparse" 
    ); 

    AnnotationPipeline pipeline = new StanfordCoreNLP(properties); 

    pipeline.annotate(annotation); 

    for (CoreMap sentence : annotation.get(SentencesAnnotation.class)) { 
     SemanticGraph sg = sentence.get(EnhancedPlusPlusDependenciesAnnotation.class); 
     Collection<TypedDependency> dependencies = sg.typedDependencies(); 
     for (TypedDependency td : dependencies) { 
      System.out.println(td); 
     } 
    } 
} 
+0

をコードは、実際に、その後、何を印刷しますか? – errantlinguist

+0

あいまいさに対する謝罪。このコードは、依存関係の2番目のブロックを出力します。私はより明確に編集しました。 – gimg1

答えて

1

NN依存性パーサーを介してCC処理済みの縮退スタンフォード依存関係(SD)を取得する場合は、CoreNLPの小さなバグを回避するためにプロパティを設定する必要があります。しかし

は、スタンフォード依存コードを維持し、我々はもはやをしていることに注意していないしてください、あなたはSDを使用するために本当に良い理由がある場合を除き、当社は、新しいプロジェクトのためのユニバーサル依存関係を使用してお勧めします。 UD表現の詳細については、Universal Dependencies (UD) documentationSchuster and Manning (2016)をご覧ください。 CCprocessedを入手するには

とSD表現を崩壊し、次のようにdepparse.languageプロパティを設定します。

public void processTestCoreNLP() { 
    String text = "Bills on ports and immigration were submitted " + 
     "by Senator Brownback, Republican of Kansas"; 

    Annotation annotation = new Annotation(text); 
    Properties properties = PropertiesUtils.asProperties(
     "annotators", "tokenize,ssplit,pos,lemma,depparse"); 

    properties.setProperty("depparse.language", "English") 

    AnnotationPipeline pipeline = new StanfordCoreNLP(properties); 

    pipeline.annotate(annotation); 

    for (CoreMap sentence : annotation.get(SentencesAnnotation.class)) { 
    SemanticGraph sg = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class); 
    Collection<TypedDependency> dependencies = sg.typedDependencies(); 
    for (TypedDependency td : dependencies) { 
     System.out.println(td); 
    } 
    } 
} 
+0

ありがとうSebastien。これは私がずっと探していたものです。私は郵便配達人を捜したが、この郵便物を渡って来なかった。 – gimg1

2

CoreNLPは最近Universal Dependenciesに古いStanford dependencies形式(上の例では形式)から切り替えます。私の最初の勧告は可能な限り新しいフォーマットを使用することです。パーサー上での継続的な開発は、普遍的な依存関係を使用して行われ、フォーマットは多くの点で従来のフォーマットとモジュロ化されている(例えば、prep->nmod)。

ただし、古い従属形式を取り除きたい場合は、CollapsedCCProcessedDependenciesAnnotation注釈を使用することができます。

+0

この回答に感謝します。私の調査では、これは私が真実だと思ったものですが、 'CollapsedCCProcessedDependenciesAnnotation'を使用しても同じユニバーサルスタイルの依存関係が得られます。つまり、' prep'でなければ 'nmod'が表示されます。退縮を 'prep'に強制的に戻すためにとにかくありますか? – gimg1

+0

私はもう少し行き、 'nmod'ではなく' prep'を出力させました。私が今注目するのは、彼らは 'prep_on'に縮小されていないということです。代わりに私は 'prep(Bills、on)'と 'pobj(on、immigration)'の2つの依存関係を持っています。これを 'prep_on(Bills、immigration)'に減らすにはどうすればいいですか?私はそれを自分で行わなければならないのですか、それとも方法がありますか? – gimg1

+1

私はここで私の奥深さから抜け出していますが、談合を始める場所は「文法的構造」でしょう。しかし、Stanford Dependenciesの表現が腐ってしまいました(例えば、 'CollapsedCCProcessedDependenciesAnnotation'は確かに古いフォーマットを返すことになっています)。 –

関連する問題