> For the complete documentation index, see [llms.txt](https://calculatedsystems.gitbook.io/cloud-nifi-processors/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calculatedsystems.gitbook.io/cloud-nifi-processors/google-cloud-platform/natural-language-api/analyzesentiment-processor.md).

# AnalyzeSentiment Processor

Part of the GCP Natural Language processor family

This processor takes in an input string and returns information about the sentiment of the text. Sentiment can be thought of as the connotation of the message. This processor will analyze the sentiment of individual sentences as well as the text overall.

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.

The example output is a great example of the strength / sentiment. The message is overall a very positive message, and the output reflects as such.

## Properties

{% hint style="info" %}
All of our Natural Language processors also include these [common properties](/cloud-nifi-processors/google-cloud-platform/natural-language-api.md#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                                          |
| ---------------- | ----------------- | ---------------------------------------------------- |
| sentences        | array of Sentence | The list of all sentences in the message             |
| language         | string            | The language code of the language the message is in. |
| overallSentiment | Sentiment         | The sentiment of the message as a whole              |
| {% endtab %}     |                   |                                                      |

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

#### `Sentence`

| Field Name  | Data Type | Description                                                                                   |
| ----------- | --------- | --------------------------------------------------------------------------------------------- |
| text        | string    | The raw string of the sentence                                                                |
| sentiment   | Sentiment | The sentiment of this sentence                                                                |
| beginOffset | int       | The number of characters from the beginning of the input string to the start of this sentence |

#### `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":{
      "overallSentiment":{
         "score":0.5,
         "magnitude":1.7
      },
      "sentences":[
         {
            "sentiment":{
               "score":0.6,
               "magnitude":0.6
            },
            "text":"James Adams is a fantastic developer who has been on the scene for over ten years."
         },
         {
            "sentiment":{
               "score":0.9,
               "magnitude":0.9
            },
            "text":"His excellent attitude and steady work ethic contribute to his character."
         },
         {
            "sentiment":{
               "score":0.2,
               "magnitude":0.2
            },
            "text":"May he stay with our company for many years to come."
         }
      ],
      "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 %}

###
