Java MomentCoreAnnotations.AnnotatedTree无法解析为类型
我正在尝试使用斯坦福核心NLP为实时推特获得情感分数。目前我收到了实时推文。但当我把它输入斯坦福大学核心NLP项目时,我得到了一个错误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
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);