Embeddable emotions to file
This commit is contained in:
parent
10ac936bd2
commit
5f847df93b
2 changed files with 146 additions and 146 deletions
146
src/Models/Emotions.php
Normal file
146
src/Models/Emotions.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/** @ORM\Embeddable */
|
||||
class Emotions{
|
||||
|
||||
/**
|
||||
* @JMS\Exclude
|
||||
* @var array
|
||||
*/
|
||||
public static $EMOTIONS = ['anger','contempt','disgust','fear','joy','sadness','surprise'];
|
||||
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $anger;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $contempt;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $disgust;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $fear;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $joy;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $sadness;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $surprise;
|
||||
|
||||
/**
|
||||
* Gets the value of anger.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getAnger()
|
||||
{
|
||||
return $this->anger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of contempt.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getContempt()
|
||||
{
|
||||
return $this->contempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of disgust.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getDisgust()
|
||||
{
|
||||
return $this->disgust;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of fear.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getFear()
|
||||
{
|
||||
return $this->fear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of joy.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getJoy()
|
||||
{
|
||||
return $this->joy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of sadness.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getSadness()
|
||||
{
|
||||
return $this->sadness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of surprise.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getSurprise()
|
||||
{
|
||||
return $this->surprise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the score of given emotion
|
||||
* @param string|Emotion $name name of the emotion
|
||||
* @return float The score
|
||||
*/
|
||||
public function getEmotionScore($emotion) {
|
||||
if(!is_string($emotion)) {
|
||||
if(is_a($emotion, Emotion::class)) {
|
||||
$emotion = $emotion->getName();
|
||||
} else {
|
||||
throw new RuntimeException("Invalid emotion", 1);
|
||||
}
|
||||
}
|
||||
$emotions = static::$EMOTIONS;
|
||||
if(in_array($emotion, $emotions)) {
|
||||
return $this->$emotion;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function setEmotion(string $emotion, float $value) {
|
||||
$emotions = static::$EMOTIONS;
|
||||
if(in_array($emotion, $emotions)) {
|
||||
$this->$emotion = $value > 100 ? 100 : $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -347,152 +347,6 @@ class Attributes {
|
|||
}
|
||||
}
|
||||
|
||||
/** @ORM\Embeddable */
|
||||
class Emotions{
|
||||
|
||||
/**
|
||||
* @JMS\Exclude
|
||||
* @var array
|
||||
*/
|
||||
public static $EMOTIONS = ['anger','contempt','disgust','fear','joy','sadness','surprise'];
|
||||
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $anger;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $contempt;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $disgust;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $fear;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $joy;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $sadness;
|
||||
/**
|
||||
* @var float Emotion parameter
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
private $surprise;
|
||||
|
||||
/**
|
||||
* Gets the value of anger.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getAnger()
|
||||
{
|
||||
return $this->anger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of contempt.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getContempt()
|
||||
{
|
||||
return $this->contempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of disgust.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getDisgust()
|
||||
{
|
||||
return $this->disgust;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of fear.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getFear()
|
||||
{
|
||||
return $this->fear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of joy.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getJoy()
|
||||
{
|
||||
return $this->joy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of sadness.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getSadness()
|
||||
{
|
||||
return $this->sadness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of surprise.
|
||||
*
|
||||
* @return float Emotion parameter
|
||||
*/
|
||||
public function getSurprise()
|
||||
{
|
||||
return $this->surprise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the score of given emotion
|
||||
* @param string|Emotion $name name of the emotion
|
||||
* @return float The score
|
||||
*/
|
||||
public function getEmotionScore($emotion) {
|
||||
if(!is_string($emotion)) {
|
||||
if(is_a($emotion, Emotion::class)) {
|
||||
$emotion = $emotion->getName();
|
||||
} else {
|
||||
throw new RuntimeException("Invalid emotion", 1);
|
||||
}
|
||||
}
|
||||
$emotions = static::$EMOTIONS;
|
||||
if(in_array($emotion, $emotions)) {
|
||||
return $this->$emotion;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public function setEmotion(string $emotion, float $value) {
|
||||
$emotions = static::$EMOTIONS;
|
||||
if(in_array($emotion, $emotions)) {
|
||||
$this->$emotion = $value > 100 ? 100 : $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** @ORM\Embeddable */
|
||||
class Expressions {
|
||||
|
||||
|
|
Loading…
Reference in a new issue