From 150b80d4f49e820edb580e52204bd6c40a8573d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=9Acigacz?= Date: Sun, 11 Jun 2023 14:49:02 +0200 Subject: [PATCH] irony - clear data and add plot function --- application/functions/irony.py | 29 +++++++++++++++++++++++++-- application/services/irony_service.py | 8 +++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/application/functions/irony.py b/application/functions/irony.py index 3a8c770..1bd819d 100644 --- a/application/functions/irony.py +++ b/application/functions/irony.py @@ -7,5 +7,30 @@ def irony_prediction(data): return result def clear_data(data): - #czyszczenie danych - return data \ No newline at end of file + 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 \ No newline at end of file diff --git a/application/services/irony_service.py b/application/services/irony_service.py index 57efdfe..47a0a34 100644 --- a/application/services/irony_service.py +++ b/application/services/irony_service.py @@ -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}) \ No newline at end of file + return jsonify({"predictions": predicitons, "count_labels": count_labels}) \ No newline at end of file