/**
  * Find attributes depending on a type
  * @param $limitWords
  * @param $type With positive / negative words = 1, From the training set = 0
  * @return array
  */
 private function findAttributes($limitWords, $type)
 {
     //Step 1: clean tweet and save in field tweet2
     $this->extractfromtweet();
     $attributesList = array();
     //Step 2: obtain attributes from tweet2
     if ($type == 1) {
         $objTweet = Tweetlab4::model()->findAll();
         foreach ($objTweet as $tweet) {
             $tweetAttributes = explode(" ", $tweet->tweet2);
             foreach ($tweetAttributes as $tweetAttr) {
                 $tweetWord = strtolower(trim($tweetAttr));
                 if ($tweetWord != '') {
                     $objWordCount = Word::model()->count('word = :word', array(':word' => $tweetWord));
                     if ($objWordCount > 0) {
                         if (isset($attributesList[$tweetWord])) {
                             $attributesList[$tweetWord]++;
                         } else {
                             $attributesList[$tweetWord] = 1;
                         }
                     }
                 }
             }
         }
         //Step 3: sort array from high to low
         arsort($attributesList);
         $mergedAttributesList = array();
         $counter = 1;
         foreach ($attributesList as $attribute => $value) {
             if (!in_array($attribute, $mergedAttributesList)) {
                 array_push($mergedAttributesList, $attribute);
             }
             $counter++;
             if ($counter > $limitWords) {
                 break;
             }
         }
     } else {
         foreach ($this->arrSentiment as $sentiment => $label_sentiment) {
             $attributesList[$sentiment] = array();
             $objTweet = Tweetlab4::model()->findAll('sentiment = :sentiment', array(':sentiment' => $sentiment));
             foreach ($objTweet as $tweet) {
                 $tweetAttributes = explode(" ", $tweet->tweet2);
                 foreach ($tweetAttributes as $tweetAttr) {
                     $tweetWord = strtolower(trim($tweetAttr));
                     if ($tweetWord != '') {
                         if ($type == 1) {
                             $objWordCount = Word::model()->count('word = :word', array(':word' => $tweetWord));
                             if ($objWordCount > 0) {
                                 if (isset($attributesList[$sentiment][$tweetWord])) {
                                     $attributesList[$sentiment][$tweetWord]++;
                                 } else {
                                     $attributesList[$sentiment][$tweetWord] = 1;
                                 }
                             }
                         } else {
                             if (isset($attributesList[$sentiment][$tweetWord])) {
                                 $attributesList[$sentiment][$tweetWord]++;
                             } else {
                                 $attributesList[$sentiment][$tweetWord] = 1;
                             }
                         }
                     }
                 }
             }
             //Step 3: sort array from high to low
             arsort($attributesList[$sentiment]);
         }
         $mergedAttributesList = array();
         foreach ($this->arrSentiment as $sentiment => $label_sentiment) {
             $counter = 1;
             foreach ($attributesList[$sentiment] as $attribute => $value) {
                 if (!in_array($attribute, $mergedAttributesList)) {
                     array_push($mergedAttributesList, $attribute);
                 }
                 $counter++;
                 if ($counter > $limitWords) {
                     break;
                 }
             }
         }
     }
     return array($attributesList, $this->arrSentiment, $mergedAttributesList);
 }