Skip to content

Commit

Permalink
Much needed editing
Browse files Browse the repository at this point in the history
Many small editorial tweaks like typos, spaces, line breaks etc
  • Loading branch information
Chaiavi committed Apr 13, 2017
1 parent 7a98b32 commit 8ee1712
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 311 deletions.
16 changes: 0 additions & 16 deletions src/main/java/org/chaiware/app/TestSentence.java

This file was deleted.

33 changes: 33 additions & 0 deletions src/main/java/org/chaiware/app/TextToEmotion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.chaiware.app;

import java.io.IOException;

import org.chaiware.emotion.EmotionalState;
import org.chaiware.emotion.Empathyscope;

public class TextToEmotion {

/** For internal use, in order to try the app and see that it is working while developing it */
public static void main(String[] args ) {
if (args.length < 1) {
System.out.println("Please send an argument with the string you want to sense for emotion");
System.exit(0);
}
String text = args[0];

System.out.println(textToEmotion(text));
}

/** Use this method in order to analyze any text for emotions */
public static EmotionalState textToEmotion(String text) {

EmotionalState sentenceState = new EmotionalState();
try {
sentenceState = Empathyscope.getInstance().feel(text);
} catch (IOException e) {
e.printStackTrace();
}

return sentenceState;
}
}
130 changes: 43 additions & 87 deletions src/main/java/org/chaiware/emotion/AffectWord.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.chaiware.emotion;

/**
* Represents one unit from the Synesketch Lexicon: a word associated with
* Represents one unit from the Lexicon: a word associated with
* emotional meaning, and it's emotional weights and valence.
* <p>
* Synesketch Lexicon, which consits of several thousand words (with emoticons),
* associates these atributes to a word:
* The Lexicon, which consists of several thousand words (with emoticons),
* associates these attributes to a word:
* <ul>
* <li>General emotional weight
* <li>General emotional valence
Expand All @@ -22,57 +22,42 @@ public class AffectWord {
private String word;

private double generalWeight = 0.0;

private double generalValence = 0.0;

private double happinessWeight = 0.0;

private double sadnessWeight = 0.0;

private double angerWeight = 0.0;

private double fearWeight = 0.0;

private double disgustWeight = 0.0;

private double surpriseWeight = 0.0;

private boolean startsWithEmoticon = false;

/**
* Class constructor which sets the affect word
*
* @param word
* String representing the word
* @param word String representing the word
*/
public AffectWord(String word) {
this.word = word;
}

