Jack Robson
Jack Robson

Reputation: 2302

Using SentimentPipeline in the Stanford Core NLP

I have setup a Maven project inside Eclipse.

Their is only class, src/main/java/App.java package 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!" );
    }
}

Then I add these dependencies and waited for Gradle to download the files:

<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>

When I run I get this error:

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

I'm looking at the documentation but can't make sense of it: https://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/sentiment/SentimentPipeline.html

What am I missing?

Upvotes: 0

Views: 283

Answers (1)

StanfordNLPHelp
StanfordNLPHelp

Reputation: 8739

You need this in your Maven dependencies:

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

Also you might just want to use the standard pipeline in your code:

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());

Upvotes: 1

Related Questions