part-type.cjs
Текст · 14 рядків
1// Тип деталі з назви ERP для оцінки пакування (R-28 П-28.11). Запуск з кореня: node research/lab/erp-profile/part-type.cjs
2const fs=require('fs');const m=new Map();
3for(const f of ['inc','mvd','sales'])for(const d of JSON.parse(fs.readFileSync(f+'.19.10.json','utf8')))for(const i of d.items)m.set(i.item_id,i);
4const items=[...m.values()];
5const firstAfterBrand=i=>{let n=i.item_name.trim();const b=i.producent_name.split(/[ (]/)[0];if(n.toUpperCase().startsWith(b.toUpperCase()))n=n.slice(b.length);return (n.trim().split(/\s+/)[0]||'').replace(/^[,.;:]+/,'');};
6const firstCyr=i=>(i.item_name.match(/[а-яіїєґ][а-яіїєґ'’-]{2,}/i)||[''])[0].toLowerCase();
7for(const [label,fn] of [['first word after brand',firstAfterBrand],['first Cyrillic word (lowercase)',firstCyr]]){
8 const c={};items.forEach(i=>{const k=fn(i);c[k]=(c[k]||0)+1});const e=Object.entries(c).sort((a,b)=>b[1]-a[1]);
9 const looksWord=k=>/^[а-яіїєґ'’-]{3,}$/i.test(k);
10 console.log('==',label,'distinct',e.length,'items as real word',items.filter(i=>looksWord(fn(i))).length,'/',items.length);
11 console.log(e.slice(0,25).map(([k,v])=>k+':'+v).join(' '));
12}
13const ex=items.filter(i=>!/^[а-яіїєґ'’-]{3,}$/i.test(firstAfterBrand(i))).slice(0,8).map(i=>i.item_name.slice(0,70));console.log(ex.join('\n'));
14