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:
1 parent
f0b7db8c12
commit
94941414e9
1 file changed
+7
-7
@@ -97,7 +97,7 @@ export function calculateSemanticSimilarity(
|
|||||||
if (context.keywords.length > 0) {
|
if (context.keywords.length > 0) {
|
||||||
let keywordMatches = 0;
|
let keywordMatches = 0;
|
||||||
for (const keyword of context.keywords) {
|
for (const keyword of context.keywords) {
|
||||||
const keywordLower = keyword.toLowerCase();
|
const keywordLower = normalizeText(keyword);
|
||||||
if (normalizedChunk.includes(keywordLower)) {
|
if (normalizedChunk.includes(keywordLower)) {
|
||||||
keywordMatches++;
|
keywordMatches++;
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ export function calculateSemanticSimilarity(
|
|||||||
if (context.entities.length > 0) {
|
if (context.entities.length > 0) {
|
||||||
let entityMatches = 0;
|
let entityMatches = 0;
|
||||||
for (const entity of context.entities) {
|
for (const entity of context.entities) {
|
||||||
const entityLower = entity.value.toLowerCase();
|
const entityLower = normalizeText(entity.value);
|
||||||
// Buscar entidade completa (case-insensitive)
|
// Buscar entidade completa (case-insensitive)
|
||||||
if (normalizedChunk.includes(entityLower)) {
|
if (normalizedChunk.includes(entityLower)) {
|
||||||
entityMatches += entity.confidence; // Ponderar por confiança
|
entityMatches += entity.confidence; // Ponderar por confiança
|
||||||
@@ -126,7 +126,7 @@ export function calculateSemanticSimilarity(
|
|||||||
if (context.topics.length > 0) {
|
if (context.topics.length > 0) {
|
||||||
let topicMatches = 0;
|
let topicMatches = 0;
|
||||||
for (const topic of context.topics) {
|
for (const topic of context.topics) {
|
||||||
const topicLower = topic.toLowerCase();
|
const topicLower = normalizeText(topic);
|
||||||
// Verificar se tópico aparece no chunk (pode ser parcial)
|
// Verificar se tópico aparece no chunk (pode ser parcial)
|
||||||
const topicWords = topicLower.split(/\s+/);
|
const topicWords = topicLower.split(/\s+/);
|
||||||
const matches = topicWords.filter(word =>
|
const matches = topicWords.filter(word =>
|
||||||
@@ -147,7 +147,7 @@ export function calculateSemanticSimilarity(
|
|||||||
if (context.synonyms.length > 0) {
|
if (context.synonyms.length > 0) {
|
||||||
let synonymMatches = 0;
|
let synonymMatches = 0;
|
||||||
for (const synonym of context.synonyms) {
|
for (const synonym of context.synonyms) {
|
||||||
const synonymLower = synonym.toLowerCase();
|
const synonymLower = normalizeText(synonym);
|
||||||
if (normalizedChunk.includes(synonymLower)) {
|
if (normalizedChunk.includes(synonymLower)) {
|
||||||
synonymMatches++;
|
synonymMatches++;
|
||||||
}
|
}
|
||||||
@@ -163,18 +163,18 @@ export function calculateSemanticSimilarity(
|
|||||||
// Verificar se contexto temporal/geográfico aparece no chunk
|
// Verificar se contexto temporal/geográfico aparece no chunk
|
||||||
let contextualScore = 0;
|
let contextualScore = 0;
|
||||||
if (context.temporalContext?.period) {
|
if (context.temporalContext?.period) {
|
||||||
if (normalizedChunk.includes(context.temporalContext.period)) {
|
if (normalizedChunk.includes(normalizeText(context.temporalContext.period))) {
|
||||||
contextualScore += 0.5;
|
contextualScore += 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context.temporalContext?.relative) {
|
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))) {
|
if (relativeTerms.some(term => normalizedChunk.includes(term))) {
|
||||||
contextualScore += 0.3;
|
contextualScore += 0.3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context.geographicContext?.location) {
|
if (context.geographicContext?.location) {
|
||||||
const locationLower = context.geographicContext.location.toLowerCase();
|
const locationLower = normalizeText(context.geographicContext.location);
|
||||||
if (normalizedChunk.includes(locationLower)) {
|
if (normalizedChunk.includes(locationLower)) {
|
||||||
contextualScore += 0.5;
|
contextualScore += 0.5;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user