echo PHP_EOL; } } else { echo 'Error in the concept tagging call: ', $response['statusInfo']; } echo PHP_EOL; echo PHP_EOL; echo PHP_EOL; echo '############################################', PHP_EOL; echo '# Relation Extraction Example #', PHP_EOL; echo '############################################', PHP_EOL; echo PHP_EOL; echo PHP_EOL; echo 'Processing text: ', $demo_text, PHP_EOL; echo PHP_EOL; $response = $alchemyapi->relations('text', $demo_text, null); if ($response['status'] == 'OK') { echo '## Response Object ##', PHP_EOL; echo print_r($response); echo PHP_EOL; echo '## Relations ##', PHP_EOL; foreach ($response['relations'] as $relation) { if (array_key_exists('subject', $relation)) { echo 'Subject: ', $relation['subject']['text'], PHP_EOL; } if (array_key_exists('action', $relation)) { echo 'Action: ', $relation['action']['text'], PHP_EOL; } if (array_key_exists('object', $relation)) { echo 'Object: ', $relation['object']['text'], PHP_EOL; }
assert($response['status'] == 'ERROR'); //invalid flavor echo 'Language tests complete!', PHP_EOL, PHP_EOL; //Title echo 'Checking title . . . ', PHP_EOL; $response = $alchemyapi->title('text', $test_text, null); assert($response['status'] == 'ERROR'); //title only works on html and url content $response = $alchemyapi->title('html', $test_html, null); assert($response['status'] == 'OK'); $response = $alchemyapi->title('url', $test_url, null); assert($response['status'] == 'OK'); 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');