You are here

Sample Source Code: ParallelDots Emotion Analysis

Often the three classes of sentiment (positive, negative and neutral) are not sufficient to understand the nuances regarding the underlying tone of a sentence. The Emotion Analysis classifier is trained on the ParallelDots proprietary data set and can let you know whether the underlying emotion behind a message is happy, sad, angry, fearful, excited, funny or indifferent. This code sample is for use with the ParallelDots Emotion Analysis API. from paralleldots.config import get_api_key import requests import json def get_emotion( text ): api_key = get_api_key() if not api_key == None: if type( text ) != str: return { "Error": "Input must be a string." } elif text in [ "", None ]: return { "Error": "Input string cannot be empty." } url = "" r = url, params={ "api_key": api_key, "text": text } ) if r.status_code != 200: return { "Error": "Oops something went wrong ! You can raise an issue at" } r = json.loads( r.text ) return r else: return { "Error": "API key does not exist" }