java - Stanford Parser - 使用德语模型 jar

标签 java parsing stanford-nlp

我想在 coreNLP 中使用斯坦福解析器。 我已经让这个例子工作了:

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

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

但是我该如何设置这个 jar 文件以供使用呢? 我只发现:

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

但我有一个装有 germn 模型的 jar ,而不是 ...ser.gz。

任何人都可以帮忙吗?

最佳答案

下面是一些解析德语句子的示例代码:

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 中有德国模型 jar。上面的代码将知道查看 CLASSPATH 中的所有 jar 并将该文件识别为位于德国 jar 中。

关于java - Stanford Parser - 使用德语模型 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37105266/

相关文章:

java - 等到文本出现在文本字段中

java - 检测鼠标点击屏幕上的任意位置

java - 按下按钮时执行的 Action

java - 解析JSON多个对象

stanford-nlp - 句子级到文档级的情感分析。分析新闻

java - 从 HttpClient for Android 获取网页结果

parsing - 如何从头开始编写递归下降解析器?

解析 Get-Counter 数据以获取值

java - 具有真正有值(value)特征的斯坦福分类器

stanford-nlp - 在 StanfordCoreNLPServer 输出中同时具有 NER 和 RegexNER 标签?