diff --git a/lib/relevance-scorer.ts b/lib/relevance-scorer.ts index 74cc39b..a7f5332 100644 --- a/lib/relevance-scorer.ts +++ b/lib/relevance-scorer.ts @@ -97,7 +97,7 @@ export function calculateSemanticSimilarity( if (context.keywords.length > 0) { let keywordMatches = 0; for (const keyword of context.keywords) { - const keywordLower = keyword.toLowerCase(); + const keywordLower = normalizeText(keyword); if (normalizedChunk.includes(keywordLower)) { keywordMatches++; } @@ -111,7 +111,7 @@ export function calculateSemanticSimilarity( if (context.entities.length > 0) { let entityMatches = 0; for (const entity of context.entities) { - const entityLower = entity.value.toLowerCase(); + const entityLower = normalizeText(entity.value); // Buscar entidade completa (case-insensitive) if (normalizedChunk.includes(entityLower)) { entityMatches += entity.confidence; // Ponderar por confiança @@ -126,7 +126,7 @@ export function calculateSemanticSimilarity( if (context.topics.length > 0) { let topicMatches = 0; for (const topic of context.topics) { - const topicLower = topic.toLowerCase(); + const topicLower = normalizeText(topic); // Verificar se tópico aparece no chunk (pode ser parcial) const topicWords = topicLower.split(/\s+/); const matches = topicWords.filter(word => @@ -147,7 +147,7 @@ export function calculateSemanticSimilarity( if (context.synonyms.length > 0) { let synonymMatches = 0; for (const synonym of context.synonyms) { - const synonymLower = synonym.toLowerCase(); + const synonymLower = normalizeText(synonym); if (normalizedChunk.includes(synonymLower)) { synonymMatches++; } @@ -163,18 +163,18 @@ export function calculateSemanticSimilarity( // Verificar se contexto temporal/geográfico aparece no chunk let contextualScore = 0; if (context.temporalContext?.period) { - if (normalizedChunk.includes(context.temporalContext.period)) { + if (normalizedChunk.includes(normalizeText(context.temporalContext.period))) { contextualScore += 0.5; } } if (context.temporalContext?.relative) { - const relativeTerms = ['recente', 'atual', 'novo', 'último', 'atualizado']; + const relativeTerms = ['recente', 'atual', 'novo', 'ultimo', 'atualizado']; if (relativeTerms.some(term => normalizedChunk.includes(term))) { contextualScore += 0.3; } } if (context.geographicContext?.location) { - const locationLower = context.geographicContext.location.toLowerCase(); + const locationLower = normalizeText(context.geographicContext.location); if (normalizedChunk.includes(locationLower)) { contextualScore += 0.5; }