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."
}
JSON
Here inside the data object,
source_textis the given text,on which the sentiment analysis was performed.sentimentis the sentiment of the text, which can be positive, negative, or neutral.scoreis the score in the range of -5 to 5.comparativeis the score divided by the number of token. (words)comparative_normalizedis the comparative score in the range of 0 to 100.calculationcontains the words, which were identified, and affected the score.tokensare all the words.wordscontains the identified words.positivecontains the positive words.negativecontains 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."
}
}
JSON
Notes
Since, this endpoint is powered by AFINN-165, it is currently not much advanced, and don't support much languages.