diff --git a/src/Analyzer.php b/src/Analyzer.php index 8e36f05..0dd546a 100644 --- a/src/Analyzer.php +++ b/src/Analyzer.php @@ -170,8 +170,8 @@ public function getSentiment($text) $text_no_emoji = ''; $prev_space = true; - - foreach($this->str_split_unicode($text) as $unichr ) { + + foreach($this->str_split_unicode($text) as $unichr ) { if (array_key_exists($unichr, $this->emojis)) { $description = $this->emojis[$unichr]; if (!($prev_space)) { @@ -384,8 +384,9 @@ public function _idioms_check($wordInContext, $valence) $sequences = [$onezero, $twoonezero, $twoone, $threetwoone, $threetwo]; foreach ($sequences as $seq) { - if (array_key_exists(strtolower($seq), Config::SPECIAL_CASE_IDIOMS)) { - $valence = Config::SPECIAL_CASE_IDIOMS[$seq]; + $key = strtolower($seq); + if (array_key_exists($key, Config::SPECIAL_CASE_IDIOMS)) { + $valence = Config::SPECIAL_CASE_IDIOMS[$key]; break; } diff --git a/src/Procedures/SentiText.php b/src/Procedures/SentiText.php index a5343a7..7a0773f 100644 --- a/src/Procedures/SentiText.php +++ b/src/Procedures/SentiText.php @@ -8,15 +8,15 @@ class SentiText { - + private $text = ""; public $words_and_emoticons = null; public $is_cap_diff = null; const PUNC_LIST = [".", "!", "?", ",", ";", ":", "-", "'", "\"", "!!", "!!!", "??", "???", "?!?", "!?!", "?!?!", "!?!?"]; - - + + function __construct($text) { //checking that is string @@ -29,7 +29,7 @@ function __construct($text) // adjacent punctuation (keeps emoticons & contractions) $this->is_cap_diff = $this->allcap_differential($this->words_and_emoticons); } - + /* Remove all punctation from a string */ @@ -38,16 +38,16 @@ function strip_punctuation($string) //$string = strtolower($string); return preg_replace("/[[:punct:]]+/", "", $string); } - + function array_count_values_of($haystack, $needle) { - if (!in_array($needle, $haystack)) { + if (!in_array($needle, $haystack, true)) { return 0; } $counts = array_count_values($haystack); return $counts[$needle]; } - + /* Check whether just some words in the input are ALL CAPS @@ -71,7 +71,7 @@ private function allcap_differential($words) } return $is_different; } - + function _words_only() { $text_mod = $this->strip_punctuation($this->text); @@ -86,9 +86,9 @@ function _words_only() function _words_and_emoticons() { - + $wes = preg_split('/\s+/', $this->text); - + # get rid of residual empty items or single letter words $wes = array_filter($wes, function ($word) { return strlen($word) > 1; @@ -96,16 +96,16 @@ function _words_and_emoticons() //Need to remap the indexes of the array $wes = array_values($wes); $words_only = $this->_words_only(); - + foreach ($words_only as $word) { foreach (self::PUNC_LIST as $punct) { //replace all punct + word combinations with word $pword = $punct .$word; - - + + $x1 = $this->array_count_values_of($wes, $pword); while ($x1 > 0) { - $i = array_search($pword, $wes); + $i = array_search($pword, $wes, true); unset($wes[$i]); array_splice($wes, $i, 0, $word); $x1 = $this->array_count_values_of($wes, $pword); @@ -114,7 +114,7 @@ function _words_and_emoticons() $wordp = $word . $punct; $x2 = $this->array_count_values_of($wes, $wordp); while ($x2 > 0) { - $i = array_search($wordp, $wes); + $i = array_search($wordp, $wes, true); unset($wes[$i]); array_splice($wes, $i, 0, $word); $x2 = $this->array_count_values_of($wes, $wordp);