23 lines
1.2 KiB
JavaScript
23 lines
1.2 KiB
JavaScript
/* Run the lexicon over 5,954 rows of real Spanish output and inspect EVERY
|
|||
|
|
change. A lexicon that corrupts correct Spanish is worse than no lexicon. */
|
||
|
|
const fs=require('fs'), vm=require('vm');
|
||
|
|
const B=require('./bible-lexicon.js');
|
||
|
|
const src=fs.readFileSync('engine.js','utf8');
|
||
|
|
const sb={console};vm.createContext(sb);
|
||
|
|
vm.runInContext(src.slice(src.indexOf('const SCRIPT_NO_SPACES'), src.indexOf('function applyFixes')), sb);
|
||
|
|
const rows=require('/tmp/es-corpus.json');
|
||
|
|
const bl=B.forLanguage('spa_Latn');
|
||
|
|
const pairs=Object.keys(bl).map(from=>({from,to:bl[from]}));
|
||
|
|
let n=0; const seen={};
|
||
|
|
for (const r of rows){
|
||
|
|
const es=String((r.tr&&r.tr.spa_Latn)||''); if(!es) continue;
|
||
|
|
const out=sb.applyTable(es,pairs);
|
||
|
|
if(out===es) continue; n++;
|
||
|
|
const a=es.split(/\s+/),b=out.split(/\s+/),d=[];
|
||
|
|
for(let i=0;i<Math.max(a.length,b.length);i++) if(a[i]!==b[i]) d.push((a[i]||'')+' -> '+(b[i]||''));
|
||
|
|
const k=d.join(' | '); seen[k]=(seen[k]||0)+1;
|
||
|
|
}
|
||
|
|
console.log('rows changed by the lexicon: '+n+' ('+(n/rows.length*100).toFixed(2)+'%)\n');
|
||
|
|
console.log('EVERY change:');
|
||
|
|
Object.entries(seen).sort((a,b)=>b[1]-a[1]).forEach(([d,c])=>console.log(' '+String(c).padStart(3)+'x '+d));
|