fivetech commited on
Commit
53ed033
·
verified ·
1 Parent(s): bef0e95

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +16 -7
index.html CHANGED
@@ -588,24 +588,33 @@ async function loadModel(repo, file) {
588
  let KB = [];
589
  fetch('knowledge.json').then(r => r.ok ? r.json() : []).then(k => {
590
  KB = k;
591
- KB.forEach(e => { e._t = tok(e.title); e._x = tok(e.title + ' ' + e.text); });
592
  console.log('KB entradas:', KB.length);
593
  }).catch(() => {});
594
- const KB_STOP = new Set(('de la el en los del se las por un una para con no su al lo como mas o pero sus le ya este esta entre cuando muy sin sobre tambien hasta hay donde quien desde todo nos durante uno les ni contra otros ese eso ante ellos esto antes algunos que unos yo otro otras otra tanto esa estos mucho quienes nada muchos cual sea poco ella estar haber estas the is are was were for with that this from have has not but what all can you your their they them his her its our who how when where which will would there been more other into could than then some any each most over such only also and use used using get set com para como una con por que los las del').split(/\s+/));
595
  function tok(s) {
596
  s = (s || '').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '');
597
  return s.split(/[^a-z0-9_$]+/).filter(w => w.length >= 3 && !KB_STOP.has(w));
598
  }
599
- function kbRetrieve(query, agentName, maxChars = 1700, k = 4) {
 
 
600
  if (!KB.length) return '';
601
- const qt = new Set(tok(query));
 
602
  if (!qt.size) return '';
603
  const scored = [];
604
  for (const e of KB) {
605
  let sc = 0;
606
  for (const w of qt) {
607
- if (e._t.includes(w)) sc += 3;
608
- else if (e._x.includes(w)) sc += 1;
 
 
 
 
 
 
609
  }
610
  if (/^Harbour/i.test(agentName) && e.src.indexOf('harbour/core') === 0) sc *= 1.7;
611
  if (/^FiveWin/i.test(agentName) && e.src.indexOf('Foro') === 0) sc *= 1.7;
@@ -617,7 +626,7 @@ function kbRetrieve(query, agentName, maxChars = 1700, k = 4) {
617
  let out = '', n = 0;
618
  for (const [sc, e] of scored) {
619
  if (n >= k || out.length + e.text.length > maxChars) break;
620
- out += `\n[${e.title} \u2014 ${e.src}]\n${e.text}\n`;
621
  n++;
622
  }
623
  return out.trim();
 
588
  let KB = [];
589
  fetch('knowledge.json').then(r => r.ok ? r.json() : []).then(k => {
590
  KB = k;
591
+ KB.forEach(e => { e._t = tok(e.title); e._x = tok(e.title + ' ' + e.text); e._ts = ' ' + e._t.join(' ') + ' '; e._xs = ' ' + e._x.join(' ') + ' '; });
592
  console.log('KB entradas:', KB.length);
593
  }).catch(() => {});
594
+ const KB_STOP = new Set(('de la el en los del se las por un una para con no su al lo como mas o pero sus le ya este esta entre cuando muy sin sobre tambien hasta hay donde quien desde todo nos durante uno les ni contra otros ese eso ante ellos esto antes algunos que unos yo otro otras otra tanto esa estos mucho quienes nada muchos cual sea poco ella estar haber estas the is are was were for with that this from have has not but what all can you your their they them his her its our who how when where which will would there been more other into could than then some any each most over such only also and use used using get set com para como una con por que los las del fivewin fwh harbour aplicacion app usar cliente clientes client ver hacer').split(/\s+/));
595
  function tok(s) {
596
  s = (s || '').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '');
597
  return s.split(/[^a-z0-9_$]+/).filter(w => w.length >= 3 && !KB_STOP.has(w));
598
  }
599
+ const KB_EXP = { dialogo:['dialog'], dialogos:['dialog'], ventana:['window'], ventanas:['window'], cadena:['string'], tabla:['table','dbf'], tablas:['table','dbf'], indice:['index'], indices:['index'], campo:['field'], campos:['field'], boton:['button'], botones:['button'], informe:['report'], informes:['report'], impresora:['printer'], imprimir:['print'], migrar:['migrate'], migracion:['migration'], conectar:['connect'], conexion:['connection'], datos:['data'], codigo:['code'], archivo:['file'], fichero:['file'], carpeta:['folder'], buscar:['search'], correo:['mail','smtp'], navegador:['webview','browser'], compilador:['compiler'], compilar:['build','compile'], libreria:['library'], funcion:['function'], funciones:['function'], clase:['class'], clases:['class'], metodo:['method'], metodos:['method'], propiedad:['property'], propiedades:['property'], evento:['event'], eventos:['event'], pestana:['tab'], cinta:['ribbon'], calendario:['calendar'], grafico:['graph'], imagen:['image'], usuario:['user'], contrasena:['password'], factura:['invoice'], pedido:['order'], cliente:['client'], clientes:['client'], proveedor:['supplier'], listado:['list'], cuadro:['box'], crear:['create'], creo:['create'], ejemplo:['example'], ejemplos:['example'], error:['error'], errores:['error'], barras:['barcode'] };
600
+ function kbNgrams(w, n = 6) { if (w.length <= n) return [w]; const g = []; for (let i = 0; i + n <= w.length; i++) g.push(w.slice(i, i + n)); return g; }
601
+ function kbRetrieve(query, agentName, maxChars = 3000, k = 5) {
602
  if (!KB.length) return '';
603
+ const qt = new Set();
604
+ for (const w of tok(query)) { qt.add(w); (KB_EXP[w] || []).forEach(x => qt.add(x)); }
605
  if (!qt.size) return '';
606
  const scored = [];
607
  for (const e of KB) {
608
  let sc = 0;
609
  for (const w of qt) {
610
+ if (e._t.includes(w)) { sc += 3; continue; }
611
+ if (w.length >= 3 && e._t.some(t => (t.length >= 4 && (t.includes(w) || w.includes(t))))) { sc += 2; continue; }
612
+ if (e._x.includes(w)) { sc += 1; continue; }
613
+ if (w.length >= 6) {
614
+ const gs = kbNgrams(w);
615
+ if (gs.some(g => e._ts.includes(g))) { sc += 2; continue; }
616
+ if (gs.some(g => e._xs.includes(g))) { sc += 0.5; }
617
+ }
618
  }
619
  if (/^Harbour/i.test(agentName) && e.src.indexOf('harbour/core') === 0) sc *= 1.7;
620
  if (/^FiveWin/i.test(agentName) && e.src.indexOf('Foro') === 0) sc *= 1.7;
 
626
  let out = '', n = 0;
627
  for (const [sc, e] of scored) {
628
  if (n >= k || out.length + e.text.length > maxChars) break;
629
+ out += `\n[${e.title} \u2014 ${e.src}]\n${e.text.slice(0, 1000)}\n`;
630
  n++;
631
  }
632
  return out.trim();