Spaces:
Sleeping
Sleeping
Upload routes/refinity.js with huggingface_hub
Browse files- routes/refinity.js +0 -73
routes/refinity.js
CHANGED
|
@@ -458,79 +458,6 @@ router.post('/compare-comments-with-corrections', async (req, res) => {
|
|
| 458 |
}
|
| 459 |
return out;
|
| 460 |
})();
|
| 461 |
-
|
| 462 |
-
// Gap-fill fallback: if there are real text edits between prev/current that are NOT covered by any
|
| 463 |
-
// annotation-derived span, add a sidebar comment with category=other and correction from `current`.
|
| 464 |
-
// This prevents "missing edits" on datasets where some revisions were made without saved highlights.
|
| 465 |
-
try {
|
| 466 |
-
const covered = mergedAnnotations
|
| 467 |
-
.filter(a => typeof a.start === 'number' && typeof a.end === 'number')
|
| 468 |
-
.map(a => ({ s: a.start, e: a.end }));
|
| 469 |
-
const overlapsAny = (s, e) => covered.some(r => !(e <= r.s || s >= r.e));
|
| 470 |
-
|
| 471 |
-
const diffParts = safeDiffTokens(prev, current);
|
| 472 |
-
let oldPos = 0;
|
| 473 |
-
for (let i = 0; i < diffParts.length; i++) {
|
| 474 |
-
const part = diffParts[i];
|
| 475 |
-
const val = Array.isArray(part.value) ? part.value.join('') : String(part.value || '');
|
| 476 |
-
|
| 477 |
-
if (part.removed) {
|
| 478 |
-
const removedText = val;
|
| 479 |
-
const start = oldPos;
|
| 480 |
-
const end = oldPos + removedText.length;
|
| 481 |
-
const next = diffParts[i + 1];
|
| 482 |
-
const nextVal = next && next.added ? (Array.isArray(next.value) ? next.value.join('') : String(next.value || '')) : '';
|
| 483 |
-
const hasReplacement = !!(next && next.added);
|
| 484 |
-
|
| 485 |
-
if (removedText && end > start && !overlapsAny(start, end)) {
|
| 486 |
-
mergedAnnotations.push({
|
| 487 |
-
start,
|
| 488 |
-
end,
|
| 489 |
-
removedText,
|
| 490 |
-
replacementText: hasReplacement ? nextVal : '',
|
| 491 |
-
category: 'other',
|
| 492 |
-
isDeleted: !hasReplacement,
|
| 493 |
-
isInsertion: false,
|
| 494 |
-
isMove: false,
|
| 495 |
-
});
|
| 496 |
-
covered.push({ s: start, e: end });
|
| 497 |
-
}
|
| 498 |
-
oldPos += removedText.length;
|
| 499 |
-
continue;
|
| 500 |
-
}
|
| 501 |
-
|
| 502 |
-
if (part.added) {
|
| 503 |
-
// Pure insertion (not a paired replacement): attach to a 1-char anchor in prev.
|
| 504 |
-
const addedText = val;
|
| 505 |
-
const prevPart = diffParts[i - 1];
|
| 506 |
-
const isPairedReplacement = !!(prevPart && prevPart.removed);
|
| 507 |
-
if (!isPairedReplacement && addedText) {
|
| 508 |
-
const anchor = Math.max(0, oldPos - 1);
|
| 509 |
-
const start = anchor;
|
| 510 |
-
const end = Math.min(prev.length, anchor + 1);
|
| 511 |
-
if (end > start && !overlapsAny(start, end)) {
|
| 512 |
-
mergedAnnotations.push({
|
| 513 |
-
start,
|
| 514 |
-
end,
|
| 515 |
-
removedText: prev.slice(start, end),
|
| 516 |
-
replacementText: addedText,
|
| 517 |
-
category: 'other',
|
| 518 |
-
isDeleted: false,
|
| 519 |
-
isInsertion: true,
|
| 520 |
-
isMove: false,
|
| 521 |
-
});
|
| 522 |
-
covered.push({ s: start, e: end });
|
| 523 |
-
}
|
| 524 |
-
}
|
| 525 |
-
continue;
|
| 526 |
-
}
|
| 527 |
-
|
| 528 |
-
// unchanged segment advances oldPos
|
| 529 |
-
oldPos += val.length;
|
| 530 |
-
}
|
| 531 |
-
|
| 532 |
-
mergedAnnotations.sort((a, b) => a.start - b.start || a.end - b.end);
|
| 533 |
-
} catch {}
|
| 534 |
} else {
|
| 535 |
// 1) Run diff to find ALL changes (like Show Diff does)
|
| 536 |
const diffParts = safeDiffTokens(prev, current);
|
|
|
|
| 458 |
}
|
| 459 |
return out;
|
| 460 |
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
} else {
|
| 462 |
// 1) Run diff to find ALL changes (like Show Diff does)
|
| 463 |
const diffParts = safeDiffTokens(prev, current);
|