2016-11-15 5 views
0

train.txtの感情モデルを訓練するデータは、このように見えるPTB形式です。別のtrain.txtを作成して他のドメインの感情モデルを訓練する

public static void main(String args[]){ 
    // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution 
    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize, ssplit,parse"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

    // read some text in the text variable 
    String text = "Yet the act is still charming here .";// Add your text here! 

    // create an empty Annotation just with the given text 
    Annotation annotation = new Annotation(text); 

    // run all Annotators on this text 

    pipeline.annotate(annotation); 

    // these are all the sentences in this document 
    // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types 
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 

    // int sentiment = 0; 
    for(CoreMap sentence: sentences) { 
     // traversing the words in the current sentence 
     Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); 
     System.out.println(tree); 
     // System.out.println(tree.yield()); 
     tree.pennPrint(System.out); 
     // Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); 
     // sentiment = RNNCoreAnnotations.getPredictedClass(tree); 
    } 

    // System.out.print(sentiment); 
} 

は次に、2つの質問が表示されます。本当の文があるべき

(3 (2 Yet) (3 (2 (2 the) (2 act)) (3 (4 (3 (2 is) (3 (2 still) (4 charming))) (2 here)) (2 .)))) 

Yet the act is still charming here. 

しかし、解析した後、私は別の構造を持って

(ROOT (S (CC Yet) (NP (DT the) (NN act)) (VP (VBZ is) (ADJP (RB still) (JJ charming)) (ADVP (RB here))) (. .))) 

は私のコードに従います私がmを使うとき自分の文章を使ってtrain.txtを作成します。

1.私のツリーはtrain.txtのツリーとは異なりますが、後者の数字は極性です。ツリーの構造が異なるようですが、2進化された解析ツリーを表示したい私は感情の番号を取得したら、この

((Yet) (((the) (act)) ((((is) ((still) (charming))) (here)) (.)))) 

ように私は、この例では、二値化パースツリーの各ノードですべてのフレーズを得るために、私自身のtrain.txt

2.Howを見るには、それを埋めることができます、私は得るべき

Yet 
the 
act 
the act 
is 
still 
charming 
still charming 
is still charming 
here 
is still charming here 
. 
is still charming here . 
the act is still charming here . 
Yet the act is still charming here. 

私がそれらを手に入れたら、私は人間の注釈者によってそれらに注釈を付けることができます。

実際に私はそれらをたくさん探していましたが、それらをうまく処理できなかったので、私はここに投稿します。便利な回答があれば分かります!

答えて

2

バイナリツリーを取得するためのプロパティにこれを追加します。

props.setProperty("parse.binaryTrees", "true"); 

文のバイナリツリーは、このようにアクセスされます:

:ここ

Tree tree = sentence.set(TreeCoreAnnotations.BinarizedTreeAnnotation.class); 

は私が書いたいくつかのサンプルコードです

import edu.stanford.nlp.ling.CoreAnnotations; 
import edu.stanford.nlp.ling.Word; 
import edu.stanford.nlp.pipeline.Annotation; 
import edu.stanford.nlp.pipeline.StanfordCoreNLP; 
import edu.stanford.nlp.trees.*; 

import java.util.ArrayList; 
import java.util.Properties; 

public class SubTreesExample { 

    public static void printSubTrees(Tree inputTree, String spacing) { 
     if (inputTree.isLeaf()) { 
      return; 
     } 
     ArrayList<Word> words = new ArrayList<Word>(); 
     for (Tree leaf : inputTree.getLeaves()) { 
      words.addAll(leaf.yieldWords()); 
     } 
     System.out.print(spacing+inputTree.label()+"\t"); 
     for (Word w : words) { 
      System.out.print(w.word()+ " "); 
     } 
     System.out.println(); 
     for (Tree subTree : inputTree.children()) { 
      printSubTrees(subTree, spacing + " "); 
     } 
    } 

    public static void main(String[] args) { 
     Properties props = new Properties(); 
     props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse"); 
     props.setProperty("parse.binaryTrees", "true"); 
     StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
     String text = "Yet the act is still charming here."; 
     Annotation annotation = new Annotation(text); 
     pipeline.annotate(annotation); 
     Tree sentenceTree = annotation.get(CoreAnnotations.SentencesAnnotation.class).get(0).get(
       TreeCoreAnnotations.BinarizedTreeAnnotation.class); 
     System.out.println("Penn tree:"); 
     sentenceTree.pennPrint(System.out); 
     System.out.println(); 
     System.out.println("Phrases:"); 
     printSubTrees(sentenceTree, ""); 

    } 
} 
+0

恐ろしい!中国の感情モデルを訓練したいのであれば、train.txtの文章はまだバイナリパースされている必要がありますか? @StanfordNLPHelp – ryh

関連する問題