2016-07-15 6 views
0

私は次のコードを試しましたが、コードは機能せず、出力はnullです。JavaでStanfordNLP Chinese segmentorを使用するには?

String text = "我爱北京天安门。"; 
StanfordCoreNLP pipeline = new StanfordCoreNLP(); 
Annotation annotation = pipeline.process(text); 
String result = annotation.get(CoreAnnotations.ChineseSegAnnotation.class); 
System.out.println(result); 

結果:正しくStanfordNLP中国セグメンタを使用する方法

... 
done [0.6 sec]. 
Using mention detector type: rule 
null 

答えて

0

いくつかのサンプルコード:

import edu.stanford.nlp.pipeline.*; 
import edu.stanford.nlp.ling.CoreAnnotations; 
import edu.stanford.nlp.ling.CoreLabel; 
import edu.stanford.nlp.util.StringUtils; 

import java.util.*; 

public class ChineseSegmenter { 

    public static void main (String[] args) { 
     // set the properties to the standard Chinese pipeline properties 
     Properties props = StringUtils.argsToProperties("-props", "StanfordCoreNLP-chinese.properties"); 
     StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
     String text = "..."; 
     Annotation annotation = new Annotation(text); 
     pipeline.annotate(annotation); 
     List<CoreLabel> tokens = annotation.get(CoreAnnotations.TokensAnnotation.class); 
     for (CoreLabel token : tokens) 
      System.out.println(token); 
    } 
} 

注:中国のモデルジャーがCLASSPATHにあることを確認します。そのファイルはここにあります:http://stanfordnlp.github.io/CoreNLP/download.html

上記のコードは、中国語分節化プログラムの実行後に作成されたトークンを出力します。

関連する問題