Spaces:
Sleeping
Sleeping
Update modules/semantic/semantic_analysis.py
Browse files
modules/semantic/semantic_analysis.py
CHANGED
|
@@ -94,7 +94,7 @@ def fig_to_bytes(fig):
|
|
| 94 |
return None
|
| 95 |
|
| 96 |
###########################################################
|
| 97 |
-
def perform_semantic_analysis(text, nlp, lang_code):
|
| 98 |
"""
|
| 99 |
Realiza el análisis semántico completo del texto.
|
| 100 |
"""
|
|
@@ -428,6 +428,7 @@ def create_topic_graph(topics, doc):
|
|
| 428 |
G.add_edge(topic1, topic2, weight=weight)
|
| 429 |
return G
|
| 430 |
|
|
|
|
| 431 |
def visualize_topic_graph(G, lang_code):
|
| 432 |
fig, ax = plt.subplots(figsize=(12, 8))
|
| 433 |
pos = nx.spring_layout(G)
|
|
@@ -447,6 +448,7 @@ def generate_summary(doc, lang_code):
|
|
| 447 |
summary = sentences[:3] # Toma las primeras 3 oraciones como resumen
|
| 448 |
return " ".join([sent.text for sent in summary])
|
| 449 |
|
|
|
|
| 450 |
def extract_entities(doc, lang_code):
|
| 451 |
entities = defaultdict(list)
|
| 452 |
for ent in doc.ents:
|
|
@@ -454,6 +456,7 @@ def extract_entities(doc, lang_code):
|
|
| 454 |
entities[ent.label_].append(ent.text)
|
| 455 |
return dict(entities)
|
| 456 |
|
|
|
|
| 457 |
def analyze_sentiment(doc, lang_code):
|
| 458 |
positive_words = sum(1 for token in doc if token.sentiment > 0)
|
| 459 |
negative_words = sum(1 for token in doc if token.sentiment < 0)
|
|
@@ -465,12 +468,15 @@ def analyze_sentiment(doc, lang_code):
|
|
| 465 |
else:
|
| 466 |
return "Neutral"
|
| 467 |
|
|
|
|
| 468 |
def extract_topics(doc, lang_code):
|
| 469 |
vectorizer = TfidfVectorizer(stop_words='english', max_features=5)
|
| 470 |
tfidf_matrix = vectorizer.fit_transform([doc.text])
|
| 471 |
feature_names = vectorizer.get_feature_names_out()
|
| 472 |
return list(feature_names)
|
| 473 |
|
|
|
|
|
|
|
| 474 |
# Asegúrate de que todas las funciones necesarias estén exportadas
|
| 475 |
__all__ = [
|
| 476 |
'perform_semantic_analysis',
|
|
|
|
| 94 |
return None
|
| 95 |
|
| 96 |
###########################################################
|
| 97 |
+
def perform_semantic_analysis(text, nlp, lang_code, semantic_t):
|
| 98 |
"""
|
| 99 |
Realiza el análisis semántico completo del texto.
|
| 100 |
"""
|
|
|
|
| 428 |
G.add_edge(topic1, topic2, weight=weight)
|
| 429 |
return G
|
| 430 |
|
| 431 |
+
##################################################
|
| 432 |
def visualize_topic_graph(G, lang_code):
|
| 433 |
fig, ax = plt.subplots(figsize=(12, 8))
|
| 434 |
pos = nx.spring_layout(G)
|
|
|
|
| 448 |
summary = sentences[:3] # Toma las primeras 3 oraciones como resumen
|
| 449 |
return " ".join([sent.text for sent in summary])
|
| 450 |
|
| 451 |
+
##################################################
|
| 452 |
def extract_entities(doc, lang_code):
|
| 453 |
entities = defaultdict(list)
|
| 454 |
for ent in doc.ents:
|
|
|
|
| 456 |
entities[ent.label_].append(ent.text)
|
| 457 |
return dict(entities)
|
| 458 |
|
| 459 |
+
##################################################
|
| 460 |
def analyze_sentiment(doc, lang_code):
|
| 461 |
positive_words = sum(1 for token in doc if token.sentiment > 0)
|
| 462 |
negative_words = sum(1 for token in doc if token.sentiment < 0)
|
|
|
|
| 468 |
else:
|
| 469 |
return "Neutral"
|
| 470 |
|
| 471 |
+
##################################################
|
| 472 |
def extract_topics(doc, lang_code):
|
| 473 |
vectorizer = TfidfVectorizer(stop_words='english', max_features=5)
|
| 474 |
tfidf_matrix = vectorizer.fit_transform([doc.text])
|
| 475 |
feature_names = vectorizer.get_feature_names_out()
|
| 476 |
return list(feature_names)
|
| 477 |
|
| 478 |
+
|
| 479 |
+
##################################################
|
| 480 |
# Asegúrate de que todas las funciones necesarias estén exportadas
|
| 481 |
__all__ = [
|
| 482 |
'perform_semantic_analysis',
|