2016-10-16 67 views
0

我想使用斯坦福庫設置我的NLP分析器。 在網站上我下載斯坦福CoreNLP - 如何設置另一種語言

  • stanford-corenlp-full-2015-12-09.zip
  • 斯坦福 - 法國corenlp - 2016年1月14日 - models.jar

現在我面臨一個問題,我如何指示我的應用程序使用法語模式來分析我的句子。

其實我有這樣的代碼(英文句子工作)

String text = "I am very sad"; 
    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

    Annotation annotation = pipeline.process(text); 
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 
    for (CoreMap sentence : sentences) { 
     String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class); 
     System.out.println(sentiment + "\t" + sentence); 
    } 

有沒有一種方式,我想法國模式的代碼來表示(和嘗試解析像「卓悅,濟米的句子「appelle吉恩」。

感謝, 阿列克謝

回答

0

的解決方案是增加斯坦福法國.jar文件在classpath。

以下代碼正在工作

String sampleFrenchText = "Le chat mange la souris"; 
Annotation frenchAnnotation = new Annotation(sampleFrenchText); 
Properties frenchProperties = StringUtils.argsToProperties(new String[]{"-props", "StanfordCoreNLP-french.properties"}); 
StanfordCoreNLP pipeline = new StanfordCoreNLP(frenchProperties); 
pipeline.annotate(frenchAnnotation); 
for (CoreMap sentence : frenchAnnotation.get(CoreAnnotations.SentencesAnnotation.class)) { 
    Tree sentenceTree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); 
    System.out.println(sentenceTree); 
}