Sentiment Analysis

The /sentiment_analysis endpoint retrieves the sentiment behind a piece of text. It determines whether the text is positive, negative, or neutral. It is powered by AFINN-165 wordlist. Thus, it is not very advanced, and will be improved in the future.

Method: POST

To make a request, send the text parameter to the /sentiment_analysis endpoint with the authorization header.

Parameters

Only one parameter is required to perform sentiment analysis, which is:

  • text: It is the text on which to perform the sentiment analysis. It is required.

Responses

On success, the response would be like as given below. As all other endpoints, the data will be in the data object, inside the response.

{
  "status": "success", 
  "data": {
    "source_text": "The movie was terrible.", 
    "sentiment": "negative",
    "score": -3, 
    "comparative": -0.75,
    "comparative_normalized": 12.5,
    "calculation": [
      {
        "terrible": -3
      }
    ], 
    "tokens": ["the", "movie", "was", "terrible"], 
    "words": ["terrible"], 
    "positive": [], 
    "negative": ["terrible"]
  },
  "message": "Sentiment analysis was successful."
} 

Here inside the data object,

  • source_text is the given text,on which the sentiment analysis was performed.
  • sentiment is the sentiment of the text, which can be positive, negative, or neutral.
  • score is the score in the range of -5 to 5.
  • comparative is the score divided by the number of token. (words)
  • comparative_normalized is the comparative score in the range of 0 to 100.
  • calculation contains the words, which were identified, and affected the score.
  • tokens are all the words.
  • words contains the identified words.
  • positive contains the positive words.
  • negative contains the negative words.

On error, like not providing the text parameter the response would be like this:

{
  "status": "error", 
  "error": {
    "code": "MISSING_PARAMETER", 
    "message": "'text' parameter is required and must be a non-empty string.", 
    "details": "Ensure the request body includes a valid 'text' field with content."
  }
}

Notes

Since, this endpoint is powered by AFINN-165, it is currently not much advanced, and don't support much languages.