ADD: sentimenthq

This commit is contained in:
Madison May
2015-06-11 16:46:51 -04:00
parent 29b190d1d2
commit 47133c956f
4 changed files with 31 additions and 2 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ JSON_HEADERS = {
'version-number': VERSION
}
from indicoio.text.sentiment import political, posneg
from indicoio.text.sentiment import political, posneg, sentiment_hq
from indicoio.text.sentiment import posneg as sentiment
from indicoio.text.lang import language
from indicoio.text.tagging import text_tags
+2 -1
View File
@@ -49,7 +49,8 @@ TEXT_APIS = [
'text_tags',
'political',
'sentiment',
'language'
'language',
'sentiment_hq'
]
IMAGE_APIS = [
+23
View File
@@ -50,3 +50,26 @@ def posneg(text, cloud=None, batch=False, api_key=None, **kwargs):
"""
return api_handler(text, cloud=cloud, api="sentiment", url_params={"batch":batch, "api_key":api_key}, **kwargs)
def sentiment_hq(text, cloud=None, batch=False, api_key=None, **kwargs):
"""
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.
For reference, 0 suggests very negative sentiment and 1 suggests very positive sentiment.
Example usage:
.. code-block:: python
>>> from indicoio import sentimenthq
>>> text = 'Thanks everyone for the birthday wishes!! It was a crazy few days ><'
>>> sentiment = sentimenthq(text)
>>> sentiment
0.6210052967071533
:param text: The text to be analyzed.
:type text: str or unicode
:rtype: Float
"""
return api_handler(text, cloud=cloud, api="sentimenthq", url_params={"batch":batch, "api_key":api_key}, **kwargs)
+5
View File
@@ -17,10 +17,15 @@ def api_handler(arg, cloud, api, url_params = {"batch":False, "api_key":None}, *
if cloud:
host = "%s.indico.domains" % cloud
else:
# default to indico public cloud
host = config.PUBLIC_API_HOST
# error message for public cloud
if api == 'sentimenthq':
raise IndicoError("The high quality sentiment API is currently in private beta.")
url = config.url_protocol + "//%s/%s" % (host, api)
url = url + "/batch" if url_params.get("batch", False) else url
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)