fix: normaliza termos do contexto antes de comparar com o chunk

calculateSemanticSimilarity normalizava o chunk (sem acentos) mas só
aplicava toLowerCase em keywords, entidades, tópicos, sinônimos, período
e local, e a lista de termos relativos tinha 'último' acentuado. Termos
com acento nunca casavam.
This commit is contained in:
evandro committed 2026-11-16 00:14:08 -03:00
1 parent f0b7db8c12
commit 94941414e9
1 file changed
+7 -7
+7 -7
View File
@@ -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;
}