Java 如何获得多个句子的整体情感

Java 如何获得多个句子的整体情感,java,jar,stanford-nlp,sentiment-analysis,Java,Jar,Stanford Nlp,Sentiment Analysis,你如何发现多个句子/一个段落/一大段文字的聚合情感 下面的代码是基于github-Stanford CoreNLP测试和各种示例编写的,但我发现的所有内容都完成了情绪分析,只计算了单个句子的情绪。但我想要的是整个推特的情感,不管其中有多少句话 我唯一能想到的另一种方法是为情绪管道.main(String[])创建一个单独的线程,并将文本输入stdin,然后在sdout中收集整体情绪。我更希望能够使用我的代码使它更简单/更高效,但我没有发现任何东西 此外,我不想像大多数人那样对jar进行系统调用,

你如何发现多个句子/一个段落/一大段文字的聚合情感

下面的代码是基于github-Stanford CoreNLP测试和各种示例编写的,但我发现的所有内容都完成了情绪分析,只计算了单个句子的情绪。但我想要的是整个推特的情感,不管其中有多少句话

我唯一能想到的另一种方法是为
情绪管道.main(String[])
创建一个单独的线程,并将文本输入
stdin
,然后在
sdout
中收集整体情绪。我更希望能够使用我的代码使它更简单/更高效,但我没有发现任何东西

此外,我不想像大多数人那样对jar进行系统调用,因为我每天要发数百万条tweet。每次加载资源的开销太大

Annotation document = new Annotation(text);
pipeline.annotate(document);

List<CoreMap> sentences = document.get(SentencesAnnotation.class);
        String output;
        for (CoreMap sentence : sentences) {
            // traversing the words in the current sentence a CoreLabel is a CoreMap with additional token-specific methods
             output = "";
            for (CoreLabel token : sentence.get(TokensAnnotation.class)) {

                // this is the text of the token
                String word = token.get(TextAnnotation.class);

                // this is the Parts Of Speech tag of the token (noun, verb, adjective etc)
                // String pos = token.get(PartOfSpeechAnnotation.class);

                // this is the NER label of the token
                String ne = token.get(NamedEntityTagAnnotation.class);
                if (!ne.contentEquals("O")) {
                    output = output + (ne + " " + word + " ");
                }
            }

            //**************Sentiment Analysis 
            Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
             String sentiment = RNNCoreAnnotations.getPredictedClass(tree);
注释文档=新注释(文本);
管道注释(文件);
列出句子=document.get(SentencesAnnotation.class);
字符串输出;
for(CoreMap句子:句子){
//遍历当前句子中的单词时,CoreLabel是一个CoreMap,带有额外的特定于标记的方法
输出=”;
for(CoreLabel标记:句子.get(TokensAnnotation.class)){
//这是令牌的文本
String word=token.get(TextAnnotation.class);
//这是标记的词性标记(名词、动词、形容词等)
//String pos=token.get(speechannotation.class的一部分);
//这是令牌的NER标签
字符串ne=token.get(NamedEntityTagAnnotation.class);
如果(!ne.contentEquals(“O”)){
输出=输出+(ne+“”+word+“”);
}
}
//**************情绪分析
Tree-Tree=句子.get(momentCoreAnnotations.AnnotatedTree.class);
字符串情感=RNNCorenceNotations.getPredictedClass(树);

斯坦福corenlp中的情感分析工具包是在句子级数据集上训练的。如果你需要文档级情感引擎,我认为在文档上训练新模型是一个更好的选择。你也可以尝试一个接一个地处理句子,并使用一些棘手的方法(如平均值、最大值)如果你找不到答案的话,也可以考虑向官方发布,如果你还没有的话。我想把句子的情感平均化,但我不觉得这会给出准确的表达。我认为我的方法是调用<代码>感伤管。line.main(String[])在一个新的线程中,以某种方式在
stdin
中抛出字符串,并以这种方式获得情绪。上面的答案是正确的。简言之……它就是不正确。这很奇怪,你会认为他们需要一个全面的情绪分析。