https://github.com/hellostealth/stealth-aws-comprehend
Built-in NLP for Stealth bots via AWS Comprehend
https://github.com/hellostealth/stealth-aws-comprehend
Last synced: about 1 year ago
JSON representation
Built-in NLP for Stealth bots via AWS Comprehend
- Host: GitHub
- URL: https://github.com/hellostealth/stealth-aws-comprehend
- Owner: hellostealth
- Created: 2018-04-27T04:40:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-08T05:25:03.000Z (almost 6 years ago)
- Last Synced: 2024-08-09T10:15:55.561Z (over 1 year ago)
- Language: Ruby
- Size: 37.1 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Stealth Amazon Comprehend
This gem provides NLP via the [AWS Comprehend](https://aws.amazon.com/comprehend/) service. It integrates with the [Stealth](https://github.com/hellostealth/stealth) Controller to provide NLP against `current_message`.
[](https://badge.fury.io/rb/stealth-aws-comprehend)
## Setup
To use AWS Comprehend, set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables to your AWS account credentials. You may also want to optionally set your preferred AWS region by setting the environment variable `AWS_REGION`. That's the only setup required!
## Using NLP
This gem adds the following methods to `current_message`:
1. `language` identifies text written in over 100 languages and returns the dominant language in `current_message` with a confidence score
2. `entities` returns the named entities ("People," "Places," "Locations," etc.) present in `current_message`
3. `key_phrases` returns the key phrases or talking points and a confidence score to support for the `current_message`
4. `sentiment` returns the overall sentiment (Positive, Negative, Neutral, or Mixed) for the `current_message`
5. `sentiment_score` returns the scoring for each sentiment (Positive, Negative, Neutral, or Mixed) for the `current_message`
If `current_message.message` is not available, each of these will return `nil`.
The following examples are run on `current_message.message` when it is equal to `"I bought a brand new Craftsman Drill at Home Depot."`.
### language
`current_message.language` will return an Array of dominate languages:
```ruby
languages = [#]
languages.first.language_code # "en"
languages.first.score # 0.9921924471855164
```
### entities
`current_message.entites` will return an Array of entities:
```ruby
entities = [#, #]
entities.first.text # "Craftsman"
entities.first.score # 5775995850563049
entities.first.type # ORGANIZATION
```
### key_phrases
`current_message.key_phrases` will return an Array of key phrases:
```ruby
key_phrases = [#, #]
key_phrases.first.text # "a brand new Craftsman Drill"
key_phrases.first.score # 0.965133786201477
```
### sentiment
`current_message.sentiment` will return the dominate sentiment of the message:
```ruby
current_message.sentiment # "NEUTRAL"
```
### sentiment_score
`current_message.sentiment_score` will return the scoring for each sentiment of the message:
```ruby
sentiment_scores = #
sentiment_scores.positive # 0.0249068271368742
sentiment_scores.negative # 0.012575631029903889
sentiment_scores.neutral # 0.9605817794799805
sentiment_scores.mixed # 0.0019358232384547591
```
## AWS Usage
Loading this gem into your bot doesn't automatically issue API requests to your AWS account. API requests are lazily made each time you call one of the above methods. One exception is `sentiment` and `sentiment_score` which share an API call and so that only a single API call is made between the two.