-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 Fase 3.1: Implementar Classe StemmerPT com NLTK RSLPStemmer
📝 Descrição
Implementar stemming para português usando NLTK RSLPStemmer como alternativa mais rápida à lemmatization.
🎯 Objetivos
- Implementar classe
StemmerPTusando NLTK - Otimização para performance (stemming é mais rápido)
- Integração com sistema de cache existente
- Comparação de performance com lemmatization
- Fallback automático
🔧 Implementação Técnica
Classe StemmerPT:
from nltk.stem import RSLPStemmer
from typing import List, Dict
from .text_preprocessing import TextProcessor
class StemmerPT(TextProcessor):
def __init__(self, cache_enabled: bool = True):
self.cache_enabled = cache_enabled
self._cache: Dict[str, str] = {}
self._load_stemmer()
def _load_stemmer(self):
\"\"\"Carrega RSLPStemmer do NLTK.\"\"\"
try:
self.stemmer = RSLPStemmer()
except LookupError:
# Download automático do corpus se necessário
import nltk
nltk.download('rslp')
self.stemmer = RSLPStemmer()
def process_text(self, text: str) -> str:
\"\"\"Aplica stemming a texto individual.\"\"\"
if self.cache_enabled and text in self._cache:
return self._cache[text]
# Processar palavra por palavra
words = text.split()
stemmed_words = [self.stemmer.stem(word) for word in words]
result = ' '.join(stemmed_words)
if self.cache_enabled:
self._cache[text] = result
return result
def process_batch(self, texts: List[str]) -> List[str]:
\"\"\"Processa lote otimizado.\"\"\"
return [self.process_text(text) for text in texts]Características:
- Performance superior: ~5-10x mais rápido que lemmatization
- Menor uso de memória: Não precisa carregar modelo grande
- Cache inteligente: Reutiliza resultados de palavras já processadas
- Robusto: Funciona sempre (NLTK já é dependência)
- Fallback ideal: Para quando lemmatization falha
✅ Critérios de Aceitação
- Stemming funcional para português usando RSLPStemmer
- Performance significativamente superior à lemmatization
- Sistema de cache implementado
- Download automático do corpus RSLP se necessário
- Integração com pipeline existente
- Benchmark completo vs lemmatization
- Testes com vocabulário jurídico
📊 Benchmarks Esperados
| Métrica | Stemming | Lemmatization | Melhoria |
|---|---|---|---|
| Velocidade | ~0.1s/1000 textos | ~2.0s/1000 textos | 20x |
| Memória | ~50MB | ~500MB | 10x |
| Qualidade | Boa | Excelente | -20% |
| Setup | Instantâneo | ~30s download | N/A |
🔗 Relacionado
- Issue principal: Adicionar stemming/lemmatization #13
- Anterior: Fase 2.1: Modificar método preparar() com parâmetros opcionais #22 (modificar preparar)
- Próxima: Sistema de cache otimizado
⏱️ Estimativa
4 horas - Implementação mais simples que lemmatization
🧪 Testes
- Stemming produz resultados consistentes
- Performance superior confirmada em benchmarks
- Cache melhora performance adicional
- Download automático funciona
- Qualidade aceitável para textos jurídicos
- Integração perfeita com pipeline
📖 Casos de uso
# Para performance máxima
cf.preparar(coluna_textos='texto', usar_stemming=True)
# Como fallback automático
cf.preparar(
coluna_textos='texto',
usar_lemmatization=True,
fallback_stemming=True # Usar stemming se lemma falhar
)Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request