irony - clear data and add plot function
This commit is contained in:
parent
c42160d818
commit
150b80d4f4
@ -7,5 +7,30 @@ def irony_prediction(data):
|
||||
return result
|
||||
|
||||
def clear_data(data):
|
||||
#czyszczenie danych
|
||||
data = [i.replace('#','').
|
||||
replace('@','').
|
||||
replace('\uf8ff','').
|
||||
replace('\t','').
|
||||
replace('\"','').
|
||||
replace('\U000fe329','').
|
||||
replace('\U000fe35b','').
|
||||
replace('\U000fe4ef','').
|
||||
replace('\U000fe341','')
|
||||
for i in data['sentences']]
|
||||
return data
|
||||
|
||||
def count_predictions(predictions):
|
||||
l0 = 0
|
||||
l1 = 0
|
||||
all = {}
|
||||
|
||||
for i in predictions:
|
||||
if i['label'] == 'LABEL_0':
|
||||
l0 += 1
|
||||
if i['label'] == 'LABEL_1':
|
||||
l1 += 1
|
||||
|
||||
all['irony'] = l1
|
||||
all['non-irony'] = l0
|
||||
|
||||
return all
|
@ -3,17 +3,19 @@ from flask import(
|
||||
jsonify,
|
||||
Blueprint,
|
||||
)
|
||||
from application.functions.irony import irony_prediction
|
||||
from application.functions.irony import irony_prediction, count_predictions, clear_data
|
||||
|
||||
irony_service = Blueprint("irony_service", __name__)
|
||||
|
||||
@irony_service.route("/get_irony_data", methods=['POST'])
|
||||
def get_data():
|
||||
data = request.get_json()
|
||||
predicitons = irony_prediction(data['sentences'])
|
||||
data_clear = clear_data(data)
|
||||
predicitons = irony_prediction(data_clear)
|
||||
count_labels = count_predictions(predicitons)
|
||||
|
||||
for i in range(0, len(predicitons)):
|
||||
predicitons[i]['sentence'] = data['sentences'][i]
|
||||
predicitons[i]['label'] = predicitons[i]['label'][6:]
|
||||
|
||||
return jsonify({"predictions": predicitons})
|
||||
return jsonify({"predictions": predicitons, "count_labels": count_labels})
|
Loading…
Reference in New Issue
Block a user