Update modules/database/database.py
Browse files- modules/database/database.py +10 -5
modules/database/database.py
CHANGED
@@ -222,11 +222,15 @@ def store_morphosyntax_result(username, text, repeated_words, arc_diagrams, pos_
|
|
222 |
return False
|
223 |
|
224 |
################################################################################################################
|
225 |
-
def store_semantic_result(username, text,
|
|
|
|
|
|
|
|
|
226 |
try:
|
227 |
-
# Convertir la figura a una imagen base64
|
228 |
buf = io.BytesIO()
|
229 |
-
|
230 |
buf.seek(0)
|
231 |
img_str = base64.b64encode(buf.getvalue()).decode('utf-8')
|
232 |
|
@@ -234,12 +238,13 @@ def store_semantic_result(username, text, network_diagram):
|
|
234 |
'username': username,
|
235 |
'timestamp': datetime.utcnow(),
|
236 |
'text': text,
|
237 |
-
'
|
|
|
|
|
238 |
'analysis_type': 'semantic'
|
239 |
}
|
240 |
|
241 |
result = analysis_collection.insert_one(analysis_document)
|
242 |
-
|
243 |
logger.info(f"An谩lisis sem谩ntico guardado con ID: {result.inserted_id} para el usuario: {username}")
|
244 |
return True
|
245 |
except Exception as e:
|
|
|
222 |
return False
|
223 |
|
224 |
################################################################################################################
|
225 |
+
def store_semantic_result(username, text, analysis_result):
|
226 |
+
if analysis_collection is None:
|
227 |
+
logger.error("La conexi贸n a MongoDB no est谩 inicializada")
|
228 |
+
return False
|
229 |
+
|
230 |
try:
|
231 |
+
# Convertir la figura de relaciones sem谩nticas a una imagen base64
|
232 |
buf = io.BytesIO()
|
233 |
+
analysis_result['relations_graph'].savefig(buf, format='png')
|
234 |
buf.seek(0)
|
235 |
img_str = base64.b64encode(buf.getvalue()).decode('utf-8')
|
236 |
|
|
|
238 |
'username': username,
|
239 |
'timestamp': datetime.utcnow(),
|
240 |
'text': text,
|
241 |
+
'entities': analysis_result['entities'],
|
242 |
+
'key_concepts': analysis_result['key_concepts'],
|
243 |
+
'relations_graph': img_str, # Guardar la imagen como string base64
|
244 |
'analysis_type': 'semantic'
|
245 |
}
|
246 |
|
247 |
result = analysis_collection.insert_one(analysis_document)
|
|
|
248 |
logger.info(f"An谩lisis sem谩ntico guardado con ID: {result.inserted_id} para el usuario: {username}")
|
249 |
return True
|
250 |
except Exception as e:
|