Reputation: 131
I recently updated from version 1 of the AWS SDK for PHP to version 3 of the AWS SDK so that I could start testing scripts using the Comprehend and Textract applications. I was able to connect through version 3 and utilize S3 using the "new S3Client()" command. There's extensive documentation regarding functions for Comprehend and Textract, but I can't figure out what the similar new client string is for each service. I've tried:
$cc = new comprehendClient();
$cc = new AWSComprehend();
$cc = new createComprehend();
and more and none of these have worked. If anyone can recommend a fix that would be really helpful. Likewise, if there's an online code repository I should look at that would be helpful. I see plenty of code samples for S3, but none for other applications (at least with SDK for PHP).
Thanks!
Upvotes: 2
Views: 1720
Reputation: 3180
From the AWS Comprehend PHP documentation provided, a Comprehend client can be instantiated and called like below :
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
use Aws\Comprehend\ComprehendClient;
/**
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
$ComprehendClient = \Aws\Comprehend\ComprehendClient::factory(array(
'credentials' => [
'key' => 'AKIAXXXXXX',
'secret' => '+TsIDxxxxxxx',
],
'region' => 'us-east-1',
'version' => 'latest',
));
$result = $ComprehendClient->detectDominantLanguage([
'Text' => "Nakabibili pala ng durian sa U.S. supermarkets kasama ng mga epol. Galing siguro sa Thailand.", // REQUIRED
]);
echo $result;
Upvotes: 4