-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentiment.cpp
More file actions
57 lines (49 loc) · 1.34 KB
/
Copy pathSentiment.cpp
File metadata and controls
57 lines (49 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Sentiment.h"
Sentiment::Sentiment() = default;
Sentiment::Sentiment(SentimentValue s) {
if (s == POSTIVE) {
posCount = 1;
negCount = 0;
} else if (s == NEGATIVE) {
posCount = 0;
negCount = 1;
} else {
posCount = 0;
negCount = 0;
}
}
void Sentiment::addTrainingData(SentimentValue s) {
if (s == POSTIVE) {
posCount++;
} else if (s == NEGATIVE) {
negCount++;
}
}
SentimentValue Sentiment::getSentiment(const double& minDeviation) {
if (posCount == 0 && negCount == 0) {
return NUETRAL;
}
// Check if postive count and negative count are close
const double posPercent = (double) posCount / (posCount + negCount);
const double negPercent = (double) negCount / (posCount + negCount);
if (posPercent > 0.5 + minDeviation) {
return POSTIVE;
} else if (negPercent > 0.5 + minDeviation) {
return NEGATIVE;
} else {
return NUETRAL;
}
}
double Sentiment::getConfidence(int totalTokens) {
int diff = abs(posCount - negCount);
return (double) diff/totalTokens * 1000;
}
SentimentValue Sentiment::negateSentiment(SentimentValue sentiment) {
if(sentiment == POSTIVE) {
return NEGATIVE;
} else if(sentiment == NEGATIVE) {
return POSTIVE;
} else {
return NUETRAL;
}
}