darrynten/watson-personality-insights-php
PHP Watson Personality Insights 客户端及附加功能
Requires
- php: ^5.5.9 || ^7.0
- darrynten/any-cache: ^1.0
- guzzlehttp/guzzle: ^6.2.1
Requires (Dev)
- internations/http-mock: ^0.8.1
- mockery/mockery: dev-master
- phpunit/phpunit: ~5.0
This package is auto-updated.
Last update: 2024-09-09 10:30:17 UTC
README
IBM Watson Personality insights API 的一个无框架且完全单元测试的客户端。
适用于 PHP 7.0+
安装
composer require darrynten/watson-personality-insights-php
用法
// Required config $config = [ 'username' => $username, 'password' => $password ]; // Get an instance $instance = new PersonalityInsights($config); // Add some text $text = file_get_contents('sample.txt'); $instance->addText($text); // Get the insights $insights = $instance->getInsights();
您可以设置的一些东西
// Set standard options $instance->config->setConsumptionPreferences(true); $instance->config->setRawScores(true); $instance->config->setVersion('2017-01-01'); $instance->config->setContentTypeHeader('application/json'); $instance->config->setContentLanguageHeader('en'); $instance->config->setAcceptHeader('application/json'); $instance->config->setAcceptLanguageHeader('en'); $instance->config->setCsvHeaders(false); // https://watson-api-explorer.mybluemix.net/apis/personality-insights-v3#!/personality45insights/profile // Set caching of requests $instance->config->setCaching(false); // Opt in to Watson tracking (off by default) $instance->config->setOptOut(false); // All config options $config = [ 'username' => $username, 'password' => $password, 'version' => $version, 'raw_scores' => $boolean, 'consumption_preferences' => $boolean, 'cache' => $boolean, ];
您还可以直接添加一个 ContentItem
/** * All possible content item config options. Only the `text` one is * required. * * https://watson-api-explorer.mybluemix.net/apis/personality-insights-v3#!/personality45insights/profile * * Defaults * * id - An md5 of the text * created - 0 * updated - 0 * contenttype - 'text/plain' * language - en * parentid - null * reply - false * forward - false */ $contentConfig = [ 'text' => $text, // The only required value 'id' => $string, // Is the md5 of the text if not set 'created' => $timestamp, // Is 0 if not set 'updated' => $timestamp, // Is 0 if not set 'contenttype' => $string, // `text/plain` or `text/html` 'language' => $string, // `en` or similar 'parentid' => $string, // The ID of a parent item. Null if not set 'reply' => $boolean, // Indicates if it is a reply to another 'forward' => $boolean, // Indicates if it is a forwarded text ]; $contentItem = new ContentItem($contentConfig); $contentItem->getContentItemJson(); $instance->addNewContentItem($contentItem);
注意
隐私
IBM 有一种模式,会将您的数据保存在他们那里,用于 Watson 的训练。这通常是默认不选择的。
由于这并没有明确说明,我们决定默认禁用,如果您想帮助 Watson 学习,可以像上面示例中那样选择启用。
默认情况下,此软件包不会允许任何类型的跟踪。
“版本”
这引起了一些混淆。这是一个 'YYYY-MM-DD' 格式的日期,Watson 将使用那个时间点存在的任何版本。
完整引用
请求的响应格式版本作为 'YYYY-MM-DD' 格式的日期;例如,指定 2016-10-20 表示 2016 年 10 月 20 日。您指定的日期不需要与服务版本完全匹配;服务将以不晚于您提供的日期的版本响应。如果您指定的日期早于版本 3 的初始发布,服务将返回该第一个版本的响应格式。如果您指定的日期在未来或晚于最新版本,服务将返回最新版本的响应格式。
凭证
您可以从 json
文件中下载您的凭证,或从开发者控制台获取。
单元测试
测试覆盖率是 100%,但您也可以包含一个实时 API 测试,以查看是否一切正常。您通常不需要这样做,但可能会有用。
进行实时测试导出
export DO_LIVE_API_TESTS=true
您还必须在项目根目录中包含您的真实 credentials.json
文件(它已在 gitignore
中)。
这将执行实时测试。
尚未支持
- 从 ContentItems 集合中删除
- 在 ContentItems 集合中修改
- 完整的错误和异常处理
- 结果操作
- 最小文本长度配置
- CSV
贡献和测试
项目当前有 100% 的测试覆盖率,请确保在贡献时更新测试。更多信息请参阅 CONTRIBUTING.md。
致谢
- Dmitry Semenov,一如既往。
- 在此处添加您自己!