ADD: keywords api support

This commit is contained in:
jagreene
2015-07-07 11:51:49 -04:00
committed by Madison May
parent c9a6585086
commit b5d0aafc4e
10 changed files with 80 additions and 30 deletions
+24
View File
@@ -0,0 +1,24 @@
from indicoio.utils.api import api_handler
import indicoio.config as config
def keywords(text, cloud=None, batch=False, api_key=None, **kwargs):
"""
Given input text, returns series of keywords and associated scores
Example usage:
.. code-block:: python
>>> import indicoio
>>> import numpy as np
>>> text = 'Monday: Delightful with mostly sunny skies. Highs in the low 70s.'
>>> keywords = indicoio.keywords(text, top_n=3)
>>> print "The keywords are: "+str(keywords.keys())
u'The keywords are ['delightful', 'highs', 'skies']
:param text: The text to be analyzed.
:type text: str or unicode
:rtype: Dictionary of feature score pairs
"""
url_params = {'batch': batch, 'api_key': api_key}
return api_handler(text, cloud=cloud, api="keywords", url_params=url_params, **kwargs)
+2 -2
View File
@@ -23,5 +23,5 @@ def language(text, cloud=None, batch=False, api_key=None, **kwargs):
:type text: str or unicode
:rtype: Dictionary of language probability pairs
"""
return api_handler(text, cloud=cloud, api="language", url_params={"batch":batch, "api_key":api_key}, **kwargs)
url_params = {"batch": batch, "api_key": api_key}
return api_handler(text, cloud=cloud, api="language", url_params=url_params, **kwargs)
+6 -6
View File
@@ -25,8 +25,8 @@ def political(text, cloud=None, batch=False, api_key=None, **kwargs):
:type text: str or unicode
:rtype: Dictionary of party probability pairs
"""
return api_handler(text, cloud=cloud, api="political", url_params={"batch":batch, "api_key":api_key}, **kwargs)
url_params = {"batch": batch, "api_key": api_key}
return api_handler(text, cloud=cloud, api="political", url_params=url_params, **kwargs)
def posneg(text, cloud=None, batch=False, api_key=None, **kwargs):
"""
@@ -48,8 +48,8 @@ def posneg(text, cloud=None, batch=False, api_key=None, **kwargs):
:type text: str or unicode
:rtype: Float
"""
return api_handler(text, cloud=cloud, api="sentiment", url_params={"batch":batch, "api_key":api_key}, **kwargs)
url_params = {"batch": batch, "api_key": api_key}
return api_handler(text, cloud=cloud, api="sentiment", url_params=url_params, **kwargs)
def sentiment_hq(text, cloud=None, batch=False, api_key=None, **kwargs):
"""
@@ -71,5 +71,5 @@ def sentiment_hq(text, cloud=None, batch=False, api_key=None, **kwargs):
:type text: str or unicode
:rtype: Float
"""
return api_handler(text, cloud=cloud, api="sentimenthq", url_params={"batch":batch, "api_key":api_key}, **kwargs)
url_params = {"batch": batch, "api_key": api_key}
return api_handler(text, cloud=cloud, api="sentimenthq", url_params=url_params, **kwargs)
+2 -2
View File
@@ -22,5 +22,5 @@ def text_tags(text, cloud=None, batch=False, api_key=None, **kwargs):
:type text: str or unicode
:rtype: Dictionary of class probability pairs
"""
return api_handler(text, cloud=cloud, api="texttags", url_params={"batch":batch, "api_key":api_key}, **kwargs)
url_params = {"batch": batch, "api_key": api_key}
return api_handler(text, cloud=cloud, api="texttags", url_params=url_params, **kwargs)