coxlr/laravel-natural-language
Composer 安装命令:
composer require coxlr/laravel-natural-language
包简介
Laravel package for the Google Natural language API
README 文档
README
This package makes using the Google Natural API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API. All methods accept a string and return an array: Docs below.
It builds upon JoggApp/laravel-natural-language, a package initially developed by Harish Toshniwal which is no longer activly maintained.
Installation
This package requires PHP 8.1 and Laravel 10 or higher.
You can install this package via composer using this command:
composer require coxlr/laravel-natural-language
-
The package will automatically register itself.
-
You can find documentation on how to set up the project and get the necessary configurations from the Google Cloud Platform console in a step by step detailed manner here.
-
You can publish the config file using the following command:
php artisan vendor:publish --provider="Coxlr\NaturalLanguage\NaturalLanguageServiceProvider"
This will create the package's config file called naturallanguage.php in the config directory. These are the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | The id of project created in the Google Cloud Platform console. |-------------------------------------------------------------------------- */ 'project_id' => env('NATURAL_LANGUAGE_PROJECT_ID', 'sample-12345'), /* |-------------------------------------------------------------------------- | Path to the json file containing the authentication credentials. |-------------------------------------------------------------------------- */ 'key_file_path' => env('NATURAL_LANGUAGE_KEY_FILE_PATH', base_path('google-credentials.json')), ];
Add the following to your .env file:
NATURAL_LANGUAGE_PROJECT_ID=your-google-project-id NATURAL_LANGUAGE_KEY_FILE_PATH=/full/path/to/your/google-credentials.json
Important: If you previously published the config file, you will need to update
key_file_pathto use theenv()helper as shown above. Older versions of the config file had a hardcoded default path that did not read from the environment.
Usage
After setting up the config file values you are all set to use the following methods:
- Detect the Sentiment: Accepts a string and returns an array.
NaturalLanguage::sentiment(string $text): array
- Detect the Entities: Accepts a string and returns an array.
NaturalLanguage::entities(string $text): array
- Detect the Sentiment per-entity basis: Accepts a string and returns an array.
NaturalLanguage::entitySentiment(string $text): array
- Detect the syntax: Accepts a string and returns an array.
NaturalLanguage::syntax(string $text): array
- Detect the categories: Accepts a string and returns an array.
NaturalLanguage::categories(string $text): array
- Annotate text: Accepts a string and an optional
featuresarray & returns an array.
NaturalLanguage::annotateText(string $text, array $features = ['sentiment', 'syntax']): array
Testing
You can run the tests with:
composer test
Changelog
Please see the CHANGELOG for more information about what has changed recently.
Security
If you discover any security related issues, please email them to hello@leecox.dev instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.
coxlr/laravel-natural-language 适用场景与选型建议
coxlr/laravel-natural-language 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.51k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「api」 「google」 「laravel」 「natural language」 「coxlr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coxlr/laravel-natural-language 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coxlr/laravel-natural-language 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coxlr/laravel-natural-language 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Simple ASCII output of array data
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Package for view storage in laravel
统计信息
- 总下载量: 1.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-27
