mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-07-29 11:15:22 +08:00
Api standardization, feature importance folder
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def language(api_root, text):
|
||||
"""
|
||||
@@ -26,10 +26,4 @@ def language(api_root, text):
|
||||
:rtype: Dictionary of language probability pairs
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({'text': text})
|
||||
response = requests.post(api_root + "language", data=data_dict, headers=JSON_HEADERS)
|
||||
response_dict = response.json()
|
||||
if len(response_dict) < 2:
|
||||
raise ValueError(response_dict.values()[0])
|
||||
else:
|
||||
return response_dict
|
||||
return api_handler(text, api_root + "language")
|
||||
|
||||
@@ -2,7 +2,7 @@ import requests
|
||||
import json
|
||||
|
||||
from indicoio import JSON_HEADERS
|
||||
from indicoio.utils import normalize
|
||||
from indicoio.utils import api_handler
|
||||
|
||||
def political(api_root, text):
|
||||
"""
|
||||
@@ -30,13 +30,7 @@ def political(api_root, text):
|
||||
:rtype: Dictionary of party probability pairs
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({'text': text})
|
||||
response = requests.post(api_root + "political", data=data_dict, headers=JSON_HEADERS)
|
||||
response_dict = response.json()
|
||||
if len(response_dict) < 2:
|
||||
raise ValueError(response_dict.values()[0])
|
||||
else:
|
||||
return response_dict
|
||||
return api_handler(text, api_root + "political")
|
||||
|
||||
def posneg(api_root, text):
|
||||
"""
|
||||
@@ -59,10 +53,4 @@ def posneg(api_root, text):
|
||||
:rtype: Float
|
||||
"""
|
||||
|
||||
data_dict = json.dumps({'text': text})
|
||||
response = requests.post(api_root + "sentiment", data=data_dict, headers=JSON_HEADERS)
|
||||
response_dict = response.json()
|
||||
if 'Sentiment' not in response_dict:
|
||||
raise ValueError(response_dict.values()[0])
|
||||
else:
|
||||
return response_dict['Sentiment']
|
||||
return api_handler(text, api_root + "sentiment")
|
||||
|
||||
Reference in New Issue
Block a user