Использование SentimentPipeline в Stanford Core NLP - PullRequest
0 голосов
/ 21 ноября 2018

Я настроил проект Maven внутри Eclipse.

Это только класс, пакет src / main / java / App.java com.nlptools.corenlp;

import java.util.List;

import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.sentiment.SentimentPipeline;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;

class App 
{
    public static void main( String[] args )
    {
        List<Annotation> list = SentimentPipeline.getAnnotations(new StanfordCoreNLP(), null, "foo.txt", false);
        for (Annotation item : list) {
            System.out.println(item.toString());
        }
        System.out.println( "Hello World!" );
    }
}

Тогда ядобавьте эти зависимости и подождите, пока Gradle загрузит файлы:

<dependency>
<groupId> edu.stanford.nlp </groupId>
<artifactId> stanford-corenlp </artifactId>
<version> 3.9.2</version>
</dependency>
<dependency>
<groupId> edu.stanford.nlp </groupId>
<artifactId> stanford-corenlp </artifactId>
<version> 3.9.2</version>
<classifier> models-english </classifier>
</dependency>

При запуске я получаю эту ошибку:

Couldn't read TokensRegexNER from edu/stanford/nlp/models/kbp/english/gazetteers/regexner_caseless.tab

Я смотрю документацию, но не могу сделатьсмысл этого: https://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/sentiment/SentimentPipeline.html

Чего мне не хватает?

1 Ответ

0 голосов
/ 21 ноября 2018

Это необходимо в зависимости от Maven:

<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.9.2</version>
    <classifier>models</classifier>
</dependency>

Также вы можете просто захотеть использовать стандартный конвейер в вашем коде:

Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
CoreDocument exampleDocument = new CoreDocument("I loved the movie!");
pipeline.annotate(exampleDocument);
System.out.println(exampleDocument.sentences().get(0).sentiment());
...