11
11
12
12
/**
13
13
* Defines logic for transferring textual affect information, emotional
14
- * manifestations recognised in text into visual output.
14
+ * manifestations recognised in text into visual output.<br/>
15
+ * This class is a singleton.
15
16
*/
16
17
public class Empathyscope {
17
18
@@ -37,8 +38,8 @@ public static Empathyscope getInstance() throws IOException {
37
38
}
38
39
39
40
/**
40
- * Textual affect sensing behavior, the main NLP alghoritm which uses
41
- * Synesketch Lexicon and several heuristic rules.
41
+ * Textual affect sensing behavior, the main NLP algorithm which uses
42
+ * the Lexicon and several heuristic rules.
42
43
*
43
44
* @param text String representing the text to be analysed
44
45
* @return {@link EmotionalState} which represents data recognised from the text
@@ -47,48 +48,48 @@ public static Empathyscope getInstance() throws IOException {
47
48
public EmotionalState feel (String text ) throws IOException {
48
49
49
50
text = text .replace ('\n' , ' ' );
50
- List <AffectWord > affectWords = new ArrayList < AffectWord > ();
51
+ List <AffectWord > affectWords = new ArrayList ();
51
52
List <String > sentences = ParsingUtility .parseSentences (text );
52
53
53
54
for (String sentence : sentences ) {
54
55
55
56
System .out .println ("- " + sentence );
56
57
57
- // we imploy 6 heuristic rules to adjust emotive weights of the words:
58
+ // we imply 6 heuristic rules to adjust emotive weights of the words:
58
59
// (1) more exclamation signs in a sentence => more intensive emotive weights
59
- double exclamationQoef = HeuristicsUtility .computeExclaminationQoef (sentence .toLowerCase ());
60
+ double exclamationQoef = HeuristicsUtility .computeExclamationQoef (sentence .toLowerCase ());
60
61
61
62
// (2) an exclamation mark next to a question mark => emotion of surprise
62
- if (HeuristicsUtility .hasExclaminationQuestionMarks (sentence )) {
63
+ if (HeuristicsUtility .hasExclamationQuestionMarks (sentence )) {
63
64
AffectWord emoWordSurprise = new AffectWord ("?!" );
64
65
emoWordSurprise .setSurpriseWeight (1.0 );
65
66
affectWords .add (emoWordSurprise );
66
67
}
67
68
68
69
boolean hasNegation = false ;
69
70
70
- List <String > splittedWords = ParsingUtility .splitWords (sentence ," " );
71
+ List <String > splitWords = ParsingUtility .splitWords (sentence ," " );
71
72
String previousWord = "" ;
72
73
String negation = "" ;
73
74
74
- for (String splittedWord : splittedWords ) {
75
+ for (String splitWord : splitWords ) {
75
76
76
- AffectWord emoWord = lexUtil .getEmoticonAffectWord (splittedWord );
77
+ AffectWord emoWord = lexUtil .getEmoticonAffectWord (splitWord );
77
78
if (emoWord == null )
78
- emoWord = lexUtil .getEmoticonAffectWord (splittedWord .toLowerCase ());
79
+ emoWord = lexUtil .getEmoticonAffectWord (splitWord .toLowerCase ());
79
80
80
81
if (emoWord != null ) {
81
82
// (3) more emoticons with more 'emotive' signs (e.g. :DDDD)
82
83
// => more intensive emotive weights
83
84
84
- double emoticonCoef = HeuristicsUtility .computeEmoticonQoef (splittedWord , emoWord );
85
+ double emoticonCoef = HeuristicsUtility .computeEmoticonQoef (splitWord , emoWord );
85
86
if (emoticonCoef == 1.0 )
86
- emoticonCoef = HeuristicsUtility .computeEmoticonQoef (splittedWord .toLowerCase (), emoWord );
87
+ emoticonCoef = HeuristicsUtility .computeEmoticonQoef (splitWord .toLowerCase (), emoWord );
87
88
emoWord .adjustWeights (exclamationQoef * emoticonCoef );
88
89
affectWords .add (emoWord );
89
90
} else {
90
91
91
- List <String > words = ParsingUtility .parseWords (splittedWord );
92
+ List <String > words = ParsingUtility .parseWords (splitWord );
92
93
93
94
for (String word : words ) {
94
95
@@ -105,10 +106,10 @@ public EmotionalState feel(String text) throws IOException {
105
106
if (emoWord != null ) {
106
107
107
108
// (5) word is upper case => more intensive emotive weights
108
- double capsLockCoef = HeuristicsUtility .computeCapsLockQoef (word );
109
+ double capsLockCoef = HeuristicsUtility .computeUpperCasedQoef (word );
109
110
110
111
// (6) previous word is a intensity modifier (e.g.
111
- // "extremly ") => more intensive emotive weights
112
+ // "extremely ") => more intensive emotive weights
112
113
double modifierCoef = HeuristicsUtility .computeModifier (previousWord );
113
114
114
115
// change the affect word!
@@ -130,18 +131,17 @@ public EmotionalState feel(String text) throws IOException {
130
131
}
131
132
132
133
private EmotionalState createEmotionalState (String text , List <AffectWord > affectWords ) {
133
- TreeSet <Emotion > emotions = new TreeSet < Emotion > ();
134
+ TreeSet <Emotion > emotions = new TreeSet ();
134
135
int generalValence = 0 ;
135
- double valence , generalWeight , happinessWeight , sadnessWeight , angerWeight , fearWeight , disgustWeight , surpriseWeight ;
136
-
137
- valence = 0.0 ;
138
- generalWeight = 0.0 ;
139
- happinessWeight = 0.0 ;
140
- sadnessWeight = 0.0 ;
141
- angerWeight = 0.0 ;
142
- fearWeight = 0.0 ;
143
- disgustWeight = 0.0 ;
144
- surpriseWeight = 0.0 ;
136
+
137
+ double valence = 0.0 ;
138
+ double generalWeight = 0.0 ;
139
+ double happinessWeight = 0.0 ;
140
+ double sadnessWeight = 0.0 ;
141
+ double angerWeight = 0.0 ;
142
+ double fearWeight = 0.0 ;
143
+ double disgustWeight = 0.0 ;
144
+ double surpriseWeight = 0.0 ;
145
145
146
146
// compute weights. maximum weights for the particular emotion are taken.
147
147
for (AffectWord affectWord : affectWords ) {
0 commit comments