# AnalyzeEntitiesWithSentiment Processor

This processor takes in an input string and returns textual references to real world items (such as names, places, etcetera). This processor has an added feature compared to the "standard" [AnalyzeEntities](https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/analyzeentities-processor) processor, which is that each entity will also have a sentiment attached to it. This sentiment represents how that particular entity is spoken about (positively or negatively) in the text.

The resulting Sentiments are reported with two values: `score` and `magnitude`. Per the [official documentation](https://cloud.google.com/natural-language/docs/basics#sentiment_analysis):

> `score` ranges from -1.0 (negative sentiment) to 1.0 (positive sentiment)\
> `magnitude` indicates the overall strength of the emotion (both positive and negative)

This means that, for example, a sentence with a sentiment that has a score of 0.8 and a magnitude of 1.7 means it's a very strongly positive message. Similarly, a sentiment with a score of -0.2 with a magnitude of 0.2 is likely a "lightly" negative message.

## Properties

{% hint style="info" %}
All of our Natural Language processors also include these [common properties](https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/..#common-properties).
{% endhint %}

This processor does not have any unique properties outside of the common ones.

## Data Output

{% tabs %}
{% tab title="Output Format" %}

| Field Name   | Data Type       | Description                                              |
| ------------ | --------------- | -------------------------------------------------------- |
| entities     | array of Entity | The list of entities found by the API                    |
| language     | string          | The language code of the language the input string is in |
| {% endtab %} |                 |                                                          |

{% tab title="Relevant Data Structures" %}

#### `Entity`

| Field Name | Data Type                                                                                                                                 | Description                                                                                                                                                     |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| mentions   | array of Mention                                                                                                                          | The words/tokens that relate to this entity                                                                                                                     |
| type       | string ([EntityType](https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/entity-types)) | This entity's classifier type                                                                                                                                   |
| sentiment  | Sentiment                                                                                                                                 | The sentiment of this entity within the text                                                                                                                    |
| metadata   | any                                                                                                                                       | [*See section on the metadata field*](https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/the-metadata-field) |

#### `Mention`

| Field Name  | Data Type                                                                                                                                 | Description                                                                                                 |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| text        | string                                                                                                                                    | The raw text of the mention                                                                                 |
| beginOffset | int                                                                                                                                       | The numer of characters from the beginning of the input string to the beginning of the text of this mention |
| type        | string ([EntityType](https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/entity-types)) | The type of mention this is. They follow the same names and descriptions as EntityTypes.                    |

#### `Sentiment`

| Field Name   | Data Type | Description                                                                                                                                                                                                                          |
| ------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| score        | float     | A number ranging from -1.0 (negative sentiment) to 1.0 (positive sentiment)                                                                                                                                                          |
| magnitude    | float     | A number ranging from 0 to +inf representing the absolute magnitude of the sentiment (regardless of score). This number can be thought of as the strength of the emotion (e.g., something being very positive, or slightly negative) |
| {% endtab %} |           |                                                                                                                                                                                                                                      |

{% tab title="Example Output" %}

```javascript
{
   "output":{
      "entities":[
         {
            "metadata":{
               "wikipedia_url":"https:\/\/en.wikipedia.org\/wiki\/James_Adams_(entrepreneur)",
               "mid":"\/m\/0136zb57"
            },
            "mentions":[
               {
                  "sentiment":{
                     "score":0.9,
                     "magnitude":0.9
                  },
                  "text":"James Adams",
                  "type":"PROPER",
                  "beginOffset":-1
               },
               {
                  "sentiment":{
                     "score":0.9,
                     "magnitude":0.9
                  },
                  "text":"developer",
                  "type":"COMMON",
                  "beginOffset":-1
               }
            ],
            "type":"PERSON"
         },
         {
            "metadata":{

            },
            "mentions":[
               {
                  "sentiment":{
                     "score":0.0,
                     "magnitude":0.0
                  },
                  "text":"scene",
                  "type":"COMMON",
                  "beginOffset":-1
               }
            ],
            "type":"LOCATION"
         },
         {
            "metadata":{

            },
            "mentions":[
               {
                  "sentiment":{
                     "score":0.9,
                     "magnitude":0.9
                  },
                  "text":"attitude",
                  "type":"COMMON",
                  "beginOffset":-1
               }
            ],
            "type":"OTHER"
         },
         {
            "metadata":{

            },
            "mentions":[
               {
                  "sentiment":{
                     "score":0.9,
                     "magnitude":0.9
                  },
                  "text":"work ethic",
                  "type":"COMMON",
                  "beginOffset":-1
               }
            ],
            "type":"OTHER"
         },
         {
            "metadata":{

            },
            "mentions":[
               {
                  "sentiment":{
                     "score":0.0,
                     "magnitude":0.0
                  },
                  "text":"company",
                  "type":"COMMON",
                  "beginOffset":-1
               }
            ],
            "type":"ORGANIZATION"
         },
         {
            "metadata":{

            },
            "mentions":[
               {
                  "sentiment":{
                     "score":0.5,
                     "magnitude":0.5
                  },
                  "text":"character",
                  "type":"COMMON",
                  "beginOffset":-1
               }
            ],
            "type":"PERSON"
         }
      ],
      "language":"en"
   },
   "raw-input":"James Adams is a fantastic developer who has been on the scene for over ten years. His excellent attitude and steady work ethic contribute to his character. May he stay with our company for many years to come."
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/analyzeentitieswithsentiment-processor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
