| """ |
| Módulo para preprocesamiento de textos antes de la extracción de eventos. |
| Incluye funciones para segmentación y filtrado de oraciones usando Stanza. |
| """ |
|
|
| import re |
| from typing import List |
|
|
|
|
| def get_filtered_sentences_from_article( |
| full_article_text: str, |
| nlp_pipeline, |
| min_sentence_words: int = 10, |
| show_text: bool = False |
| ) -> List: |
| """ |
| Realiza los pasos 1, 2 y 3 del pipeline: |
| 1. Aplana el texto (normaliza espacios). |
| 2. Segmenta en oraciones con Stanza. |
| 3. Filtra las oraciones (por longitud y puntuación final). |
| """ |
| separadores_regex = r'(\u00a0\s*| {2,}|\n+)' |
| texto_limpio_y_plano = re.sub(separadores_regex, ' ', full_article_text).strip() |
| |
| doc = nlp_pipeline(texto_limpio_y_plano) |
| sentences = doc.sentences |
| |
| filtered_sentences = [] |
| |
| for s in sentences: |
| sentence_text = s.text.strip() |
| |
| if len(sentence_text.split()) < min_sentence_words: |
| continue |
| |
| if not sentence_text.endswith(('.', ':', '?', '!', '"', ')', '"', ']')): |
| if show_text: |
| print(f"DESCARTADO (Posible titulo): '{sentence_text}'") |
| continue |
| |
| filtered_sentences.append(s) |
| |
| if show_text: |
| print(f"Proceso completado. Se encontraron {len(filtered_sentences)} oraciones validas.") |
| |
| return filtered_sentences |
|
|