【问题标题】:Stanford CoreNLP - How to setup another language斯坦福 CoreNLP - 如何设置另一种语言
【发布时间】:2016-10-16 08:36:43
【问题描述】:

我正在尝试使用 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”这样的句子。

谢谢, 亚历克斯

【问题讨论】:

    标签: java nlp stanford-nlp


    【解决方案1】:

    解决方法是在类路径中添加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);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      相关资源
      最近更新 更多