Spaces:
Running
Running
Update modules/text_analysis/discourse_analysis.py
Browse files
modules/text_analysis/discourse_analysis.py
CHANGED
|
@@ -18,6 +18,9 @@ from .semantic_analysis import (
|
|
| 18 |
POS_TRANSLATIONS,
|
| 19 |
ENTITY_LABELS
|
| 20 |
)
|
|
|
|
|
|
|
|
|
|
| 21 |
#####################
|
| 22 |
# Define colors for grammatical categories
|
| 23 |
POS_COLORS = {
|
|
@@ -75,98 +78,6 @@ ENTITY_LABELS = {
|
|
| 75 |
}
|
| 76 |
}
|
| 77 |
|
| 78 |
-
CUSTOM_STOPWORDS = {
|
| 79 |
-
'es': {
|
| 80 |
-
# Artículos
|
| 81 |
-
'el', 'la', 'los', 'las', 'un', 'una', 'unos', 'unas',
|
| 82 |
-
# Preposiciones comunes
|
| 83 |
-
'a', 'ante', 'bajo', 'con', 'contra', 'de', 'desde', 'en',
|
| 84 |
-
'entre', 'hacia', 'hasta', 'para', 'por', 'según', 'sin',
|
| 85 |
-
'sobre', 'tras', 'durante', 'mediante',
|
| 86 |
-
# Conjunciones
|
| 87 |
-
'y', 'e', 'ni', 'o', 'u', 'pero', 'sino', 'porque',
|
| 88 |
-
# Pronombres
|
| 89 |
-
'yo', 'tú', 'él', 'ella', 'nosotros', 'vosotros', 'ellos',
|
| 90 |
-
'ellas', 'este', 'esta', 'ese', 'esa', 'aquel', 'aquella',
|
| 91 |
-
# Verbos auxiliares comunes
|
| 92 |
-
'ser', 'estar', 'haber', 'tener',
|
| 93 |
-
# Palabras comunes en textos académicos
|
| 94 |
-
'además', 'también', 'asimismo', 'sin embargo', 'no obstante',
|
| 95 |
-
'por lo tanto', 'entonces', 'así', 'luego', 'pues',
|
| 96 |
-
# Números escritos
|
| 97 |
-
'uno', 'dos', 'tres', 'primer', 'primera', 'segundo', 'segunda',
|
| 98 |
-
# Otras palabras comunes
|
| 99 |
-
'cada', 'todo', 'toda', 'todos', 'todas', 'otro', 'otra',
|
| 100 |
-
'donde', 'cuando', 'como', 'que', 'cual', 'quien',
|
| 101 |
-
'cuyo', 'cuya', 'hay', 'solo', 'ver', 'si', 'no',
|
| 102 |
-
# Símbolos y caracteres especiales
|
| 103 |
-
'#', '@', '/', '*', '+', '-', '=', '$', '%'
|
| 104 |
-
},
|
| 105 |
-
'en': {
|
| 106 |
-
# Articles
|
| 107 |
-
'the', 'a', 'an',
|
| 108 |
-
# Common prepositions
|
| 109 |
-
'in', 'on', 'at', 'by', 'for', 'with', 'about', 'against',
|
| 110 |
-
'between', 'into', 'through', 'during', 'before', 'after',
|
| 111 |
-
'above', 'below', 'to', 'from', 'up', 'down', 'of',
|
| 112 |
-
# Conjunctions
|
| 113 |
-
'and', 'or', 'but', 'nor', 'so', 'for', 'yet',
|
| 114 |
-
# Pronouns
|
| 115 |
-
'i', 'you', 'he', 'she', 'it', 'we', 'they', 'this',
|
| 116 |
-
'that', 'these', 'those', 'my', 'your', 'his', 'her',
|
| 117 |
-
# Auxiliary verbs
|
| 118 |
-
'be', 'am', 'is', 'are', 'was', 'were', 'been', 'have',
|
| 119 |
-
'has', 'had', 'do', 'does', 'did',
|
| 120 |
-
# Common academic words
|
| 121 |
-
'therefore', 'however', 'thus', 'hence', 'moreover',
|
| 122 |
-
'furthermore', 'nevertheless',
|
| 123 |
-
# Numbers written
|
| 124 |
-
'one', 'two', 'three', 'first', 'second', 'third',
|
| 125 |
-
# Other common words
|
| 126 |
-
'where', 'when', 'how', 'what', 'which', 'who',
|
| 127 |
-
'whom', 'whose', 'there', 'here', 'just', 'only',
|
| 128 |
-
# Symbols and special characters
|
| 129 |
-
'#', '@', '/', '*', '+', '-', '=', '$', '%'
|
| 130 |
-
},
|
| 131 |
-
'fr': {
|
| 132 |
-
# Articles
|
| 133 |
-
'le', 'la', 'les', 'un', 'une', 'des',
|
| 134 |
-
# Prepositions
|
| 135 |
-
'à', 'de', 'dans', 'sur', 'en', 'par', 'pour', 'avec',
|
| 136 |
-
'sans', 'sous', 'entre', 'derrière', 'chez', 'avant',
|
| 137 |
-
# Conjunctions
|
| 138 |
-
'et', 'ou', 'mais', 'donc', 'car', 'ni', 'or',
|
| 139 |
-
# Pronouns
|
| 140 |
-
'je', 'tu', 'il', 'elle', 'nous', 'vous', 'ils',
|
| 141 |
-
'elles', 'ce', 'cette', 'ces', 'celui', 'celle',
|
| 142 |
-
# Auxiliary verbs
|
| 143 |
-
'être', 'avoir', 'faire',
|
| 144 |
-
# Academic words
|
| 145 |
-
'donc', 'cependant', 'néanmoins', 'ainsi', 'toutefois',
|
| 146 |
-
'pourtant', 'alors',
|
| 147 |
-
# Numbers
|
| 148 |
-
'un', 'deux', 'trois', 'premier', 'première', 'second',
|
| 149 |
-
# Other common words
|
| 150 |
-
'où', 'quand', 'comment', 'que', 'qui', 'quoi',
|
| 151 |
-
'quel', 'quelle', 'plus', 'moins',
|
| 152 |
-
# Symbols
|
| 153 |
-
'#', '@', '/', '*', '+', '-', '=', '$', '%'
|
| 154 |
-
}
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
##############################################################################################################
|
| 158 |
-
def get_stopwords(lang_code):
|
| 159 |
-
"""
|
| 160 |
-
Obtiene el conjunto de stopwords para un idioma específico.
|
| 161 |
-
Combina las stopwords de spaCy con las personalizadas.
|
| 162 |
-
"""
|
| 163 |
-
try:
|
| 164 |
-
nlp = spacy.load(f'{lang_code}_core_news_sm')
|
| 165 |
-
spacy_stopwords = nlp.Defaults.stop_words
|
| 166 |
-
custom_stopwords = CUSTOM_STOPWORDS.get(lang_code, set())
|
| 167 |
-
return spacy_stopwords.union(custom_stopwords)
|
| 168 |
-
except:
|
| 169 |
-
return CUSTOM_STOPWORDS.get(lang_code, set())
|
| 170 |
|
| 171 |
#################
|
| 172 |
def compare_semantic_analysis(text1, text2, nlp, lang):
|
|
|
|
| 18 |
POS_TRANSLATIONS,
|
| 19 |
ENTITY_LABELS
|
| 20 |
)
|
| 21 |
+
|
| 22 |
+
from .stopwords import get_custom_stopwords
|
| 23 |
+
|
| 24 |
#####################
|
| 25 |
# Define colors for grammatical categories
|
| 26 |
POS_COLORS = {
|
|
|
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
#################
|
| 83 |
def compare_semantic_analysis(text1, text2, nlp, lang):
|