PHP
SDK使用指南
请参考 开始使用
NLP基础服务2.0依赖
composer require alibabacloud/alinlp-20200629
代码示例
<?php
namespace demo;
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\SDK\Alinlp\V20200629\Alinlp;
use AlibabaCloud\SDK\Alinlp\V20200629\Models\GetNerChEcomRequest;
use Darabonba\OpenApi\Models\Config;
$config = new Config();
$config->accessKeyId = "<your-access-key-id>";
$config->accessKeySecret = "<your-access-key-secret>'";
$config->regionId = "cn-hangzhou";
$config->endpoint = "alinlp.cn-hangzhou.aliyuncs.com";
$client = new Alinlp($config);
$request = new GetNerChEcomRequest();
$request->serviceCode = 'alinlp';
$request->text = '电动多功能磨浆机';
try {
$response = $client->getNerChEcom($request);
$json_string = json_encode($response->body, JSON_UNESCAPED_UNICODE);
echo $json_string;
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}
注:代码GetNerChEcomRequest
中的GetNerChEcom
是算法的actionName,可以替换成您需要的算法的值,可以在API参考文档中的请求参数-Action-示例值中找到;
示例:需要调用基础版-中文分词-通用,进入中文分词(基础版),复制下图中的示例值,将GetNerChEcomRequest
替换为GetWsChGeneralRequest
;替换后要注意算法的请求参数也要更改,参考API文档即可。
调用异常自助排查
若调用过程中出现了异常可对照调用异常自助排查(错误码汇总),找到表格中对应的描述,描述中包含具体错误原因和解决方案