Package com.tagtraum.audiokern.mood
Class Mood
- java.lang.Object
-
- com.tagtraum.audiokern.mood.Mood
-
- All Implemented Interfaces:
Externalizable,Serializable,org.json.simple.JSONAware
public class Mood extends Object implements Externalizable, org.json.simple.JSONAware
Valence/arousal based mood. Internally used mood constants/angles are derived from J. A. Russell, "A circumspect model of affect", Journal of Personality and Social Psychology, vol. 39, no. 6, p. 1161, 1980.
-
-
Field Summary
Fields Modifier and Type Field Description static MoodAFRAIDstatic MoodALARMEDstatic MoodANGRYstatic MoodANNOYEDstatic MoodAROUSEDstatic MoodASTONISHEDstatic MoodBOREDstatic MoodCALMstatic Mood[]CATEGORIESstatic Mood[]CATEGORIES_NO_NEUTRALstatic MoodCATEGORY_AROUSEDstatic MoodCATEGORY_CONTENTstatic MoodCATEGORY_DEPRESSEDstatic MoodCATEGORY_DISTRESSEDstatic MoodCATEGORY_EXCITEDstatic MoodCATEGORY_MISERABLEstatic MoodCATEGORY_NEUTRALstatic MoodCATEGORY_PLEASEDstatic MoodCATEGORY_SLEEPYstatic MoodDELIGHTEDstatic MoodDEPRESSEDstatic MoodDISTRESSEDstatic MoodDROOPYstatic MoodEXCITEDstatic MoodFRUSTRATEDstatic MoodGLADstatic MoodGLOOMYstatic MoodHAPPYstatic Mood[]LABELED_MOODSstatic byteMAX_AROUSALstatic floatMAX_STRENGTHstatic byteMAX_VALENCEstatic MoodMISERABLEstatic MoodNEUTRALstatic MoodPLEASEDstatic MoodRELAXEDstatic MoodSADstatic MoodSERENEstatic MoodSLEEPYstatic MoodTENSEstatic MoodTIRED
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description floatcosineSimilarity(float otherAngle)floatcosineSimilarity(int valence, int arousal)floatcosineSimilarity(Mood mood)Compares the angles of two moods and returns a number between -1 and 1.booleanequals(Object o)floatgetAngle()Angle of this emotion in a circumspect model.intgetArousal()Arousal of this song.MoodgetCategory()One of nine categories this mood can be grouped into.intgetCategoryOrdinal()One of nine categories this mood can be grouped into.MoodgetClosestLabeledMood()One of a number of labeled moods this mood is most similar to.float[]getComponents()Mood components valence and arousal scaled to the range-1to1.StringgetLabel()ColorgetRedGreenSaturation()Maps valence to values from red (negative) to green (positive) and indicates the associated arousal through saturation.static ColorgetRedGreenSaturation(int valence, int arousal)Maps valence to values from red (negative) to green (positive) and indicates the associated arousal through saturation.floatgetStrength()Indicates the strength of an emotion, assuming a no-strength center in the middle of the valence/arousal scale.MoodStrengthgetStrengthClass()Classifies this mood into a strength class.intgetValence()Valence of this song.static MoodguessMood(String... words)Attempt to derive a mood from the given word list.inthashCode()voidreadExternal(ObjectInput in)voidsetArousal(int arousal)Sets the arousal - a value ranging from -100 to +100.voidsetLabel(String label)voidsetValence(int valence)Sets the valence - a value ranging from -100 to +100.StringtoJSONString()StringtoString()voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
MAX_AROUSAL
public static byte MAX_AROUSAL
-
MAX_VALENCE
public static byte MAX_VALENCE
-
MAX_STRENGTH
public static float MAX_STRENGTH
-
HAPPY
public static final Mood HAPPY
-
DELIGHTED
public static final Mood DELIGHTED
-
EXCITED
public static final Mood EXCITED
-
ASTONISHED
public static final Mood ASTONISHED
-
AROUSED
public static final Mood AROUSED
-
TENSE
public static final Mood TENSE
-
ALARMED
public static final Mood ALARMED
-
ANGRY
public static final Mood ANGRY
-
AFRAID
public static final Mood AFRAID
-
ANNOYED
public static final Mood ANNOYED
-
DISTRESSED
public static final Mood DISTRESSED
-
FRUSTRATED
public static final Mood FRUSTRATED
-
MISERABLE
public static final Mood MISERABLE
-
SAD
public static final Mood SAD
-
GLOOMY
public static final Mood GLOOMY
-
DEPRESSED
public static final Mood DEPRESSED
-
BORED
public static final Mood BORED
-
DROOPY
public static final Mood DROOPY
-
TIRED
public static final Mood TIRED
-
SLEEPY
public static final Mood SLEEPY
-
CALM
public static final Mood CALM
-
RELAXED
public static final Mood RELAXED
-
SERENE
public static final Mood SERENE
-
GLAD
public static final Mood GLAD
-
PLEASED
public static final Mood PLEASED
-
NEUTRAL
public static final Mood NEUTRAL
-
CATEGORY_PLEASED
public static final Mood CATEGORY_PLEASED
-
CATEGORY_EXCITED
public static final Mood CATEGORY_EXCITED
-
CATEGORY_AROUSED
public static final Mood CATEGORY_AROUSED
-
CATEGORY_DISTRESSED
public static final Mood CATEGORY_DISTRESSED
-
CATEGORY_MISERABLE
public static final Mood CATEGORY_MISERABLE
-
CATEGORY_DEPRESSED
public static final Mood CATEGORY_DEPRESSED
-
CATEGORY_SLEEPY
public static final Mood CATEGORY_SLEEPY
-
CATEGORY_CONTENT
public static final Mood CATEGORY_CONTENT
-
CATEGORY_NEUTRAL
public static final Mood CATEGORY_NEUTRAL
-
CATEGORIES_NO_NEUTRAL
public static final Mood[] CATEGORIES_NO_NEUTRAL
-
CATEGORIES
public static final Mood[] CATEGORIES
-
LABELED_MOODS
public static final Mood[] LABELED_MOODS
-
-
Constructor Detail
-
Mood
public Mood(int valence, int arousal) throws IllegalArgumentExceptionMood.- Parameters:
valence- -100 <= valence <= +100arousal- -100 <= arousal <= +100- Throws:
IllegalArgumentException- if the parameters aren't in the valid range
-
Mood
public Mood(int valence, int arousal, String label) throws IllegalArgumentExceptionMood.- Parameters:
valence- -100 <= valence <= +100arousal- -100 <= arousal <= +100label- description- Throws:
IllegalArgumentException- if the parameters aren't in the valid range
-
Mood
public Mood()
Mood.
-
Mood
public Mood(String jsonString)
Instantiate from JSON string.- Parameters:
jsonString- json string- See Also:
toJSONString()
-
Mood
public Mood(float angleInRadians, String label, float strength) throws IllegalArgumentExceptionMood.- Parameters:
angleInRadians- angleInRadianslabel- labelstrength- value between 0 and 100.- Throws:
IllegalArgumentException- if strength is greater than 100
-
-
Method Detail
-
cosineSimilarity
public float cosineSimilarity(Mood mood)
Compares the angles of two moods and returns a number between -1 and 1. -1 being most dissimilar, 0 being orthogonal and 1 being the same.- Parameters:
mood- another mood,nullwill always lead to a similarity of 0- Returns:
- similarity
-
cosineSimilarity
public float cosineSimilarity(int valence, int arousal)
-
cosineSimilarity
public float cosineSimilarity(float otherAngle)
-
getComponents
public float[] getComponents()
Mood components valence and arousal scaled to the range-1to1.- Returns:
- [valance, arousal]
-
getAngle
public float getAngle()
Angle of this emotion in a circumspect model. In polar coordinates this would be the angle,getStrength()would be the length.- Returns:
- angle (in radians) of this mood
-
getStrength
public float getStrength()
Indicates the strength of an emotion, assuming a no-strength center in the middle of the valence/arousal scale. In essence this is the length of the vector from the center of the scale to the actual emotion.- Returns:
- strength
- See Also:
getAngle()
-
getStrengthClass
public MoodStrength getStrengthClass()
Classifies this mood into a strength class.- Returns:
- strength class
-
getValence
public int getValence()
Valence of this song. This is a value ranging from -100 to +100.- Returns:
- valence
-
setValence
public void setValence(int valence)
Sets the valence - a value ranging from -100 to +100.- Parameters:
valence- -100 <= valence <= +100- Throws:
IllegalArgumentException- if the parameter isn't in the valid range
-
getArousal
public int getArousal()
Arousal of this song. This is a value ranging from -100 to +100.- Returns:
- arousal
-
setArousal
public void setArousal(int arousal) throws IllegalArgumentExceptionSets the arousal - a value ranging from -100 to +100.- Parameters:
arousal- -100 <= arousal <= +100- Throws:
IllegalArgumentException- if the parameter isn't in the valid range
-
getLabel
public String getLabel()
-
setLabel
public void setLabel(String label)
-
getCategory
public Mood getCategory()
One of nine categories this mood can be grouped into.CATEGORY_NEUTRALis chosen when the length of this mood is less then 20.- Returns:
- category
-
getCategoryOrdinal
public int getCategoryOrdinal()
One of nine categories this mood can be grouped into.CATEGORY_NEUTRALis chosen when the length of this mood is less then 20.- Returns:
- a number denoting a category
-
getClosestLabeledMood
public Mood getClosestLabeledMood()
One of a number of labeled moods this mood is most similar to.NEUTRALis chosen when the length of this mood is less then 20.- Returns:
- category
-
getRedGreenSaturation
public Color getRedGreenSaturation()
Maps valence to values from red (negative) to green (positive) and indicates the associated arousal through saturation.- Returns:
- color red green mapping of this mood
-
getRedGreenSaturation
public static Color getRedGreenSaturation(int valence, int arousal)
Maps valence to values from red (negative) to green (positive) and indicates the associated arousal through saturation.- Parameters:
valence- valencearousal- arousal- Returns:
- color red green mapping of this mood
-
toJSONString
public String toJSONString()
- Specified by:
toJSONStringin interfaceorg.json.simple.JSONAware
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
guessMood
public static Mood guessMood(String... words)
Attempt to derive a mood from the given word list.- Parameters:
words- word list- Returns:
- derived mood or
null, if we were unable to derive one
-
-