mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-06-27 16:10:34 +08:00
ADD: Twitter Engagement
This commit is contained in:
@@ -10,6 +10,7 @@ JSON_HEADERS = {
|
||||
'version-number': VERSION
|
||||
}
|
||||
|
||||
from indicoio.text.twitter_engagement import twitter_engagement
|
||||
from indicoio.text.sentiment import political, posneg, sentiment_hq
|
||||
from indicoio.text.sentiment import posneg as sentiment
|
||||
from indicoio.text.lang import language
|
||||
@@ -41,7 +42,7 @@ def detect_batch_decorator(f):
|
||||
kwargs['batch'] = True
|
||||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
apis = dict((api, globals().get(api)) for api in API_NAMES)
|
||||
|
||||
for api in apis:
|
||||
|
||||
+2
-1
@@ -52,7 +52,8 @@ TEXT_APIS = [
|
||||
'language',
|
||||
'sentiment_hq',
|
||||
'keywords',
|
||||
'named_entities'
|
||||
'named_entities',
|
||||
'twitter_engagement'
|
||||
]
|
||||
|
||||
IMAGE_APIS = [
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from indicoio.utils.api import api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def twitter_engagement(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
"""
|
||||
Given input text, returns an engagment score between 0 and 1
|
||||
|
||||
Example usage:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> import indicoio
|
||||
>>> import numpy as np
|
||||
>>> text = 'Monday: Delightful with mostly sunny skies. Highs in the low 70s.'
|
||||
>>> engagement = indicoio.twitter_engagement(text)
|
||||
|
||||
:param text: The text to be analyzed.
|
||||
:type text: str or unicode
|
||||
:rtype: Float of engagement between 0 and 1
|
||||
"""
|
||||
url_params = {"batch": batch, "api_key": api_key}
|
||||
return api_handler(text, cloud=cloud, api="twitterengagement", url_params=url_params, **kwargs)
|
||||
@@ -11,6 +11,7 @@ from indicoio import batch_political, batch_sentiment, batch_fer, batch_content_
|
||||
from indicoio import batch_language, batch_image_features, batch_text_tags
|
||||
from indicoio import keywords, batch_keywords
|
||||
from indicoio import sentiment_hq, batch_sentiment_hq
|
||||
from indicoio import twitter_engagement, batch_twitter_engagement
|
||||
from indicoio import named_entities, batch_named_entities
|
||||
from indicoio import predict_image, predict_text, batch_predict_image, batch_predict_text
|
||||
from indicoio.utils.errors import IndicoError
|
||||
@@ -289,6 +290,22 @@ class FullAPIRun(unittest.TestCase):
|
||||
self.assertTrue(isinstance(response, float))
|
||||
self.assertTrue(response > 0.5)
|
||||
|
||||
def test_twitter_engagement(self):
|
||||
test_string = "Worst song ever."
|
||||
response = twitter_engagement(test_string)
|
||||
|
||||
self.assertIsInstance(response, float)
|
||||
self.assertTrue(response <= 1)
|
||||
self.assertTrue(response >= 0)
|
||||
|
||||
def test_batch_twitter_engagement(self):
|
||||
test_string = "Worst song ever."
|
||||
response = batch_twitter_engagement([test_string, test_string])
|
||||
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertIsInstance(response[0], float)
|
||||
self.assertEqual(response[0], response[1])
|
||||
|
||||
def test_good_fer(self):
|
||||
fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy'])
|
||||
test_face = os.path.normpath(os.path.join(DIR, "data/48by48.png"))
|
||||
|
||||
Reference in New Issue
Block a user