2016-11-08 8 views
3

私の目的は、テキストからそれに接続されたNE(Person)と動詞を抽出することです。たとえば、私はこの文章を持っています:テキストから名前付きエンティティ+動詞を抽出するには

ダンブルドーは通りを回って戻ってきました。ハリー・ポッターは目を覚ますことなく毛布の中を転がした。

理想的な結果として、私は

ダンブルドアが歩いなってもらう必要があります。ハリー・ポッターが転がした

私はスタンフォードNERを使用して人を見つけてマークし、NEを含まないすべての文を削除します。だから、最終的に私は文字の名前を持つ文章のみからなる「純粋な」テキストを持っています。 その後、スタンフォードの依存関係を使用します。その結果、私はこのようなスムーズさを得ました。(CONLLUの出力形式):

1 Dumbledore _ _ NN _ 2 nsubj _ _ 
2 turned _ _ VBD _ 0 root _ _ 
3 and _ _ CC _ 2 cc _ _ 
4 walked _ _ VBD _ 2 conj _ _ 
5 back _ _ RB _ 4 advmod _ _ 
6 down _ _ IN _ 8 case _ _ 
7 the _ _ DT _ 8 det _ _ 
8 street _ _ NN _ 4 nmod _ _ 
9 . _ _ . _ 2 punct _ _ 

1 Harry _ _ NNP _ 2 compound _ _ 
2 Potter _ _ NNP _ 3 nsubj _ _ 
3 rolled _ _ VBD _ 0 root _ _ 
4 over _ _ IN _ 3 compound:prt _ _ 
5 inside _ _ IN _ 7 case _ _ 
6 his _ _ PRP$ _ 7 nmod:poss _ _ 
7 blankets _ _ NNS _ 3 nmod _ _ 
8 without _ _ IN _ 9 mark _ _ 
9 waking _ _ VBG _ 3 advcl _ _ 
10 up _ _ RP _ 9 compound:prt _ _ 
11 . _ _ . _ 3 punct _ _ 

これですべての問題が発生します。私は人と動詞を知っていますが、この形式からそれをどのように抽出するのか分かりません。 私はこのようにすることができます:テーブル内のNN/NNPを見つけて、その「親」を見つけて、そのすべての「子」単語を抽出します。理論的にはうまくいくはずです。理論的に。

誰かが他のアイデアを思いついて、その人からその人の行動を得る方法がありますか?それともそれ以上の合理的な方法があれば?

私は非常に助けに感謝します!ここで

答えて

1

はあなたの問題を支援するいくつかのサンプルコードです:

import java.io.*; 
import java.util.*; 
import edu.stanford.nlp.ling.*; 
import edu.stanford.nlp.pipeline.*; 
import edu.stanford.nlp.semgraph.*; 
import edu.stanford.nlp.util.*; 



public class NERAndVerbExample { 

    public static void main(String[] args) throws IOException { 
    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,depparse,entitymentions"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
    String text = "John Smith went to the store."; 
    Annotation annotation = new Annotation(text); 
    pipeline.annotate(annotation); 
    System.out.println("---"); 
    System.out.println("text: " + text); 
    System.out.println(""); 
    System.out.println("dependency edges:"); 
    for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { 
     SemanticGraph sg = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class); 
     for (SemanticGraphEdge sge : sg.edgeListSorted()) { 
     System.out.println(
       sge.getGovernor().word() + "," + sge.getGovernor().index() + "," + sge.getGovernor().tag() + "," + 
         sge.getGovernor().ner() 
         + " - " + sge.getRelation().getLongName() 
         + " -> " 
         + sge.getDependent().word() + "," + 
         +sge.getDependent().index() + "," + sge.getDependent().tag() + "," + sge.getDependent().ner()); 
     } 
     System.out.println(); 
     System.out.println("entity mentions:"); 
     for (CoreMap entityMention : sentence.get(CoreAnnotations.MentionsAnnotation.class)) { 
     int lastTokenIndex = entityMention.get(CoreAnnotations.TokensAnnotation.class).size()-1; 
     System.out.println(entityMention.get(CoreAnnotations.TextAnnotation.class) + 
       "\t" + 
       entityMention.get(CoreAnnotations.TokensAnnotation.class) 
         .get(lastTokenIndex).get(CoreAnnotations.IndexAnnotation.class) + "\t" + 
       entityMention.get(CoreAnnotations.NamedEntityTagAnnotation.class)); 
     } 
    } 
    } 
} 

私はエンティティに言及作業を支援するためにスタンフォードCoreNLP 3.8.0にいくつかのシンタックスシュガーを追加するために願っています。

このコードを少し説明すると、基本的にエンティティメントの注釈子は、同じNERタグを使ってトークンをグループ化してグループ化します。したがって、 "John Smith"はエンティティの言及としてマークされます。

依存グラフを調べると、各単語のインデックスを取得できます。

同様に、エンティティの言及のためのトークンのリストにアクセスすると、エンティティの言及の各単語のインデックスを見つけることもできます。

もう少しコードを追加することで、それらを一緒にリンクし、要求していたエンティティ言葉動詞ペアを作成できます。

現行のコードで分かるように、エンティティの言及にアクセスするのは非常に面倒ですので、3.8.0で改善するようにします。

+0

ああ、ありがとう! ちょうど1つの問題 - 私はあなたのコードをコンパイルして、それがどのように動作するか見ることができません。これは、コンパイル情報を '解析中にファイルの終わりに達しました'と示します。たぶん私は間違ったことをしているだけでしょうか? エンティティの言及と索引付けについて読むことができるリソースはありますか? ところで、私はSemRegexについて読んだことがあります。私の意見では、このツールはNE +動詞ペアの検索にも役立ちます。本当にそうですか? とにかく、ありがとう! –

関連する問題