extract() public method

Extracts all parts of a tweet and returns an associative array containing the extracted elements.
public extract ( ) : array
return array The elements in the tweet.
Exemplo n.º 1
0
 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (self::shouldGenerateInsight('favorited_links', $instance, $insight_date = 'today', $regenerate_existing_insight = true)) {
         $fpost_dao = DAOFactory::getDAO('FavoritePostDAO');
         $favorited_posts = $fpost_dao->getAllFavoritePosts($instance->network_user_id, $instance->network, 40);
         $todays_favorited_posts_with_links = array();
         foreach ($favorited_posts as $post) {
             if (date('Y-m-d', strtotime($post->pub_date)) == date('Y-m-d')) {
                 $post_text = $post->post_text;
                 $text_parser = new Twitter_Extractor($post_text);
                 $elements = $text_parser->extract();
                 if (count($elements['urls'])) {
                     $todays_favorited_posts_with_links[] = $post;
                 }
             }
         }
         $favorited_links_count = count($todays_favorited_posts_with_links);
         if ($favorited_links_count) {
             $verb = '';
             $post_type = '';
             if ($favorited_links_count == 1) {
                 $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " <strong>1 " . $this->terms->getNoun('post') . "</strong> with a link in it.";
             } else {
                 $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " <strong>" . $favorited_links_count . " " . $this->terms->getNoun('post', InsightTerms::PLURAL) . "</strong> with links in them:";
             }
             $this->insight_dao->insertInsightDeprecated("favorited_links", $instance->id, $this->insight_date, "Links you liked:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($todays_favorited_posts_with_links));
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Exemplo n.º 2
0
 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (self::shouldGenerateInsight('link_prompt', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = array('foursquare', 'youtube'), $alternate_day = (int) date('j') % 2)) {
         $post_dao = DAOFactory::getDAO('PostDAO');
         $link_dao = DAOFactory::getDAO('LinkDAO');
         // Check from midnight two days ago until an hour from now
         // (to avoid clock-sync issues)
         $recent_posts = $post_dao->getPostsByUserInRange($instance->network_user_id, $instance->network, date('Y-m-d H:i:s', strtotime('-2 days midnight')), date('Y-m-d H:i:s', strtotime('+1 hour')));
         $posts_with_links = array();
         foreach ($recent_posts as $post) {
             $post_text = $post->post_text;
             $text_parser = new Twitter_Extractor($post_text);
             $elements = $text_parser->extract();
             if (count($elements['urls'])) {
                 $posts_with_links[] = $post;
             }
         }
         $num_posts = $post_dao->countAllPostsByUserSinceDaysAgo($instance->network_user_id, $instance->network, 30);
         $num_links = $link_dao->countLinksPostedByUserSinceDaysAgo($instance->network_user_id, $instance->network, 30);
         if ($num_posts && $num_links / $num_posts > 0.2 && count($recent_posts) && !count($posts_with_links)) {
             $insight_text = $this->username . " hasn't " . $this->terms->getVerb('posted') . " a link in the last 2 days. It may be time to share an interesting link with " . $this->terms->getNoun('friend', InsightTerms::PLURAL) . ".";
             $this->insight_dao->insertInsightDeprecated('link_prompt', $instance->id, $this->insight_date, "Nudge:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Exemplo n.º 3
0
 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (self::shouldGenerateInsight('interactions', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = 3, count($last_week_of_posts), $excluded_networks = array('facebook', 'google+', 'foursquare', 'youtube'))) {
         $user_dao = DAOFactory::getDAO('UserDAO');
         $mentions_count = array();
         $mentions_info = array();
         $insight_data = array();
         foreach ($last_week_of_posts as $post) {
             $post_text = $post->post_text;
             // Extract mentions from post text
             $text_parser = new Twitter_Extractor($post_text);
             $elements = $text_parser->extract();
             $mentions_in_post = $elements['mentions'];
             foreach ($mentions_in_post as $mention_in_post) {
                 if ($mention_in_post == $instance->network_username) {
                     // Don't count metweets
                     continue;
                 } else {
                     $mentioned_user = $user_dao->getUserByName($mention_in_post, $instance->network);
                     if (isset($mentioned_user)) {
                         $mention_in_post = '@' . $mentioned_user->username;
                         $mentions_info[$mention_in_post] = $mentioned_user;
                     } else {
                         $mention_in_post = '@' . $mention_in_post;
                     }
                     // Update mention count
                     if (array_key_exists($mention_in_post, $mentions_count)) {
                         $mentions_count[$mention_in_post]++;
                     } else {
                         $mentions_count[$mention_in_post] = 1;
                     }
                 }
             }
         }
         if (count($mentions_count)) {
             // Get most mentioned user
             arsort($mentions_count);
             $most_mentioned_user = each($mentions_count);
             // Add mentions to dataset
             foreach ($mentions_count as $mention => $count) {
                 $mention_info['mention'] = $mention;
                 $mention_info['count'] = $count;
                 $mention_info['user'] = $mentions_info[$mention];
                 $insight_data[] = $mention_info;
             }
         }
         if (isset($most_mentioned_user)) {
             $insight_text = $this->username . " mentioned " . $most_mentioned_user['key'] . " <strong>" . $this->terms->getOccurrencesAdverb($most_mentioned_user['value']) . "</strong> last week.";
             $this->insight_dao->insertInsightDeprecated('interactions', $instance->id, $this->insight_date, "BFFs:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($insight_data));
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
Exemplo n.º 4
0
 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (self::shouldGenerateInsight('metweet', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = 2, count($last_week_of_posts), $excluded_networks = array('facebook', 'google+', 'foursquare', 'youtube'))) {
         $metweet_count = 0;
         foreach ($last_week_of_posts as $post) {
             if (isset($post->in_retweet_of_post_id)) {
                 $post_text = $post->post_text;
                 $text_parser = new Twitter_Extractor($post_text);
                 $elements = $text_parser->extract();
                 $mentions_in_post = $elements['mentions'];
                 if (in_array($instance->network_username, $mentions_in_post)) {
                     $metweet_count++;
                 }
             }
         }
         if ($metweet_count > 1) {
             $insight_text = $this->username . " retweeted " . $this->username . " mentions " . "<strong>" . $this->terms->getOccurrencesAdverb($metweet_count) . "</strong> last week";
             $insight_baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
             $insight_baseline_dao->insertInsightBaseline("metweet_count", $instance->id, $metweet_count, $this->insight_date);
             $last_monday = date('Y-m-d', strtotime('-7 day'));
             $last_monday_insight_baseline = $insight_baseline_dao->getInsightBaseline("metweet_count", $instance->id, $last_monday);
             if (isset($last_monday_insight_baseline)) {
                 if ($last_monday_insight_baseline->value > $metweet_count) {
                     $difference = $last_monday_insight_baseline->value - $metweet_count;
                     $insight_text .= ", {$difference} fewer time" . ($difference > 1 ? "s" : "") . " than the prior week.";
                 } elseif ($last_monday_insight_baseline->value < $metweet_count) {
                     $difference = $metweet_count - $last_monday_insight_baseline->value;
                     $insight_text .= ", {$difference} more time" . ($difference > 1 ? "s" : "") . " than the prior week.";
                 } else {
                     $insight_text .= ".";
                 }
             } else {
                 $insight_text .= ".";
             }
             $this->insight_dao->insertInsightDeprecated("metweet", $instance->id, $this->insight_date, "Metweets:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }