#java #nlp #stanford-nlp
#java #nlp #stanford-nlp
Вопрос:
Я пытаюсь настроить свой анализатор NLP, используя библиотеку stanford. На веб-сайте, который я скачал
- stanford-corenlp-full-2015-12-09.zip
- standford-french-corenlp-2016-01-14-models.jar
Теперь я столкнулся с проблемой, как я могу указать своему приложению использовать французскую модель для анализа моего предложения.
У меня на самом деле есть этот код (работающий для английских предложений)
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».
Спасибо, Алексей
Ответ №1:
Решение состоит в том, чтобы добавить файл standford french .jar в classpath .
Следующий код работает
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);
}