【问题标题】:Using SentimentPipeline in the Stanford Core NLP在斯坦福 Corenlp 中使用 Sentiment Pipeline
【发布时间】:2018-11-21 15:22:56
【问题描述】:

我已经在 Eclipse 中设置了一个 Maven 项目。

它们是唯一的类,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

我错过了什么?

【问题讨论】:

    标签: java stanford-nlp


    【解决方案1】:

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

    【讨论】:

    • 管道变量是什么类型,如何初始化?
    • 糟糕,我将其添加进去。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多