Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MomentCoreAnnotations.AnnotatedTree无法解析为类型_Java_Twitter_Compiler Errors_Nlp_Stanford Nlp - Fatal编程技术网

Java MomentCoreAnnotations.AnnotatedTree无法解析为类型

Java MomentCoreAnnotations.AnnotatedTree无法解析为类型,java,twitter,compiler-errors,nlp,stanford-nlp,Java,Twitter,Compiler Errors,Nlp,Stanford Nlp,我正在尝试使用斯坦福核心NLP为实时推特获得情感分数。目前我收到了实时推文。但当我把它输入斯坦福大学核心NLP项目时,我得到了一个错误 import edu.stanford.nlp.ling.CoreAnnotations; import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations; import edu.stanford.nlp.pipeline.Annotation; import edu.stanford.nlp.pipeline.Sta

我正在尝试使用斯坦福核心NLP为实时推特获得情感分数。目前我收到了实时推文。但当我把它输入斯坦福大学核心NLP项目时,我得到了一个错误

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;

public class NLP {
    static StanfordCoreNLP pipeline;

    public static void init() {
        pipeline = new StanfordCoreNLP("MyPropFile.properties");
    }

    public static int findSentiment(String tweet) {

        int mainSentiment = 0;
        if (tweet != null && tweet.length() > 0) {
            int longest = 0;
            Annotation annotation = pipeline.process(tweet);
            for (CoreMap sentence : annotation
                    .get(CoreAnnotations.SentencesAnnotation.class)) {
                Tree tree = sentence
                        .get(SentimentCoreAnnotations.AnnotatedTree.class);
                int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
                String partText = sentence.toString();
                if (partText.length() > longest) {
                    mainSentiment = sentiment;
                    longest = partText.length();
                }

            }
        }
        return mainSentiment;
    }
}
我正在从类NLP外部调用init()和findEntity()函数

NLP.init();
System.out.println(status.getText() + " : " + NLP.findSentiment(status.getText()));
我的错误是:感伤CoreAnnotations.AnnotatedTree无法解析为类型

请尝试更改

Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);

Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);