Beispiel #1
0
    }
} else {
    echo 'Error in the sentiment analysis call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo '############################################', PHP_EOL;
echo '#   Targeted Sentiment Analysis Example    #', PHP_EOL;
echo '############################################', PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo 'Processing text: ', $demo_text, PHP_EOL;
echo 'Target: Denver, Colorado', PHP_EOL;
echo PHP_EOL;
$response = $alchemyapi->sentiment_targeted('text', $demo_text, 'Denver', null);
if ($response['status'] == 'OK') {
    echo '## Response Object ##', PHP_EOL;
    echo print_r($response);
    echo PHP_EOL;
    echo '## Targeted Sentiment ##', PHP_EOL;
    echo 'sentiment: ', $response['docSentiment']['type'], PHP_EOL;
    if (array_key_exists('score', $response['docSentiment'])) {
        echo 'score: ', $response['docSentiment']['score'], PHP_EOL;
    }
} else {
    echo 'Error in the targeted sentiment analysis call: ', $response['statusInfo'];
}
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
Beispiel #2
0
echo 'Concept tests complete!', PHP_EOL, PHP_EOL;
//Sentiment
echo 'Checking sentiment . . . ', PHP_EOL;
$response = $alchemyapi->sentiment('text', $test_text, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment('html', $test_html, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment('url', $test_url, null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment('random', $test_url, null);
assert($response['status'] == 'ERROR');
//invalid flavor
echo 'Sentiment tests complete!', PHP_EOL, PHP_EOL;
//Sentiment Targeted
echo 'Checking targeted sentiment . . . ', PHP_EOL;
$response = $alchemyapi->sentiment_targeted('text', $test_text, 'heart', null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment_targeted('html', $test_html, 'language', null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment_targeted('url', $test_url, 'Congress', null);
assert($response['status'] == 'OK');
$response = $alchemyapi->sentiment_targeted('random', $test_url, 'Congress', null);
assert($response['status'] == 'ERROR');
//invalid flavor
$response = $alchemyapi->sentiment_targeted('text', $test_text, null, null);
assert($response['status'] == 'ERROR');
//missing target
echo 'Targeted sentiment tests complete!', PHP_EOL, PHP_EOL;
//Text
echo 'Checking clean text . . . ', PHP_EOL;
$response = $alchemyapi->text('text', $test_text, null);