ollieparsley / corticalio
此软件包已废弃,不再维护。未建议替代软件包。
cortical.io API 的客户端库
v1.0.1
2019-01-01 20:26 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2023-05-29 01:31:57 UTC
README
描述
cortical.io 官方 PHP 库已弃用且不再维护 (https://github.com/cortical-io/php-client-sdk)。因此,由于我需要使用 PHP 服务调用 API,我决定创建此库,以便其他人也可以使用它。
链接
- REST API 文档: https://www.cortical.io/resources_apidocumentation.html
- REST API 控制台: https://api.cortical.io/
- Cortical.io 网站: https://cortical.io/
要求
PHP >= 7.0
用法
安装
推荐使用 composer
composer require ollieparsley/corticalio
发送请求
Retinas
$client = new \Corticalio\Client([
'api_key' => 'MY_API_KEY',
]);
echo "List retinas: \n";
print_r($client->retinas->listRetinas());
echo "\n\n";
echo "Show retina en_associative: \n";
print_r($client->retinas->getRetina('en_associative'));
echo "\n\n";
Terms
$client = new \Corticalio\Client([
'api_key' => 'MY_API_KEY',
]);
echo "List terms: \n";
print_r($client->terms->listTerms('en_associative'));
echo "\n\n";
echo "Show term soccer using en_associative: \n";
print_r($client->terms->getTerm('en_associative', 'soccer'));
echo "\n\n";
echo "Show term contexts for soccer using en_associative: \n";
print_r($client->terms->listTermContexts('en_associative', 'soccer'));
echo "\n\n";
echo "Show similar terms to soccer using en_associative: \n";
print_r($client->terms->listSimilarTerms('en_associative', 'soccer'));
echo "\n\n";
Compare
$client = new \Corticalio\Client([
'api_key' => 'MY_API_KEY',
]);
echo "Compare 2 elements using en_associative: \n";
$element1 = new \Corticalio\Model\ExpressionElement();
$element1->text = 'Manchester City lost the football match';
$element2 = new \Corticalio\Model\ExpressionElement();
$element2->text = 'Manchester United won the football match';
print_r($client->compare->compare('en_associative', $element1, $element2));
echo "\n\n";
echo "Bulk compare element pairs en_associative: \n";
$elementPairs = new \Corticalio\Model\ExpressionElementArray();
$elementPairs->addPair($element1, $element2);
$elementPairs->addPair($element2, $element1);
print_r($client->compare->bulkCompare('en_associative', $elementPairs));
echo "\n\n";
Exceptions
存在一个通用的 Corticalio\Exception
类,它出于某些特定原因被扩展以使用。任何从这个基本异常中抛出的内容都可能是来自依赖项,如 Guzzle。
API 部分
覆盖
这些 API 部分由客户端库覆盖
- Retinas
- Terms
- Compare
待办事项
这些尚未完成。但我确实希望用这些来完成库
- 文本
- 表达式
- 图片
- 分类
版本控制
我们使用 SemVer 进行版本控制。有关可用的版本,请参阅 此存储库上的标签。
作者
贡献
请为此库做出贡献。请提交拉取请求,我会尽力审查它们并在适当的情况下合并。
许可
本项目采用MIT许可协议 - 请参阅LICENSE文件以获取详细信息