簡體   English   中英

Stanford CoreNLP-如何設置另一種語言

[英]Stanford CoreNLP - How to setup another language

我正在嘗試使用stanford庫設置我的NLP解析器。 在我下載的網站上

  • stanford-corenlp-full-2015-12-09.zip
  • standford-french-corenlp-2016-01-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);
    }

有沒有一種方法可以在代碼中指出我想要法語模型(並嘗試解析“ Bonjour,je m'appelle Jean”之類的句子。

謝謝,Alexi

解決方法是在類路徑中添加standford french .jar文件。

以下代碼正在工作

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM