Example #1
0
 /**
  * Computes the upper case qoeficient.
  * 
  * @param word {@link String} representing the word
  * @return double representing the upper case qoeficient
  */
 public static function computeCapsLockQoef($word)
 {
     if (Eklekt_Emotion_Utility_Heuristics::isCapsLock($word)) {
         return 1.5;
     } else {
         return 1.0;
     }
 }
Example #2
0
 /**
  * Textual affect sensing behavior, the main NLP alghoritm which uses
  * Synesketch Lexicon and several heuristic rules.
  * 
  * @param text
  *            String representing the text to be analysed
  * @return {@link EmotionalState} which represents data recognised from the
  *         text
  * @throws IOException
  */
 public function feel($text)
 {
     $text = str_replace('\\n', ' ', $text);
     $affectWords = array();
     //$sentences = ParsingUtility.parseSentences(text);
     $sentences = preg_split('/[!\\.]+/', $text);
     foreach ($sentences as $sentence) {
         // we imploy 5 heuristic rules to adjust emotive weights of the
         // words:
         // (1) negation in a sentence => flip valence of the affect words in
         // it
         $hasNegation = Eklekt_Emotion_Utility_Heuristics::hasNegation(strtolower($sentence));
         // (2) more exclamination signs in a sentence => more intensive
         // emotive weights
         $exclaminationQoef = Eklekt_Emotion_Utility_Heuristics::computeExclaminationQoef(strtolower($sentence));
         $splittedWords = explode(" ", $sentence);
         $previousWord = "";
         foreach ($splittedWords as $splittedWord) {
             $emoWord = $this->lexUtil->getEmoticonAffectWord($splittedWord);
             if ($emoWord != null) {
                 // (3) more emoticons with more 'emotive' signs (e.g. :DDDD)
                 // => more intensive emotive weights
                 $emoticonCoef = Eklekt_Emotion_Utility_Heuristics::computeEmoticonCoef($splittedWord, $emoWord);
                 $emoWord->adjustWeights($exclaminationQoef * $emoticonCoef);
                 $affectWords[] = $emoWord;
             } else {
                 $words = preg_split('/[^A-Za-z\\-]+/', $splittedWord);
                 if (empty($words)) {
                     $words = array($splittedWord);
                 }
                 foreach ($words as $word) {
                     $emoWord = $this->lexUtil->getAffectWord(strtolower($word));
                     if ($emoWord != null) {
                         // (4) word is upper case => more intensive emotive
                         // weights
                         $capsLockCoef = Eklekt_Emotion_Utility_Heuristics::computeCapsLockQoef($word);
                         // (5) previous word is a intensity modifier (e.g.
                         // "extremly") => more intensive emotive weights
                         $modifierCoef = Eklekt_Emotion_Utility_Heuristics::computeModifier($previousWord);
                         // change the affect word!
                         if ($hasNegation) {
                             $emoWord->flipValence();
                         }
                         $emoWord->adjustWeights($exclaminationQoef * $capsLockCoef * $modifierCoef);
                         $affectWords[] = $emoWord;
                     }
                     $previousWord = $word;
                 }
             }
         }
     }
     return $this->createEmotionalState($text, $affectWords);
 }