[英]Stanford CoreNLP - How to setup another language
我正在尝试使用stanford库设置我的NLP解析器。 在我下载的网站上
现在,我面临一个问题,如何指示我的应用使用法语模型来分析我的句子。
我实际上有此代码(适用于英语句子)
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”之类的句子。
谢谢,Alexi
解决方法是在类路径中添加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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.