0

I have a quick question to call an NLTK Api using python.To find the sentiment of "great"; The API syntax is

 $ curl -d "text=great" http://text-processing.com/api/sentiment/

I need to use a python request to post this and to receive a json object as response.I am trying to use with

resp = requests.post(url, data=values, allow_redirects=True)

if url is http://text-processing.com/api/sentiment/ how must text parameter to be passed?

1 Answer 1

1

Modifying the guide from the requests documentation, to suit your requirement, this is what you do:

>>> import json
>>> url = 'http://text-processing.com/api/sentiment/'
>>> payload = {'text': 'great'}

>>> r = requests.post(url, data=json.dumps(payload))
Sign up to request clarification or add additional context in comments.

7 Comments

The responce is retrieved as a json object. { "probability": { "neg": 0.39680315784838732, "neutral": 0.28207586364297021, "pos": 0.60319684215161262 }, "label": "pos" } How can i retrieve these parameters separately as neg pos neutral and label?
@AbhijathBenhur Isn't it what you want?
Yes this was exactly what i wanted.!! but i need to seperate the values of pos neg and neutral into seperate python variables.
Assuming whatever you pasted above is in a variable json_response, neg = json_response['probability']['neg'] and similarly for pos and neutral. Please accept the answer if it resolves your issue :)
It results with a response of json_response not defined. :-( i have imported json
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.