/laravel-natural-language

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.

Primary LanguagePHPMIT LicenseMIT

Laravel package for the Google Natural language API

Latest Version Build Status Total Downloads

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.

natural

Installation

  • You can install this package via composer using this command:
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'),
];

How to use

  • 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 features array & returns an array.
NaturalLanguage::annotateText(string $text, array $features = ['sentiment', 'syntax']): array

Testing

You can run the tests with:

vendor/bin/phpunit

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 harish@jogg.co instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see the License File for more information.