-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Added functions to fill the BECK
- Loading branch information
1 parent
ba7b103
commit 10fdb7e
Showing
4 changed files
with
95 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,17 @@ | ||
import pandas as pd | ||
from preprocessing_service import Preprocesamiento | ||
import json | ||
import pprint | ||
from model_word2vec_service import ModelWord2Vec | ||
import nltk | ||
nltk.download('punkt') | ||
df = pd.read_csv("./datasets/comentarios_full.csv", encoding='utf-8') | ||
comments = list(df["text"]) | ||
classes = list(df["class"]) | ||
|
||
# df_prueba_chelsea = df_prueba_chelsea.append({'Nombre': 'Vaughn', 'Numero de camiseta':'33'}, ignore_index=True) | ||
preprocesamiento = Preprocesamiento() | ||
|
||
pp = Preprocesamiento() | ||
w2v = ModelWord2Vec() | ||
df_cve = pd.read_csv('./datasets/coseno.csv', encoding='utf-8') | ||
columns = list(df_cve.columns)[2:] | ||
inicio = 6000 | ||
fin = 8000 | ||
class_comment = 0 | ||
# Lectura beck | ||
beck_data_preprocessing = {} | ||
try: | ||
if open('./JSON/items_preprocessing.json', 'r'): | ||
beck_data_preprocessing = json.loads( | ||
open('./JSON/items_preprocessing.json', 'r', encoding='utf-8').read()) | ||
except Exception as e: | ||
print(f'Error: {e}') | ||
|
||
for comment in comments[inicio:fin]: | ||
try: | ||
print(f'Comentario: {class_comment + 1}/{len(comments)}') | ||
new_comment = {} | ||
contador = 0 | ||
new_comment["Comentario"] = comment | ||
comment_preprocesado = preprocesamiento.preprocesamiento_con_ortografia( | ||
comment) | ||
new_comment["Comentario Preprocesado"] = comment_preprocesado | ||
w2v.add_corpus(comment_preprocesado) | ||
for item in beck_data_preprocessing.keys(): | ||
for result in beck_data_preprocessing[item].keys(): | ||
new_comment[columns[contador]] = w2v.get_cosine_similarity(comment_preprocesado, beck_data_preprocessing[item][result]["data"]) | ||
contador += 1 | ||
|
||
# Add to dataframe | ||
new_comment["Clase"] = classes[class_comment] | ||
df_cve = df_cve.append(new_comment, ignore_index=True) | ||
class_comment += 1 | ||
except Exception as e: | ||
print(f'Error en el comentario {class_comment} omitiendo...') | ||
print(e) | ||
class_comment += 1 | ||
continue | ||
|
||
df_cve.to_csv('./datasets/coseno.csv', index=False, encoding="utf-8") | ||
comentario = "Estoy muy triste y no se que hacer" | ||
# Escribe un comentario triste y largo | ||
comentario = "Estoy muy triste y no se que hacer es un día nublado y esta lloviendo" | ||
# Preprocesado del comentario | ||
comentario_procesado = pp.preprocesamiento_con_ortografia(comentario) | ||
# Obtener la similitud de coseno entre el comentario y | ||
# Cada una de las respuestas del inventario de depresión de BECK (BDI-II) | ||
cosine_similarity_beck = w2v.get_cosine_similarity_BECK(comentario_procesado) | ||
# Obtener la respuesta por item basandose en la similitud de coseno | ||
results_beck = w2v.get_result_beck(cosine_similarity_beck) | ||
print("El comentario lleno el inventario BECK de esta manera:", results_beck) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import numpy as np | ||
#array del 1 al 21 | ||
array = list(np.arange(1, 22)) | ||
primera_parte = array[:15] # 4 respuestas | ||
segunda_parte = array[15:16] # 7 respuestas | ||
tercera_parte = array[16:17] # 4 respuestas | ||
cuarta_parte = array[17:18] # 7 respuestas | ||
quinta_parte = array[18:] # 4 respuestas |