PHPackages                             michaeljwright/aws-comprehend - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. michaeljwright/aws-comprehend

Abandoned → aws-sdk-php-laravelLibrary[API Development](/categories/api)

michaeljwright/aws-comprehend
=============================

A Laravel package for the AWS Comprehend

v1.1(7y ago)427.3k↓43.3%1[1 PRs](https://github.com/michaeljwright/aws-comprehend/pulls)MITPHP

Since Jun 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/michaeljwright/aws-comprehend)[ Packagist](https://packagist.org/packages/michaeljwright/aws-comprehend)[ RSS](/packages/michaeljwright-aws-comprehend/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

A Laravel package/facade for Amazon Comprehend, part of AWS API PHP SDK.

Amazon Comprehend is a natural language processing (NLP) service that uses machine learning to find insights and relationships in text. It's great for running sentiment analysis on batches of documents.

This repository implements a simple Service Provider of the AWS Comprehend client, and makes it easily accessible via a Facade in Laravel &gt;= 5.

- See docs for usage ([https://docs.aws.amazon.com/comprehend/latest/dg/API\_Reference.html](https://docs.aws.amazon.com/comprehend/latest/dg/API_Reference.html))

Also see [AWS Comprehend](https://aws.amazon.com/comprehend/) for more information.

Requirements
------------

[](#requirements)

Create an account at [AWS](https://aws.amazon.com/console/) and take note of your API keys.

Installation using [Composer](https://getcomposer.org)
------------------------------------------------------

[](#installation-using-composer)

In your terminal application move to the root directory of your laravel project using the cd command and require the project as a dependency using composer.

composer require michaeljwright/aws-comprehend

This will add the following lines to your composer.json and download the project and its dependencies to your projects ./vendor directory:

```
//

./composer.json
{
    "name": "michaeljwright/aws-comprehend",
    "description": "A Laravel package for the AWS Comprehend",

    // ...

    "require-dev": {
        "phpunit/phpunit": "~5.7",
        "orchestra/testbench": "~3.0"
        // ...
    },
    "require": {
        "aws/aws-sdk-php":"~3.0"
    },

    //...
}
```

Setup / Configuration
---------------------

[](#setup--configuration)

In order to use the static interface we must customize the application configuration to tell the system where it can find the new service. Open the file config/app.php and add the following lines (\[a\], \[b\]):

```
// config/app.php

return [

    // ...

    'providers' => [

        // ...

        /*
         * Package Service Providers...
         */
        MichaelJWright\Comprehend\ComprehendServiceProvider::class, // [a]

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

    ],

    // ...

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,

        // ...

        'Comprehend' => 'MichaelJWright\Comprehend\ComprehendFacade', // [b]
        'Hash' => Illuminate\Support\Facades\Hash::class,

        // ...
    ],

];
```

Publish Vendor
--------------

[](#publish-vendor)

aws-comprehend requires a connection configuration. To get started, you'll need to publish all vendor assets running:

php artisan vendor:publish

This will create a config/comprehend.php file in your app that you can modify to set your configuration. Make sure you add relevant environment variables which are referenced in the comprehend.php file.

*IMPORTANT* It's very important to edit your AWS IAM for the specified key/secret/region to include the Amazon Comprehend API. Otherwise nothing will work.

Usage
-----

[](#usage)

Now you should be able to use the facade within your application.

*IMPORTANT* There is a limit of 25 comments (what AWS calls documents) for each API call.

For example:

```
$config = [
       'LanguageCode' => 'en',
       'TextList' => ['This is good', 'This is bad'],
   ];

$jobSentiment = \Comprehend::batchDetectSentiment($config);

dd($jobSentiment['ResultList']);
```

Example to detect Sentiment from a given array containing strings (comments)
----------------------------------------------------------------------------

[](#example-to-detect-sentiment-from-a-given-array-containing-strings-comments)

```
// FIRST create a function to call the comprehend facade and parse the results (below will return an array with the overall sentiment as well as positive/negative scores)

public function sentimentAnalysis($comments) {

    $results = array();

    if(count($comments)>0) {
        $config = [
               'LanguageCode' => 'en',
               'TextList' => $comments,
           ];

        $jobSentiment = \Comprehend::batchDetectSentiment($config);

        $positive = array();
        $negative = array();

        if(count($jobSentiment['ResultList'])) {
            foreach($jobSentiment['ResultList'] as $result){
                $positive[] = $result['SentimentScore']['Positive'];
                $negative[] = $result['SentimentScore']['Negative'];
            }
        }

        $results['positive'] = array_sum($positive)/count($positive);
        $results['negative'] = array_sum($negative)/count($negative);
        $results['sentiment'] = ($results['positive'] > $results['negative'] ? 'POSITIVE' : 'NEGATIVE');

        return $results;
    } else {
        return $results['sentiment'] = 'INVALID';
    }
}

// SECOND create an array of comments for the analysis and call the above function

$comments = [
    'I think this is very good considering I created a package/wrapper for Amazon Comprehend. Yay me!',
    'Oh my good this is such a bloody rubbish package/wrapper. I hope the author stops coding immediately.',
    'This is really good, I really love this stand by this',
    'This is sooooo bad'
];

dd($this->sentimentAnalysis($comments));
```

Testing
-------

[](#testing)

Unit Tests are created with PHPunit and orchestra/testbench, they can be ran with ./vendor/bin/phpunit.

Contributing
------------

[](#contributing)

Find an area you can help with and do it. Open source is about collaboration and open participation. Try to make your code look like what already exists or better and submit a pull request. Also, if you have any ideas on how to make the code better or on improving the scope and functionality please contact any of the contributors.

License
-------

[](#license)

MIT License.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

2897d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8090690?v=4)[Mike Wright](/maintainers/michaeljwright)[@michaeljwright](https://github.com/michaeljwright)

---

Top Contributors

[![michaeljwright](https://avatars.githubusercontent.com/u/8090690?v=4)](https://github.com/michaeljwright "michaeljwright (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/michaeljwright-aws-comprehend/health.svg)

```
[![Health](https://phpackages.com/badges/michaeljwright-aws-comprehend/health.svg)](https://phpackages.com/packages/michaeljwright-aws-comprehend)
```

###  Alternatives

[sociallydev/spaces-api

Library for accessing Digital Ocean spaces

218428.6k](/packages/sociallydev-spaces-api)[thephalcons/amazon-webservices-bundle

A Symfony2 Bundle for interfacing with Amazon Web Services (AWS)

110224.7k](/packages/thephalcons-amazon-webservices-bundle)[keboola/storage-api-client

Keboola Storage API PHP Client

10387.5k25](/packages/keboola-storage-api-client)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[cion/laravel-text-to-speech

This package creates a shared API to easily use Text to Speech functionalities amongst different TTS providers.

4228.3k](/packages/cion-laravel-text-to-speech)[larareko/aws-rekognition

A Laravel package for the AWS Rekognition

2013.1k](/packages/larareko-aws-rekognition)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
