Stanford Parser - 使用德国模型罐

问题描述 投票:2回答:3

我想在coreNLP中使用stanford解析器。我已经有了这个例子:

http://stanfordnlp.github.io/CoreNLP/simple.html

但是:我需要德国模特。所以我下载了“stanford-german-2016-01-19-models.jar”。

但是如何设置此jar文件以供使用?我才发现:

LexicalizedParser lp = LexicalizedParser.loadModel("englishPCFG.ser.gz");

但我有一个德国模特的罐子,不是...... ser.gz。

有人可以帮忙吗?

java parsing stanford-nlp
3个回答
4
投票

以下是解析德语句子的示例代码:

import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.simple.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.util.PropertiesUtils;
import edu.stanford.nlp.util.StringUtils;

import java.util.*;

public class SimpleGermanExample {

    public static void main(String[] args) {
        String sampleGermanText = "...";
        Annotation germanAnnotation = new Annotation(sampleGermanText);
        Properties germanProperties = StringUtils.argsToProperties(
                new String[]{"-props", "StanfordCoreNLP-german.properties"});
        StanfordCoreNLP pipeline = new StanfordCoreNLP(germanProperties);
        pipeline.annotate(germanAnnotation);
        for (CoreMap sentence : germanAnnotation.get(CoreAnnotations.SentencesAnnotation.class)) {
            Tree sentenceTree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
            System.out.println(sentenceTree);
        }
    }
}

确保下载完整的工具包以使用此示例代码。

http://stanfordnlp.github.io/CoreNLP/

还要确保你的CLASSPATH中有德国模型罐。上面的代码将知道查看CLASSPATH中的所有jar并将该文件识别为在德语jar中。


1
投票

首先:这有效,谢谢!但是,对于所有这些注释器,我不需要这种复杂的方式。这就是为什么我想从简单的CoreNLP Api开始。那是我的代码:

import edu.stanford.nlp.simple.*;
import java.util.*;

public class Main {

public static void main(String[] args) {

    Sentence sent = new Sentence("Lucy is in the sky with diamonds.");
    List<String> posTags =  sent.posTags();
    List<String> words = sent.words();
    for (int i = 0; i < posTags.size(); i++) {
        System.out.println(words.get(i)+" "+posTags.get(i));
    }
  }
}

如何使用此示例获取德语属性文件?

或者另一种方式:如何在示例中仅获得带有pos标记的单词?


0
投票

德语等同于英语示例如下:

LexicalizedParser lp = LexicalizedParser.loadModel("germanPCFG.ser.gz");

提取最新的stanford-german-corenlp-2018-10-05-models.jar文件,你会在文件夹中找到它:stanford-german-corenlp-2018-10-05-models \ edu \ stanford \ nlp \ models \ lexparser

© www.soinside.com 2019 - 2024. All rights reserved.