我想在 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/