Exemple #1
0
 function extract($source)
 {
     // TODO - should remove this default value
     $Bolts_id = Bolts_Registry::get('yahoo_api_Bolts_id');
     $curl_handle = curl_init();
     $keywords = null;
     $all_keywords = null;
     $filter = new Bolts_FilterTags();
     $noisewords = Bolts_NoiseWords::getAll();
     $url = "http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction";
     curl_setopt($curl_handle, CURLOPT_URL, $url);
     curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
     curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl_handle, CURLOPT_POST, 1);
     curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "appid=" . $Bolts_id . "&output=php&context=" . urlencode($source));
     $buffer = curl_exec($curl_handle);
     curl_close($curl_handle);
     $results = unserialize($buffer);
     if (is_array($results['ResultSet'])) {
         if (!is_array($results['ResultSet']['Result'])) {
             $all_keywords = array($results['ResultSet']['Result']);
         } else {
             $all_keywords = $results['ResultSet']['Result'];
         }
     }
     $keywords = array();
     if (is_array($all_keywords)) {
         foreach ($all_keywords as $keyword) {
             // this is probably overkill, but in case I ever need to check for other things, I'm okay.
             $errors = 0;
             if (in_array($keyword, $noisewords)) {
                 $errors++;
             }
             if ($errors == 0) {
                 $keywords[] = $filter->filter($keyword);
             }
         }
     }
     return $keywords;
 }
Exemple #2
0
 static function makeTagArray($tag_string)
 {
     $tags = explode(',', $tag_string);
     $tag_filter = new Bolts_FilterTags();
     $tag_array = array();
     foreach ($tags as $tag) {
         if (trim($tag) != "" and $tag != "none" and !is_null($tag)) {
             $tag = $tag_filter->filter($tag);
             if (!in_array($tag, $tag_array)) {
                 $tag_array[] = $tag;
             }
         }
     }
     return $tag_array;
 }