Add local api support, fix test case

This commit is contained in:
Madison May
2014-09-25 17:05:16 -04:00
parent 6898e1ea07
commit a3d4d85412
8 changed files with 46 additions and 15 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ import json
from indicoio import JSON_HEADERS
def language(text):
def language(api_root, text):
"""
Given input text, returns a probability distribution over 33 possible
languages of what language the text was written in.
@@ -27,7 +27,7 @@ def language(text):
"""
data_dict = json.dumps({'text': text})
response = requests.post("http://api.indico.io/language", data=data_dict, headers=JSON_HEADERS)
response = requests.post(api_root + "language", data=data_dict, headers=JSON_HEADERS)
response_dict = response.json()
if len(response_dict) < 2:
raise ValueError(response_dict.values()[0])
+4 -4
View File
@@ -4,7 +4,7 @@ import json
from indicoio import JSON_HEADERS
from indicoio.utils import normalize
def political(text):
def political(api_root, text):
"""
Given input text, returns a probability distribution over the political alignment of the speaker.
@@ -31,14 +31,14 @@ def political(text):
"""
data_dict = json.dumps({'text': text})
response = requests.post("http://api.indico.io/political", data=data_dict, headers=JSON_HEADERS)
response = requests.post(api_root + "political", data=data_dict, headers=JSON_HEADERS)
response_dict = response.json()
if len(response_dict) < 2:
raise ValueError(response_dict.values()[0])
else:
return response_dict
def posneg(text):
def posneg(api_root, text):
"""
Given input text, returns a scalar estimate of the sentiment of that text.
Values are roughly in the range 0 to 1 with 0.5 indicating neutral sentiment.
@@ -60,7 +60,7 @@ def posneg(text):
"""
data_dict = json.dumps({'text': text})
response = requests.post("http://api.indico.io/sentiment", data=data_dict, headers=JSON_HEADERS)
response = requests.post(api_root + "sentiment", data=data_dict, headers=JSON_HEADERS)
response_dict = response.json()
if 'Sentiment' not in response_dict:
raise ValueError(response_dict.values()[0])