def __sub__(self, other):
        if isinstance(other, str):
            other = self.string_to_emotion(other)

        if isinstance(other, Neutrality):
            emo = copy(self)
            return emo

        if isinstance(other, Feeling):
            c = copy(self)
            for e in other.emotions:
                c = c - e
            return c

        if isinstance(other, Emotion):
            # matrix product of emotion vectors
            other_vector = other.emotion_vector

            result_vector = np.array(other_vector) - np.array(self.emotion_vector)
            c = CompositeEmotion()

            for e in result_vector:
                if e.dimension:
                    c.components.append(e)
            if len(c.components) == 1:
                return c.components[0]
            if not len(c.components):
                return Neutrality()
            return c

        return NotImplemented
    def emotion_vector(self):
        sensitivity = Neutrality()
        attention = Neutrality()
        pleasantness = Neutrality()
        aptitude = Neutrality()
        for emotion in self.components:
            if emotion.dimension == self.sensitivity_dimension:
                sensitivity = sensitivity + emotion
            elif emotion.dimension == self.attention_dimension:
                attention = attention + emotion
            elif emotion.dimension == self.aptitude_dimension:
                aptitude = aptitude + emotion
            elif emotion.dimension == self.pleasantness_dimension:
                pleasantness = pleasantness + emotion

        return [sensitivity, attention, pleasantness, aptitude]
Esempio n. 3
0
    def emotion_vector(self):
        sensitivity = Neutrality()
        attention = Neutrality()
        pleasantness = Neutrality()
        aptitude = Neutrality()

        for e in self.emotions:
            if "sensitivity" in e:
                sensitivity = sensitivity + e
            if "attention" in e:
                attention = attention + e
            if "aptitude" in e:
                aptitude = aptitude + e
            if "pleasantness" in e:
                pleasantness = pleasantness + e

        return [sensitivity, attention, pleasantness, aptitude]
Esempio n. 4
0
from emotion_data.emotions import EMOTIONS
from emotion_data.feelings import Feeling, FEELINGS
from emotion_data.plutchik import Neutrality, Emotion
import numpy as np

n = Neutrality()

# if summing emotions from different dimensions you get a Feeling
e = EMOTIONS["annoyance"]
e2 = EMOTIONS["trust"]
f = e + e2

assert type(f) == Feeling
assert str(f) == "mix of annoyance and trust"

# feelings might have a explicit name or not
e = EMOTIONS["anticipation"]
e2 = EMOTIONS["joy"]
f = e + e2

assert f.name == "optimism"
assert f.secondary_name == "mix of anticipation and joy"
assert str(f) == f.secondary_name

# strings with emotion can also be used
f = e + "joy"
assert f.name == "optimism"

# or feeling names
f = e + "love"
assert f.name == "mix of joy and trust and anticipation"
from emotion_data.plutchik import Neutrality, Emotion
from emotion_data.composite_emotions import COMPOSITE_EMOTIONS, CompositeEmotion, CompositeDimension
import numpy as np

e = COMPOSITE_EMOTIONS["disapproval"]

# composite emotions are emotions in more than 1 dimension
# some composite emotions have a name
assert e.name == "disapproval"

# if the emotion is not named, the naming is of the sort
# "{dimension name} of {emotion name}, {dimension2 name} of {emotion2 name}"
assert e.secondary_name == "pleasantness of grief, attention of amazement"

# composite emotions have an 4D emotion vector representation
assert e.emotion_vector == [Neutrality(), EMOTIONS["amazement"], EMOTIONS["grief"], Neutrality()]

# composite emotions have an equivalent feeling
assert isinstance(e.equivalent_feeling, Feeling)
assert str(e.equivalent_feeling) == "mix of amazement and grief"
assert e.equivalent_feeling.name == "horror"

# composite emotions can be summed, this operates on the emotion_vector level
e2 = COMPOSITE_EMOTIONS["anxiety"]
assert e + e2 == "sensitivity of terror, pleasantness of grief"
assert isinstance(e2, CompositeEmotion)

e2 = EMOTIONS["rage"]
assert e + e2 == "sensitivity of rage, attention of amazement, pleasantness of grief"
assert isinstance(e + e2, CompositeEmotion)
Esempio n. 6
0
 def __abs__(self):
     return Neutrality()
Esempio n. 7
0
assert d.valence == 1

# pleasantness and aptitude valence will depend on the emotion flow
d = DIMENSIONS["pleasantness"]
assert d.kind == "neutral"
assert d.valence == 0

# you can check if dimensions contain an emotion
e = EMOTIONS["rage"]

d = DIMENSIONS["sensitivity"]

assert e in d

# neutrality is in every dimension
n = Neutrality()
for dim in DIMENSIONS:
    assert n in DIMENSIONS[dim]

# dimension emotions can be retrieved
assert d.basic_emotion == EMOTIONS["annoyance"]
assert d.basic_opposite == "apprehension"

# composite dimensions can be created
d2 = DIMENSIONS["aptitude"]
c = d + d2
assert c.name == "sensitivity/aptitude"
assert isinstance(c, CompositeDimension)

# composite dimensions have composite emotions
assert isinstance(c.intense_opposite, CompositeEmotion)
# when used as string emotion name is considered
assert e.name == str(e)

# len of emotions is always between 0 and 4 (1 per dimension)
assert len(e) == 1

# when used as boolean valence is used (positive vs negative emotion)
assert bool(e) == True

e = EMOTIONS["terror"]
assert bool(e) == False


# Neutrality is the neutral and unitary element of emotions, it changes nothing
n = Neutrality()
assert e + n == e
assert e - n == e
assert e * n == e
assert e / n == e

assert len(n) == 0
assert int(n) == 0

try:
    bool(n)
except:
    # bool for neutrality is undefined
    reason = "neutrality can not be cast to bool"

# neutrality is both true and false
 def array_to_emotion(arr):
     sensitivity = Neutrality(dimension="sensitivity") + arr.item(0)
     attention = Neutrality(dimension="attention") + arr.item(1)
     pleasantness = Neutrality(dimension="pleasantness") + arr.item(2)
     aptitude = Neutrality(dimension="aptitude") + arr.item(3)
     return sensitivity + pleasantness + aptitude + attention