/**
* Class constructor which sets the affect word and it's weights. Valence is
* Class constructor which sets the affect word and its weights. Valence is
* calculated as a function of different emotion type weights.
*
* @param word
* {@link String} representing the word
* @param generalWeight
* double representing the general emotional weight
* @param happinessWeight
* double representing the happiness weight
* @param sadnessWeight
* double representing the sadness weight
* @param angerWeight
* double representing the anger weight
* @param fearWeight
* double representing the fear weight
* @param disgustWeight
* double representing the disgust weight
* @param surpriseWeight
* double representing the surprise weight
* @param word {@link String} representing the word
* @param generalWeight double representing the general emotional weight
* @param happinessWeight double representing the happiness weight
* @param sadnessWeight double representing the sadness weight
* @param angerWeight double representing the anger weight
* @param fearWeight double representing the fear weight
* @param disgustWeight double representing the disgust weight
* @param surpriseWeight double representing the surprise weight
*/
public AffectWord(String word, double generalWeight,
double happinessWeight, double sadnessWeight, double angerWeight,
double fearWeight, double disgustWeight, double surpriseWeight) {

this.word = word;
this.generalWeight = generalWeight;
this.happinessWeight = happinessWeight;
Expand All @@ -89,29 +74,21 @@ public AffectWord(String word, double generalWeight,
* by the quoeficient. Valence is calculated as a function of different
* emotion type weights.
*
* @param word
* {@link String} representing the word
* @param generalWeight
* double representing the general emotional weight
* @param happinessWeight
* double representing the happiness weight
* @param sadnessWeight
* double representing the sadness weight
* @param angerWeight
* double representing the anger weight
* @param fearWeight
* double representing the fear weight
* @param disgustWeight
* double representing the disgust weight
* @param surpriseWeight
* double representing the surprise weight
* @param quoficient
* double representing the quoficient for adjusting the weights
* @param word {@link String} representing the word
* @param generalWeight double representing the general emotional weight
* @param happinessWeight double representing the happiness weight
* @param sadnessWeight double representing the sadness weight
* @param angerWeight double representing the anger weight
* @param fearWeight double representing the fear weight
* @param disgustWeight double representing the disgust weight
* @param surpriseWeight double representing the surprise weight
* @param quoficient double representing the quoficient for adjusting the weights
*/
public AffectWord(String word, double generalWeight,
double happinessWeight, double sadnessWeight, double angerWeight,
double fearWeight, double disgustWeight, double surpriseWeight,
double quoficient) {

this.word = word;
this.generalWeight = generalWeight * quoficient;
this.happinessWeight = happinessWeight * quoficient;
Expand All @@ -126,8 +103,7 @@ public AffectWord(String word, double generalWeight,
/**
* Adjusts weights by the certain quoficient.
*
* @param quoficient
* double representing the quoficient for adjusting the weights
* @param quoficient double representing the quoficient for adjusting the weights
*/

public void adjustWeights(double quoficient) {
Expand Down Expand Up @@ -159,14 +135,12 @@ private void normalise() {
}

/**
* Flips valence of the word -- calculates change from postive to negative
* emotion.
* Flips valence of the word -- calculates change from postive to negative emotion.
*/
public void flipValence() {
generalValence = -generalValence;
double temp = happinessWeight;
happinessWeight = Math.max(Math.max(sadnessWeight, angerWeight), Math
.max(fearWeight, disgustWeight));
happinessWeight = Math.max(Math.max(sadnessWeight, angerWeight), Math.max(fearWeight, disgustWeight));
sadnessWeight = temp;
angerWeight = temp / 2;
fearWeight = temp / 2;
Expand All @@ -183,6 +157,7 @@ public AffectWord clone() {
sadnessWeight, angerWeight, fearWeight, disgustWeight,
surpriseWeight);
value.setStartsWithEmoticon(startsWithEmoticon);

return value;
}

Expand All @@ -199,9 +174,7 @@ public boolean startsWithEmoticon() {
/**
* Sets does the word start with emoticon.
*
* @param startsWithEmoticon
* boolean (true if the word starts with the emoticon, false if
* not)
* @param startsWithEmoticon boolean (true if the word starts with the emoticon, false if not)
*/
public void setStartsWithEmoticon(boolean startsWithEmoticon) {
this.startsWithEmoticon = startsWithEmoticon;
Expand All @@ -219,8 +192,7 @@ public double getAngerWeight() {
/**
* Getter for the anger weight.
*
* @param angerWeight
* double which represents the anger weight
* @param angerWeight double which represents the anger weight
*/
public void setAngerWeight(double angerWeight) {
this.angerWeight = angerWeight;
Expand All @@ -238,8 +210,7 @@ public double getDisgustWeight() {
/**
* Setter for the disgust weight.
*
* @param disgustWeight
* double which represents the disgust weight
* @param disgustWeight double which represents the disgust weight
*/
public void setDisgustWeight(double disgustWeight) {
this.disgustWeight = disgustWeight;
Expand All @@ -257,8 +228,7 @@ public double getFearWeight() {
/**
* Getter for the fear weight.
*
* @param fearWeight
* double which represents the fear weight
* @param fearWeight double which represents the fear weight
*/
public void setFearWeight(double fearWeight) {
this.fearWeight = fearWeight;
Expand All @@ -276,8 +246,7 @@ public double getHappinessWeight() {
/**
* Setter for the happiness weight.
*
* @param happinessWeight
* double which represents the happiness weight
* @param happinessWeight double which represents the happiness weight
*/
public void setHappinessWeight(double happinessWeight) {
this.happinessWeight = happinessWeight;
Expand All @@ -295,8 +264,7 @@ public double getSadnessWeight() {
/**
* Setter for the sadness weight.
*
* @param sadnessWeight
* double which represents the sadness weight
* @param sadnessWeight double which represents the sadness weight
*/
public void setSadnessWeight(double sadnessWeight) {
this.sadnessWeight = sadnessWeight;
Expand All @@ -314,8 +282,7 @@ public double getSurpriseWeight() {
/**
* Setter for the surprise weight.
*
* @param surpriseWeight
* double which represents the surprise weight
* @param surpriseWeight double which represents the surprise weight
*/
public void setSurpriseWeight(double surpriseWeight) {
this.surpriseWeight = surpriseWeight;
Expand All @@ -342,8 +309,7 @@ public double getGeneralWeight() {
/**
* Setter for the general weight.
*
* @param generalWeight
* double which represents the general weight
* @param generalWeight double which represents the general weight
*/
public void setGeneralWeight(double generalWeight) {
this.generalWeight = generalWeight;
Expand All @@ -361,8 +327,7 @@ public double getGeneralValence() {
/**
* Setter for the general valence
*
* @param generalValence
* double which represents the general valence
* @param generalValence double which represents the general valence
*/
public void setGeneralValence(int generalValence) {
this.generalValence = generalValence;
Expand All @@ -373,21 +338,15 @@ public void setGeneralValence(int generalValence) {
* emotional weight for emotion types defined by Ekman: happiness, sadness,
* fear, anger, disgust, and surprise.
*
* @return boolean value, true if all specific emotional weight have the
* value of zero
* @return boolean value, true if all specific emotional weight have the value of zero
*/
public boolean isZeroEkman() {
if (getWeightSum() == 0) {
return true;
} else {
return false;
}

return getWeightSum() == 0;
}

/**
* Returns a string representation of the object.
*
* @return a string representation of the object
* @return a string representation of the different weights of the emotions
*/
public String toString() {
return word + " " + generalWeight + " " + happinessWeight + " "
Expand All @@ -396,13 +355,10 @@ public String toString() {
}

private double getValenceSum() {
return happinessWeight - sadnessWeight - angerWeight - fearWeight
- disgustWeight;
return happinessWeight - sadnessWeight - angerWeight - fearWeight - disgustWeight;
}

private double getWeightSum() {
return happinessWeight + sadnessWeight + angerWeight + fearWeight
+ disgustWeight + surpriseWeight;
return happinessWeight + sadnessWeight + angerWeight + fearWeight + disgustWeight + surpriseWeight;
}

}
Loading

0 comments on commit 8ee1712

Please sign in to comment.