How To Build Sentiment Analysis In Few Steps Using Emotional Sensor Data Set

Emotional Sensor  Data Set Its a Simple CSV File Contain Top 23 650  English Words Classified Statistically Into 7 Basic Emotions Disgust, Surprise ,Neutral ,Anger ,Sad ,Happy and Fear.
For Example :

word  , disgust      , surprise   , neutral     , anger       ,sad  ,   happy,  fear
happy , 5.7510927E-4 , 0.02726018 , 0.010006902 , 0.022659307 , 0.015067863 , 0.054175295 , 0.013687601

Lets try To Analyse Emotionally This Text :“When I saw a good friend again after not having seen her for a long time.”
FIRST We Start Searching In Emotional Sensor  Data Set For This Words and Get Its Corresponding Values.

saw  , 0.049492735  , 0.022072937  , 0.010556622  , 0.01631478  , 0.010556622  , 0.023718126  , 0.010830821 
good  , 0.0036019539  , 0.020695973  , 0.026434679  , 0.019108672  , 0.021306474  , 0.032905985  , 0.019108672 
friend  , 0.019634776  , 0.007837751  , 0.0073529417  , 0.042905625  , 0.014301876  , 0.032563027  , 0.018665161 
......

SECONDLY We Calculate Final Emotional Value Like This:

DISGUST =(word1_DISGUST_value+word2_DISGUST_value+...)/number of words =0.008641913 
SURPRISE=(word1_SURPRISE_value+word2_SURPRISE_value+...)/number of words =0.025260884 
NEUTRAL =(word1_NEUTRAL_value+word2_NEUTRAL_value+...)/number of words =0.010167446 
ANGER= 0.024733393 
SAD =0.02346175 
HAPPY =0.02654479 
FEAR =0.024353992 

Now We Can See That HAPPY is The Max Value Then We Result That the Text “When I saw a good friend again after not having seen her for a long time.”
Contain Happy Emotion.

We Can Do all That in Simple Lines of Java Code Like This Example

public class testAndbrain {
 static final String DIR_PATH = "base/";

 public static HashMap < String, String[] > readLines(URL url) throws IOException {
  HashMap < String, String[] > hmap = new HashMap < String, String[] > ();

  Reader fileReader = new InputStreamReader(url.openStream(),
   Charset.forName("UTF-8"));
  List < String > lines;
  String line = "";
  try (BufferedReader bufferedReader = new BufferedReader(fileReader)) {
   String line2 = "";
   String[] wordline;
   int index = 0;
   while ((line2 = bufferedReader.readLine()) != null) {
    index = line2.indexOf(",");
    wordline = line2.split(",");
    hmap.put(line2.substring(0,
     index), line2.substring(index, line2.length()).split(","));
   }
  }
  return hmap;
 }

 static float disgust = 0;
 static float surprise = 0;
 static float neutral = 0;
 static float anger = 0;
 static float sad = 0;
 static float happy = 0;
 static float fear = 0;
 public static String getMAX() {  // }

 public static void main(String[] args) throws IOException {
  System.out.println("START TEST ANDBRAIN");
  String sentence = "when i saw a good friend again after not having seen her for
  a long time ";
  String[] testPhrase = sentence.split("\\s");
  URL words = new File(DIR_PATH + "andbrain.csv").toURI().toURL();
  final HashMap < String, String[] > wordss = readLines(words);

  disgust = 0;
  surprise = 0;
  neutral = 0;
  anger = 0;
  sad = 0;
  happy = 0;
  fear = 0;
  for (String word: testPhrase) {
   Set set = wordss.entrySet();
   Iterator iterator = set.iterator();
   String[] wordProb;
   while (iterator.hasNext()) {
    Map.Entry mentry = (Map.Entry) iterator.next();
    wordProb = (String[]) mentry.getValue();

    if (mentry.getKey().toString().substring(0, mentry.getKey().toString().length() - 1).equals(word)) {
     disgust += Float.parseFloat(wordProb[1]);
     surprise += Float.parseFloat(wordProb[2]);
     neutral += Float.parseFloat(wordProb[3]);
     anger += Float.parseFloat(wordProb[4]);
     sad += Float.parseFloat(wordProb[5]);
     happy += Float.parseFloat(wordProb[6]);
     fear += Float.parseFloat(wordProb[7]);


     System.out.print(word);
     for (String wo: wordProb) {
      System.out.print(" ," + wo);
     }
     System.out.println(" ");

    }

   }

  }
  System.out.println("DISGUST " + String.valueOf(disgust / testPhrase.length) + " ");
  System.out.println("SUPRISE " + String.valueOf(surprise / testPhrase.length) + " ");
  System.out.println("NEUTRAL " + String.valueOf(neutral / testPhrase.length) + " ");
  System.out.println("ANGER " + String.valueOf(anger / testPhrase.length) + " ");
  System.out.println("SAD " + String.valueOf(sad / testPhrase.length) + " ");
  System.out.println("HAPPY " + String.valueOf(happy / testPhrase.length) + " ");
  System.out.println("FEAR " + String.valueOf(fear / testPhrase.length) + " ");
  System.out.println("*********************************");
  System.out.println(" *** < " + sentence + " > ***");
  System.out.println("*********** < " + getMAX() + " > ************");
  System.out.println("*********************************");

  
 }

}

Get Your Copy Now FROM HERE and You Can Try a Live Demo FROM HERE
Just Contact us For Any Question We Are Here To Serve You.