darrynten/google-natural-language-php
Composer 安装命令:
composer require darrynten/google-natural-language-php
包简介
PHP Google Natural Language Client with Extras
README 文档
README
An unofficial, fully unit tested Google Natural Language PHP client with extra sugar.
Why not just use the official one?
The official one is great, and we actually use it in this package, it just doesn't quite have the sort of features we needed, so we wrapped it up with some extra bits.
What extra features?
Cost Cutters
The Google Natural Language API costs money. If you're doing anything with it at scale, you're going to have to keep an eye on your calls to make sure things aren't running away with you. I learnt this the hard way. It can get expensive.
That's why we introduced some cost cutting features.
Caching Requests
By default this package caches your requests, something you would have to usually do yourself.
It caches using a framework-agnostic approach, whereby it leverages any host frameworks caching mechanism, and falls back to a temporary cache if there is no cache available.
The supported frameworks are detailed in the AnyCache project.
Examples include Laravel, Symfony, Doctrine, Psr6 and more.
This feature is on by default and can easily be disabled.
Cheapskate Mode
While not immediately clear, the Google Natural Language API charges per 1000 characters.
We've added "cheapskate mode" that, if set, automatically truncates the desired text, saving you another credit.
This feature is on by default and can easily be disabled.
Conveniences
There are a few other conveniences like being able to set the type, language, encoding etc.
One use case would be running a single instance of text through multiple language attempts.
Usage
use DarrynTen\GoogleNaturalLanguagePhp\GoogleNaturalLanguage; // Config options $config = [ 'projectId' => 'my-awesome-project' // At the very least ]; // Make a processor $language = new GoogleNaturalLanguage($config); // Set text $text = 'Google Natural Language processing is awesome!'; $language->setText($text); // Get stuff $language->getEntities(); $language->getSyntax(); $language->getSentiment(); // Get all stuff $language->getAll(); // Set optional things $language->setType('HTML'); $language->setLanguage('en'); $language->setEncodingType('UTF16'); // Extra features $language->setCaching(false); $language->setCheapskate(false); // Full config options $config = [ 'projectId' => 'my-awesome-project', // required 'authCache' => \CacheItemPoolInterface, // stores access tokens 'authCacheOptions' => $array, // cache config 'authHttpHandler' => callable(), // psr-7 auth handler 'httpHandler' => callable(), // psr-7 rest handler 'keyFile' => $json, // content 'keyFilePath' => $string, // path 'retries' => 3, // default is 3 'scopes' => $array, // app scopes 'cache' => $boolean, // cache 'cheapskate' => $boolean // limit text to 1000 chars ]; // authCache, authCacheOptions, authHttpHandler and httpHandler are not // currently implemented.
See The Google Cloud Docs for more on these options and their usage.
Options
setType($type)- EitherPLAIN_TEXT(default) orHTMLsetEncodingType($type)- EitherUTF8(default)UTF16,UTF32orNONEsetLanguage($language)- Either ISO (en,es) or BCP-47 (en-ZA,en-GB).
If no language is provided then it is autodetected from the text and is returned with the response.
Missing Features
Feel free to open a PR!
Usage of Google\Cloud\Storage\StorageObject is presently not possible.
- Custom
authCacheandauthCacheOptions - Custom
httpHandlerandauthHttpHandler
Entity Sentiment
You can retrieve the sentiment of some text
$instance = new GoogleNaturalLanguage($config);
$instance->setText('A duck and a cat in a field at night');
$sentiment = $instance->getEntitySentiment();
Roadmap
- - Get Entities of Type - Will allow the ability to retrieve, for example, only the People, or only the Locations
- - Sentiment shortcuts (is positive etc)
- - Check for types, has location etc
- - And more!
Acknowledgements
-
Dmitry Semenov for being such a legend.
-
Bradley Weston for coming out of nowhere.
-
blaisedufrain for the sentiment analysis.
-
Open a PR and put yourself here :)
darrynten/google-natural-language-php 适用场景与选型建议
darrynten/google-natural-language-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.48k 次下载、GitHub Stars 达 77, 最近一次更新时间为 2017 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 darrynten/google-natural-language-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 darrynten/google-natural-language-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 77
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2017-02-12