/** * @return string */ public function getCategoryFor($text) { $info = $this->alchemy->category('text', $text); if (isset($info['category'])) { return $info['category']; } }
echo PHP_EOL; } } else { echo 'Error in the relation extraction call: ', $response['statusInfo']; } echo PHP_EOL; echo PHP_EOL; echo PHP_EOL; echo '############################################', PHP_EOL; echo '# Text Categorization Example #', PHP_EOL; echo '############################################', PHP_EOL; echo PHP_EOL; echo PHP_EOL; echo 'Processing text: ', $demo_text, PHP_EOL; echo PHP_EOL; $response = $alchemyapi->category('text', $demo_text, null); if ($response['status'] == 'OK') { echo '## Response Object ##', PHP_EOL; echo print_r($response); echo PHP_EOL; echo '## Category ##', PHP_EOL; echo 'text: ', $response['category'], PHP_EOL; echo 'score: ', $response['score'], PHP_EOL; } else { echo 'Error in the text categorization call: ', $response['statusInfo']; } echo PHP_EOL; echo PHP_EOL; echo PHP_EOL; echo '############################################', PHP_EOL; echo '# Language Detection Example #', PHP_EOL;
echo 'Title tests complete!', PHP_EOL, PHP_EOL; //Relations echo 'Checking relations . . . ', PHP_EOL; $response = $alchemyapi->relations('text', $test_text, null); assert($response['status'] == 'OK'); $response = $alchemyapi->relations('html', $test_html, null); assert($response['status'] == 'OK'); $response = $alchemyapi->relations('url', $test_url, null); assert($response['status'] == 'OK'); $response = $alchemyapi->relations('random', $test_url, null); assert($response['status'] == 'ERROR'); //invalid flavor echo 'Relations tests complete!', PHP_EOL, PHP_EOL; //Category echo 'Checking category . . . ', PHP_EOL; $response = $alchemyapi->category('text', $test_text, null); assert($response['status'] == 'OK'); $response = $alchemyapi->category('html', $test_html, array('url' => 'test')); assert($response['status'] == 'OK'); $response = $alchemyapi->category('url', $test_url, null); assert($response['status'] == 'OK'); $response = $alchemyapi->category('random', $test_url, null); assert($response['status'] == 'ERROR'); //invalid flavor echo 'Category tests complete!', PHP_EOL, PHP_EOL; //Feeds echo 'Checking feeds . . . ', PHP_EOL; $response = $alchemyapi->feeds('text', $test_text, null); assert($response['status'] == 'ERROR'); //feeds only works on html and url content $response = $alchemyapi->feeds('html', $test_html, array('url' => 'test'));