This package makes using the Google Natural Language API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
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.
composer require joggapp/laravel-natural-language
The package will automatically register itself.
We have documented how to setup the project and get the necessary configurations from the Google Cloud Platform console in a step by step detailed manner over here.
You can publish the config file using the following command:
php artisan vendor:publish --provider="JoggApp\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' => base_path('composer.json'),
];
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
NaturalLanguage::entities(string $text): array
NaturalLanguage::entitySentiment(string $text): array
NaturalLanguage::syntax(string $text): array
NaturalLanguage::categories(string $text): array
features
array & returns an array.NaturalLanguage::annotateText(string $text, array $features = ['sentiment', 'syntax']): array
You can run the tests with:
vendor/bin/phpunit
Please see the CHANGELOG for more information about what has changed recently.
If you discover any security related issues, please email them to [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see the License File for more information.