我想在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。
任何人可以帮忙吗?
答案 0 :(得分: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 :(得分: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));
}
}
}
如何通过此示例获取德语prperties文件?
或者另一种方式:如何在示例中仅使用带有pos标记的单词?
答案 2 :(得分: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