mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-07-14 01:10:35 +08:00
ADD: keywords api support
This commit is contained in:
+34
-16
@@ -9,6 +9,7 @@ from indicoio import config
|
||||
from indicoio import political, sentiment, fer, facial_features, language, image_features, text_tags
|
||||
from indicoio import batch_political, batch_sentiment, batch_fer, batch_facial_features
|
||||
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 predict_image, predict_text, batch_predict_image, batch_predict_text
|
||||
from indicoio.utils.errors import IndicoError
|
||||
@@ -32,18 +33,22 @@ class BatchAPIRun(unittest.TestCase):
|
||||
response = batch_text_tags(test_data, api_key=self.api_key)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
|
||||
def test_batch_keywords(self):
|
||||
test_data = ["A working api is key to the success of our young company"]
|
||||
response = batch_keywords(test_data, api_key=self.api_key)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
|
||||
def test_batch_posneg(self):
|
||||
test_data = ['Worst song ever', 'Best song ever']
|
||||
response = batch_sentiment(test_data, api_key=self.api_key)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(response[0] < 0.5)
|
||||
|
||||
# TODO: uncomment once the high quality sentiment API is publicly released
|
||||
# def test_batch_sentiment_hq(self):
|
||||
# test_data = ['Worst song ever', 'Best song ever']
|
||||
# response = batch_sentiment_hq(test_data, api_key=self.api_key)
|
||||
# self.assertTrue(isinstance(response, list))
|
||||
# self.assertTrue(response[0] < 0.5)
|
||||
def test_batch_sentiment_hq(self):
|
||||
test_data = ['Worst song ever', 'Best song ever']
|
||||
response = batch_sentiment_hq(test_data, api_key=self.api_key)
|
||||
self.assertTrue(isinstance(response, list))
|
||||
self.assertTrue(response[0] < 0.5)
|
||||
|
||||
def test_batch_political(self):
|
||||
test_data = ["Guns don't kill people, people kill people."]
|
||||
@@ -202,6 +207,20 @@ class FullAPIRun(unittest.TestCase):
|
||||
for v in results.values():
|
||||
assert v >= 0.1
|
||||
|
||||
def test_keywords(self):
|
||||
text = "A working api is key to the success of our young company"
|
||||
|
||||
results = keywords(text)
|
||||
assert 'api' in results.keys()
|
||||
|
||||
results = keywords(text, top_n=3)
|
||||
assert len(results) is 3
|
||||
|
||||
results = keywords(text, threshold=.1)
|
||||
for v in results.values():
|
||||
assert v >= .1
|
||||
|
||||
|
||||
def test_political(self):
|
||||
political_set = set(['Libertarian', 'Liberal', 'Conservative', 'Green'])
|
||||
test_string = "Guns don't kill people, people kill people."
|
||||
@@ -228,18 +247,17 @@ class FullAPIRun(unittest.TestCase):
|
||||
self.assertTrue(isinstance(response, float))
|
||||
self.assertTrue(response > 0.5)
|
||||
|
||||
# TODO: uncomment when the high quality sentiment API is publicly released
|
||||
# def test_sentiment_hq(self):
|
||||
# test_string = "Worst song ever."
|
||||
# response = sentiment_hq(test_string)
|
||||
def test_sentiment_hq(self):
|
||||
test_string = "Worst song ever."
|
||||
response = sentiment_hq(test_string)
|
||||
|
||||
# self.assertTrue(isinstance(response, float))
|
||||
# self.assertTrue(response < 0.5)
|
||||
self.assertTrue(isinstance(response, float))
|
||||
self.assertTrue(response < 0.5)
|
||||
|
||||
# test_string = "Best song ever."
|
||||
# response = sentiment_hq(test_string)
|
||||
# self.assertTrue(isinstance(response, float))
|
||||
# self.assertTrue(response > 0.5)
|
||||
test_string = "Best song ever."
|
||||
response = sentiment_hq(test_string)
|
||||
self.assertTrue(isinstance(response, float))
|
||||
self.assertTrue(response > 0.5)
|
||||
|
||||
def test_good_fer(self):
|
||||
fer_set = set(['Angry', 'Sad', 'Neutral', 'Surprise', 'Fear', 'Happy'])
|
||||
|
||||
Reference in New Issue
Block a user