function extract_keyword($content, $permalink) { // Set up the text to analyze keyword. // If the length of the feed is not up to quality standards, track down and load the actual article. if (strlen(strip_tags($content)) < 500) { $extracted_text = $this->feed_hunter($permalink)->text; // Make sure the newly loaded feed is up to quality standards. if (strlen(strip_tags($content)) > 500) { $specimen = $extracted_text; } else { $specimen = strip_tags($content); } } else { $specimen = strip_tags($content); } $characters = array('"'); $replacements = array(' '); $text = str_replace($characters, $replacements, $specimen); // Load the AlchemyAPI and configure access key. require_once 'inc/AlchemyAPI.php'; $alchemyObj = new AlchemyAPI(); $alchemyObj->setAPIKey("1414657c7c56cc31a067f8daafabf1d6978c28fe"); // Analyze the article, fetching the concept, keyword, and category of an article. $tags_json = json_decode($alchemyObj->TextGetRankedKeywords($text, 'json')); $concepts_json = json_decode($alchemyObj->TextGetRankedConcepts($text, 'json')); $category = json_decode($alchemyObj->TextGetCategory($text, 'json')); $this->feed_model->alchemy_meter(3); // Parse the result retrieved from AlchemyAPI into an associated array. $tags = array(); foreach ($concepts_json->concepts as $concept) { $characters = array("'"); $replacements = array(""); $output = str_replace($characters, $replacements, $concept->text); $tag['keyword'] = $output; $tag['confidence'] = $concept->relevance; $tag['is_concept'] = TRUE; array_push($tags, $tag); } foreach ($tags_json->keywords as $keyword) { $characters = array("'"); $replacements = array(""); $output = str_replace($characters, $replacements, $keyword->text); $tag['keyword'] = $output; $tag['confidence'] = $keyword->relevance; $tag['is_concept'] = FALSE; array_push($tags, $tag); } // Return the result. $result['tags'] = $tags; $result['category'] = $category->category; return $result; }