linguabot commited on
Commit
b3d3da8
·
verified ·
1 Parent(s): f50113b

Upload routes/tutorial-refinity.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. routes/tutorial-refinity.js +23 -2
routes/tutorial-refinity.js CHANGED
@@ -259,8 +259,29 @@ router.post('/compare-comments-with-corrections', async (req, res) => {
259
 
260
  // Sort by position
261
  annotationBasedItems.sort((a, b) => a.start - b.start || a.end - b.end);
262
-
263
- const mergedAnnotations = annotationBasedItems;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
  const lines = [];
266
  let pos = 0;
 
259
 
260
  // Sort by position
261
  annotationBasedItems.sort((a, b) => a.start - b.start || a.end - b.end);
262
+
263
+ // De-dupe identical annotations (same span/category/correction/flags).
264
+ // Without this, duplicated DB rows (or re-annotated identical spans) can cause the
265
+ // generator to literally duplicate the span text in the document body.
266
+ const mergedAnnotations = (() => {
267
+ const out = [];
268
+ const seen = new Set();
269
+ for (const it of annotationBasedItems) {
270
+ const key = [
271
+ it.start ?? '',
272
+ it.end ?? '',
273
+ String(it.category || ''),
274
+ String(it.replacementText || ''),
275
+ it.isDeleted ? '1' : '0',
276
+ it.isInsertion ? '1' : '0',
277
+ it.isMove ? '1' : '0',
278
+ ].join('|');
279
+ if (seen.has(key)) continue;
280
+ seen.add(key);
281
+ out.push(it);
282
+ }
283
+ return out;
284
+ })();
285
 
286
  const lines = [];
287
  let pos = 0;