File size: 1,339 Bytes
714aaf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { parseBatchInput } from './text_preprocessing.js';
import { correctText } from './correction_inference.js';

export async function correctBatch(rawText, metadata, enrichResult) {
  const items = parseBatchInput(rawText);
  const results = [];
  for (let index = 0; index < items.length; index += 1) {
    const generation = await correctText(items[index], metadata);
    results.push({ rowId: index + 1, ...enrichResult(generation) });
  }
  return results;
}

export function downloadCsv(rows, filename = 'grammar_corrections.csv') {
  const headers = ['row_id','original_text','corrected_text','edit_count','error_categories','confidence_proxy','meaning_preservation','overcorrection_flag','latency_ms','inference_mode'];
  const escape = (value) => `"${String(value ?? '').replaceAll('"', '""')}"`;
  const lines = [headers.join(',')];
  rows.forEach((row) => lines.push([
    row.rowId,row.original,row.corrected,row.tracked.wordLevelEditCount,row.categories.categories.join('; '),row.confidence.score,row.meaning.score,row.over.flag,row.latencyMs,row.mode,
  ].map(escape).join(',')));
  const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' });
  const link = document.createElement('a');
  link.href = URL.createObjectURL(blob); link.download = filename; link.click(); URL.revokeObjectURL(link.href);
}