- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我输入句子时:
"So excited to be back! We're here to reconnect with & meet new innovators at ghc16"
那么返回的情绪是负面的。无法理解发生这种情况的原因。语句为正,但仍返回负值。
class SentimentAnalyzer {
public TweetWithSentiment findSentiment(String line) {
if(line == null || line.isEmpty()) {
throw new IllegalArgumentException("The line must not be null or empty.");
}
Annotation annotation = processLine(line);
int mainSentiment = findMainSentiment(annotation);
if(mainSentiment < 0 || mainSentiment > 4) { //You should avoid magic numbers like 2 or 4 try to create a constant that will provide a description why 2
return null; //You should avoid null returns
}
TweetWithSentiment tweetWithSentiment = new TweetWithSentiment(line, toCss(mainSentiment));
return tweetWithSentiment;
}
private String toCss(int sentiment) {
switch (sentiment) {
case 0:
return "very negative";
case 1:
return "negative";
case 2:
return "neutral";
case 3:
return "positive";
case 4:
return "very positive";
default:
return "default";
}
}
private int findMainSentiment(Annotation annotation) {
int mainSentiment = Integer.MIN_VALUE;
int longest = Integer.MIN_VALUE;
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
String word = token.get(CoreAnnotations.TextAnnotation.class);
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);
System.out.println("word: " + word);
System.out.println("pos: " + pos);
System.out.println("ne: " + ne);
System.out.println("Lemmas: " + lemma);
}
int sentenceLength = String.valueOf(sentence).length();
if(sentenceLength > longest) {
Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
mainSentiment = RNNCoreAnnotations.getPredictedClass(tree);
longest = sentenceLength ;
}
}
return mainSentiment;
}
private Annotation processLine(String line) {
StanfordCoreNLP pipeline = createPieline();
return pipeline.process(line);
}
private StanfordCoreNLP createPieline() {
Properties props = createPipelineProperties();
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
return pipeline;
}
private Properties createPipelineProperties() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment");
return props;
}
}
最佳答案
这是又一个技术限制案例regarding nlp lib itself ,主要针对一些具体点:
Ambiguous sentiment words - "This product works terribly" vs. "This product is terribly good"
Missed negations - "I would never in a millions years say that this product is worth buying"
Quoted/Indirect text - "My dad says this product is terrible, but I disagree"
Comparisons - "This product is about as useful as a hole in the head"
Anything subtle - "This product is ugly, slow and uninspiring, but it's the only thing on the market that does the job"
在您的示例中,算法没有任何问题。让我们分别分析文本的某些部分:
很高兴能回来!
-> 积极We're here to reconnect with
-> 中立在 ghc16 上认识新的创新者
-> 中立在一个简单的平均值中,我们会得到介于中性 和正 之间的值。然而,正如我们所见,该算法是不可预测的,这就是为什么如果您在文本中添加一个单词(& 也没有得到很好的解释):
So excited to be back! We're here to reconnect with you and meet new innovators at ghc16
...结果将返回中性。
建议:
情绪
1
视为消极的东西,一旦您将面临这样的情况;如果它们都不适合,请考虑切换到另一个 Machine-learning technique .
关于java - 使用 Stanford CoreNLP 情绪分析时输出不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41378527/
我目前正在做一个项目,我必须提取用户的面部表情(网络摄像头一次只能提取一个用户),比如悲伤或快乐。 目前我发现的最佳可能性: 我使用 OpenCV 进行人脸检测。 OpenCV 开发板上的一些用户建议
此代码来自Facebook Chat Emoticons Bar Grease Monkey UserScript ImagesURL = HttpsOn?'https://s-static.ak.f
我正在寻找一种可以分析短文本情感的工具。我搜索了一个星期,但找不到一个可以公开获得的好的。理想的工具是将短文本作为输入并猜测情感的工具。它最好是一个独立的应用程序或库。 我不需要通过文本训练的工具。而
是否有任何简单的 Android/Java 库/框架可以检测图片上的人脸并给我一些关于图片上的人的信息?我的意思是诸如性别、年龄、情绪(微笑、悲伤、愤怒)之类的信息...... 我试过Face++和微
我下载了WN-Affect .但是,我不确定如何使用它来检测句子的情绪。例如,如果我有一个字符串“我讨厌足球”。我希望能够检测情绪是否不好,情绪是否是恐惧。 WN-Affect 没有关于如何操作的教程
现在,Skype 将淘汰其桌面 API 以支持 Skype URI,我正在尝试弄清楚如何修改状态和情绪消息。我的应用程序是一个 chrome 扩展程序,使用它的人都知道它的作用。它是一个合法的用例。目
我有这个: import styled from 'react-emotion'; const Box = styled('div')` display: flex; flex-directi
我是一名优秀的程序员,十分优秀!