Skip to content

Commit f15f133

Browse files
Use constants for negative / neutral / positive
1 parent d087228 commit f15f133

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Antoineaugusti/LaravelSentimentAnalysis/SentimentAnalysis.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
class SentimentAnalysis {
66

77
private $sentiment;
8+
const NEGATIVE = 'negative';
9+
const NEUTRAL = 'neutral';
10+
const POSITIVE = 'positive';
811

912
public function __construct()
1013
{
@@ -23,15 +26,15 @@ public function decision($string)
2326

2427
switch ($dominantClass) {
2528
case 'neg':
26-
return 'negative';
29+
return self::NEGATIVE;
2730
break;
2831

2932
case 'neu':
30-
return 'neutral';
33+
return SELF::NEUTRAL;
3134
break;
3235

3336
case 'pos':
34-
return 'positive';
37+
return SELF::POSITIVE;
3538
break;
3639
}
3740
}
@@ -54,7 +57,7 @@ public function score($string)
5457
*/
5558
public function isPositive($string)
5659
{
57-
return $this->decision($string) == 'positive';
60+
return $this->decision($string) == SELF::POSITIVE;
5861
}
5962

6063
/**
@@ -64,7 +67,7 @@ public function isPositive($string)
6467
*/
6568
public function isNegative($string)
6669
{
67-
return $this->decision($string) == 'negative';
70+
return $this->decision($string) == self::NEGATIVE;
6871
}
6972

7073
/**
@@ -74,6 +77,6 @@ public function isNegative($string)
7477
*/
7578
public function isNeutral($string)
7679
{
77-
return $this->decision($string) == 'neutral';
80+
return $this->decision($string) == SELF::NEUTRAL;
7881
}
7982
}

0 commit comments

Comments
 (0)