MediaWiki:Gadget-LabelScan.js: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 36: Zeile 36:
     await loadTesseract();
     await loadTesseract();


     return Tesseract.recognize(file, "eng", {
     return Tesseract.recognize(file, "deu+eng", {
      logger: m => { /* kein Fortschritt nötig */ }
    tessedit_char_whitelist: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -'()",
    tessedit_pageseg_mode: 6,
    logger: m => { /* Fortschritt optional */ }
     }).then(r => r.data.text || "");
     }).then(r => r.data.text || "");
   }
   }


   // Sucht nach Destillerie & Alter
   // Sucht nach Destillerie & Alter
  function extractQuery(text) {
function extractQuery(text) {
    text = text.replace(/\s+/g, " ");
  text = text.replace(/\s+/g, " ");


    const dist = text.match(/\b([A-Z][a-z]{3,})\b/);
  const names = text.match(/\b([A-Z][a-z]{3,})\b/g) || [];
    const age = text.match(/\b([1-3]?\d)\s?(years?|yo|Jahre)\b/i);
  const ages = text.match(/\b([1-3]?\d)\s?(years?|yo|Jahre|Jahr)\b/gi) || [];
  const years = text.match(/\b(19|20)\d{2}\b/g) || [];


    let parts = [];
  const parts = [...names.slice(0, 2), ...ages.slice(0, 1), ...years.slice(0, 1)];
    if (dist) parts.push(dist[1]);
    if (age) parts.push(age[1]);


    return parts.join(" ");
  return parts.join(" ");
  }
}


   async function searchWiki(q) {
   async function searchWiki(q) {