textrazor / textrazor-php
TextRazor 文本分析 API 的 PHP SDK
1.0.1
2022-03-08 11:21 UTC
Requires
- php: >=5.6.0
- ext-curl: *
This package is auto-updated.
Last update: 2024-09-08 21:37:06 UTC
README
TextRazor Text Analytics API 的 PHP SDK。
TextRazor 通过简单的 API 提供了最先进的自然语言处理工具,让您能够在几分钟内将语义技术集成到您的应用程序中。
数百个应用程序依赖 TextRazor 在各个领域理解非结构化文本,包括社交媒体监控、企业搜索、推荐系统和广告定位。
有关 TextRazor API 的更多信息,请访问 https://www.textrazor.com。
入门
- 从 https://www.textrazor.com 获取免费的 API 密钥。
经典方法
- 将文件
TextRazor.php
复制到您的项目中,并通过require_once 'TextRazor.php';
加载类。
Composer 方法
composer require textrazor/textrazor-php
示例
- 创建 TextRazor 对象的实例,并开始分析您的文本。
<?php require_once 'TextRazor.php'; // This is only required if you are **NOT** using Composer! TextRazorSettings::setApiKey('YOUR_API_KEY_HERE'); $text = 'Barclays misled shareholders and the public about one of the biggest investments in the banks history, a BBC Panorama investigation has found.'; $textrazor = new TextRazor(); $textrazor->addExtractor('entities'); $response = $textrazor->analyze($text); if (isset($response['response']['entities'])) { foreach ($response['response']['entities'] as $entity) { print_r($entity['entityId'] . PHP_EOL); } }
文档
请访问 TextRazor PHP 参考。
错误处理
在输入错误、TextRazor 错误或网络错误的情况下,TextRazor PHP SDK 会抛出一个包含有用错误信息的异常。
编码
TextRazor 期望所有文本都编码为 UTF-8。请在调用 analyze
方法之前确保所有内容都编码为有效的 UTF-8,否则服务将返回错误。
响应
PHP 使得操作服务器返回的 JSON 响应变得非常简单。您可以在 https://www.textrazor.com/docs/rest 上找到有关各种字段的更多信息。
附录
如果您有任何疑问,请通过 support@textrazor.com 联系我们,我们将尽快回复您。如果您有任何改进 API 或文档的想法,我们也非常愿意听取您的意见。