我如何从斯坦福的情绪分析中检索积极性的 5 个值?

How would I retrieve the 5 values of positivity from Stanford's Sentiment Analysis?

我希望传递要解析的字符串和 return 评分最高的数字 (1-5)。

例如,这将 return 2:

我假设您将 Stanford CoreNLP 管道与 sentiment annotator 一起使用。

这个注释器在每个句子上设置一个注释,称为 SentimentCoreAnnotations.ClassName。只需检索此值:(未经测试的示例)

Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, parse, sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

// read some text in the text variable
String text = ... // Add your text here!

// create an empty Annotation just with the given text
Annotation document = new Annotation(text);

// run all Annotators on this text
pipeline.annotate(document);

// these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = document.get(SentencesAnnotation.class);

for (CoreMap sentence : sentences) {
  String sentimentLabel = sentence.get(SentimentCoreAnnotations.ClassName.class);

  // ...
}