0

I want to use the Python-SDK for Emotion Analysis using the AlchemyAPI.

from alchemyapi import AlchemyAPI    
alchemyapi = AlchemyAPI()
demo_text = 'I am happy'
alchemyapi.emotion('text', demo_text)

gives this error:

AttributeError: AlchemyAPI instance has no attribute 'emotion'

How do I make an API call to detect emotions as mentioned here?

A screenshot of the alchemyapi demo predicting emotions

Poorva Rane
  • 83
  • 2
  • 13

1 Answers1

2

Please follow all the steps above:

  1. Get Your Free API Key - AlchemyAPI requires an API Key to access their text analysis functions.
  2. Clone Python SDK from GitHub - To make using AlchemyAPI easier, they've created a software development kit, or SDK for short.

Hint:

mkdir -p ~/src/test
cd ~/src/test
git clone https://github.com/AlchemyAPI/alchemyapi_python.git
cd alchemyapi_python/

3. Configure the Python SDK to use your API Key - all you need to do is configure it to use your API key:

python alchemyapi.py YOUR_API_KEY

4. Run a simple Example:

python example.py

At this point you should get lots of output in the terminal window as each function is called and the output is parsed.

Now, to be able to use AlchemyAPI functionality just copy and paste the alchemyapi.py file into your project, and in the file that will handle the text analysis include the following lines:

from alchemyapi import AlchemyAPI
alchemyapi = AlchemyAPI()

Now you can use the alchemyapi object to access any of the text analysis functions:

myText = "I'm excited to get started with AlchemyAPI!"
response = alchemyapi.sentiment("text", myText)
print "Sentiment: ", response["docSentiment"]["type"]

Disclaimer: make sure that you follow all these steps in order to be able to access the API.

Cajuu'
  • 1,064
  • 2
  • 16
  • 46
  • I have done these steps. What I want is `emotions`. I want my sentence to be classified into `joy, sadness, fear, anger, disgust` like how it is done [here](http://www.alchemyapi.com/products/demo/alchemylanguage). [This](http://www.alchemyapi.com/products/alchemylanguage/emotion-analysis) is a page on what exactly I want to do. – Poorva Rane Apr 05 '16 at 16:20