mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-16 11:14:18 +08:00
ADD: sentimenthq
This commit is contained in:
@@ -9,7 +9,7 @@ JSON_HEADERS = {
|
|||||||
'version-number': VERSION
|
'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.sentiment import posneg as sentiment
|
||||||
from indicoio.text.lang import language
|
from indicoio.text.lang import language
|
||||||
from indicoio.text.tagging import text_tags
|
from indicoio.text.tagging import text_tags
|
||||||
|
|||||||
+2
-1
@@ -49,7 +49,8 @@ TEXT_APIS = [
|
|||||||
'text_tags',
|
'text_tags',
|
||||||
'political',
|
'political',
|
||||||
'sentiment',
|
'sentiment',
|
||||||
'language'
|
'language',
|
||||||
|
'sentiment_hq'
|
||||||
]
|
]
|
||||||
|
|
||||||
IMAGE_APIS = [
|
IMAGE_APIS = [
|
||||||
|
|||||||
@@ -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)
|
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)
|
||||||
|
|||||||
@@ -17,10 +17,15 @@ def api_handler(arg, cloud, api, url_params = {"batch":False, "api_key":None}, *
|
|||||||
|
|
||||||
if cloud:
|
if cloud:
|
||||||
host = "%s.indico.domains" % cloud
|
host = "%s.indico.domains" % cloud
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# default to indico public cloud
|
# default to indico public cloud
|
||||||
host = config.PUBLIC_API_HOST
|
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 = config.url_protocol + "//%s/%s" % (host, api)
|
||||||
url = url + "/batch" if url_params.get("batch", False) else url
|
url = url + "/batch" if url_params.get("batch", False) else url
|
||||||
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)
|
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)
|
||||||
|
|||||||
Reference in New Issue
Block a user