Z26403

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z26403"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z25127",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z25127( Z25127K1 ) {\n\tvar input=Z25127K1;\n\tconst separators=[\" \",\"\\t\",\"/\",\"\\\\\",\":\",\".\",\"|\"];\n\tconst prefOptions=[\"ahms\", \"hmsa\", \"hams\"];\n\n\tfunction languageSpecificOptions(){\n\t\tdefineLiterals({\n\t\t\tam:AM,\n\t\t\tpm:PM,\n\t\t\ta:AM,\n\t\t\tp:PM,\n\t\t\t\"㏂\":AM,\n\t\t\t\"㏘\":PM\n\t\t},AMPM,LETTER_BY_LETTER);\n\t\tdefineConstraint([\"h\"],HOUR,AFTER);\n\t\tdefineConstraint([\"m\",\"'\"],MINUTE,AFTER);\n\t\tdefineConstraint([\"s\",'\"',\"''\"],SECOND,AFTER);\n\t}\n\t\n\tfunction formatOutput(o){\n\t\tlet h= o[HOUR]??0;\n\t\tif (o[AMPM]==AM \u0026\u0026 h==12){\n\t\t\th=0;\n\t\t} else if (o[AMPM]==PM \u0026\u0026 h!=12){\n\t\t\th+=12;\n\t\t}\n\t\tif (h==24) h=0;\n\t\treturn {K1:h, K2: o[MINUTE]??0, K3: o[SECOND]??0};\n\t}\n\n\n\t//IMPORTANT: delete_chain must contain all the fields\n\tconst delete_chain=\"smah\";\n\n\t// FIELDS\n\tconst HOUR='h';\n\tconst MINUTE='m';\n\tconst SECOND='s';\n\tconst AMPM='a';\n\n\t// SPECIAL VALUES\n\tconst AM=Symbol();\n\tconst PM=Symbol();\n\n\t// NUMERIC ELEMENTS SETTINGS\n\tconst numericElements=\"hms\";\n\tconst numericElementMin={\n\t\th:0,\n\t\tm:0,\n\t\ts:0\n\t};\n\tconst numericElementMax={\n\t\th:24,\n\t\tm:59,\n\t\ts:60\t//for leap seconds\n\t}\n\n\t//END OF LANGUAGE-SPECIFIC CODE\n\t\n\t//Start of general code\n\tconst BEFORE=10;\n\tconst AFTER=20;\n\tconst BEFORE_OR_AFTER=30;\n\n\tconst LENIENT=true;\n\tconst NORMAL=false;\n\tconst LETTER_BY_LETTER=Symbol();\n\t\n\tfunction MultipleMeanings(m,e){\n\t\tfor (let i=0; i\u003Cm.length; ++i){\n\t\t\tthis[m[i]]=e[i];\n\t\t}\n\t}\n\n\tfunction defineLiterals(literals,meaning,compMode=LENIENT, forced=false){\n\t\tlet bestGuess=null;\n\t\tconst compFunc= compMode==LENIENT ? lenientComp : lessLenientComp;\n\t\tfor (let m in literals){\n\t\t\tlet target=m.split(\" \");\n\t\t\tlet ok=true;\n\t\t\tfor (let t=0; t\u003Ctarget.length; ++t){\n\t\t\t\tif (elements[iAtt+t]==undefined || !compFunc(elements[iAtt+t],target[t])){\n\t\t\t\t\tok=false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok){\n\t\t\t\tif (bestGuess == null || bestGuess[1]\u003Ctarget.length){\n\t\t\t\t\tbestGuess = [literals[m],target.length];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (compMode==LETTER_BY_LETTER ){\n\t\t\t\tlet target=m.split(\"\");\n\t\t\t\ttarget.filter((l)=\u003El!=\" \");\n\t\t\t\tlet ok=true;\n\t\t\t\tfor (let t=0; t\u003Ctarget.length; ++t){\n\t\t\t\t\tif (elements[iAtt+t]==undefined || !compFunc(elements[iAtt+t],target[t])){\n\t\t\t\t\t\tok=false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ok){\n\t\t\t\t\tif (bestGuess == null || bestGuess[1]\u003Ctarget.length){\n\t\t\t\t\t\tbestGuess = [literals[m],target.length];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\tfor (let m of meaning){\n\t\t\tif (m.length\u003E1){\n\t\t\t\tlet o=new MultipleMeanings(m,bestGuess[0]);\n\t\t\t\tfor (let mAtt of m){\n\t\t\t\t\t_currGuess[mAtt]=o;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t_currGuess[m]=bestGuess[0];\n\t\t\t}\n\t\t}\n\t\t_nSteps=bestGuess[1];\n\t\tif (forced){\n\t\t\t_forced=meaning;\n\t\t}\n\t\treturn true;\n\n\t}\n\tfunction defineLiteralFunction(f,meaning, forced=false){\n\t\tlet bestGuess=f(elements,iAtt);\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\tfor (let m of meaning){\n\t\t\tif (m.length\u003E1){\n\t\t\t\tlet o=new MultipleMeanings(m,bestGuess[0]);\n\t\t\t\tfor (let mAtt of m){\n\t\t\t\t\t_currGuess[mAtt]=o;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t_currGuess[m]=bestGuess[0];\n\t\t\t}\n\t\t}\n\t\t_nSteps=bestGuess[1];\n\t\tif (forced){\n\t\t\t_forced=meaning;\n\t\t}\n\t\treturn true;\n\t}\n\tfunction defineConstraint(literals, meaning, position, compMode=NORMAL){\n\n\t\tlet bestGuess=null;\n\t\tconst compFunc= compMode==LENIENT ? lenientComp : lessLenientComp;\n\t\tfor (let m of literals){\n\t\t\tlet target=m.split(\" \");\n\t\t\tlet ok=true;\n\t\t\tfor (let t=0; t\u003Ctarget.length; ++t){\n\t\t\t\tif (elements[iAtt+t]==undefined || !compFunc(elements[iAtt+t],target[t])){\n\t\t\t\t\tok=false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok){\n\t\t\t\tif (bestGuess == null || bestGuess\u003Ctarget.length){\n\t\t\t\t\tbestGuess = target.length;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\t\t\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\t\n\t\t_constraintsList.push({pos:possibilities.length, meaning:meaning, type: position});\n\n\t\t_nSteps=bestGuess;\n\t\t_isToBeIgnored=true;\n\t\treturn true;\n\t}\n\tfunction defineConstraintFunction(f,meaning,position){\n\n\t\tlet bestGuess=f(elements,iAtt);\n\t\tif (bestGuess==null){\n\t\t\treturn false;\n\t\t}\n\n\t\tif (typeof(meaning)==\"string\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\t_constraintsList.push({pos:possibilities.length, meaning:meaning, type: position});\n\t\t_nSteps=bestGuess;\n\t\t_isToBeIgnored=true;\n\t\treturn true;\n\t}\n\n\tfunction lenientComp(a,b){\n\t\ta=a.toLowerCase().replaceAll(/,|\\.|;|:/g,\"\");\n\t\tb=b.toLowerCase();\n\t\tif (a==\"\") return false;\n\t\treturn a==b.substring(0,a.length);\n\t}\n\n\tfunction lessLenientComp(a,b){\n\t\ta=a.toLowerCase().replaceAll(/,|\\.|;|:/g,\"\");\n\t\tb=b.toLowerCase();\n\t\tif (a==\"\") return false;\n\t\treturn a==b;\n\t}\n\n\tfunction extractNumber(s){\n\t\tlet res=/-?[0-9]+/.exec(s);\n\t\tif (res!=null){\n\t\t\treturn Number(res);\n\t\t}\n\t\treturn null;\n\t}\n\t\n\tfunction isValidTime(t){\n\t\tif (t==null || t.K1==undefined || t.K2==undefined || t.K3==undefined){\n\t\t\treturn false;\n\t\t}\n\t\tif (!isFinite(t.K1)||!isFinite(t.K2)||!isFinite(t.K3)){\n\t\t\treturn false;\n\t\t}\n\t\tif (t.K1\u003C0 || t.K1\u003E=24){\n\t\t\treturn false;\n\t\t}\n\t\tif (t.K2\u003C0 || t.K2\u003E=60){\n\t\t\treturn false;\n\t\t}\n\t\tif (t.K1===23 \u0026\u0026 t.K2===59 \u0026\u0026 t.K3===60){\n\t\t\treturn true;\n\t\t}\n\t\tif (t.K3\u003C0 || t.K3\u003E=60){\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\n\n\t\n\t/**************** START TOKENISATION ***********************/\n\n\tinput=input.replaceAll(/-|—|‒|–|—|⸺|⸺/g,\"-\");\n\n\n\tvar elements=[\"\"];\n\tfor (let i=0; i\u003Cinput.length;){\n\t\tlet s=separators.find((v)=\u003E input.substring(i,i+v.length)==v);\n\t\tif (s!==undefined){\n\t\t\tif(elements[elements.length-1]!=\"\")\n\t\t\t\telements.push(\"\");\n\t\t\ti+=s.length;\n\t\t\tcontinue;\n\t\t}\n\t\telements[elements.length-1]+=input[i++];\n\t}\n\tif(elements[elements.length-1]==\"\") elements.pop();\n\n\n\tlet elSeparato=[];\n\tfor (let i=0; i\u003Celements.length; ++i){\n\t\t//Separate numbers from text\n\t\tfor (let e of elements[i].matchAll(/((?:(?\u003C=^|\\s)[\\-\\+])?[0-9]+)?(?:\\-?([^0-9\\-]+))?/g)){\n\t\t\telSeparato.push(e.splice(1))\n\t\t}\n\t}\n\telSeparato=elSeparato.flat();\n\telements=elSeparato.filter((v)=\u003E(v!=null \u0026\u0026 v!=\"\"));\n\n\t// Wikifunctions.Debug(\"elements:\");\n\t// Wikifunctions.Debug(elements);\n\n\t/**************** END TOKENISATION ***********************/\n\t/**************** START FINDING POSSIBILITIES ***********************/\n\tvar possibilities=[];\n\n\tvar _constraintsList=[];\n\tvar _nSteps=1;\n\n\tfor(var iAtt=0; iAtt\u003Celements.length; iAtt+=_nSteps){\n\t\t_nSteps=1;\n\t\tlet n=extractNumber(elements[iAtt]);\n\t\tvar _currGuess={};\t//Object containing all the current guesses\n\t\tvar _forced=null;\n\t\tvar _isToBeIgnored=false;\n\n\t\t//////////\n\n\t\tlanguageSpecificOptions();\n\n\t\tfor (let i of numericElements){\n\t\t\tif (n\u003E=numericElementMin[i] \u0026\u0026 n\u003C=numericElementMax[i]){\n\t\t\t\t_currGuess[i]??=n;\n\t\t\t}\n\t\t}\n\n\n\n\t\tif (_forced!=null){\n\t\t\tfor (let j in _currGuess){\n\t\t\t\tif (_forced.find((v)=\u003E(v==j)) == undefined){\n\t\t\t\t\t_currGuess[j]=null;\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!_isToBeIgnored)\n\t\t\tpossibilities.push(_currGuess);\n\t}\n\t\n\n\tif (_constraintsList.length\u003E0){\n\t\tfor (let pAtt=0; pAtt\u003C possibilities.length; ++pAtt){\n\t\t\tfor (let c of _constraintsList){\n\t\t\t\tif ((c.type==AFTER \u0026\u0026 pAtt!=c.pos-1) ||\n\t\t\t\t    (c.type==BEFORE \u0026\u0026 pAtt!=c.pos) ||\n\t\t\t\t    (c.type==BEFORE_OR_AFTER \u0026\u0026 pAtt!=c.pos-1 \u0026\u0026 pAtt!=c.pos)){\n\t\t\t\t\tfor(let m of c.meaning){\n\t\t\t\t\t\tpossibilities[pAtt][m]=null;\t\n\t\t\t\t\t}\n\t\t\t\t} else if ((c.type==AFTER \u0026\u0026 pAtt==c.pos-1) ||\n\t\t\t\t\t(c.type==BEFORE \u0026\u0026 pAtt==c.pos)){\n\t\t\t\t\tfor (let m in possibilities[pAtt]){\n\t\t\t\t\t\tif (c.meaning.find((x)=\u003E x==m)==undefined){\n\t\t\t\t\t\t\tpossibilities[pAtt][m]=null;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t/**************** END FINDING POSSIBILITIES ***********************/\n\n\n\tpossibilities=possibilities.filter((v)=\u003E(Object.entries(v).filter((x)=\u003Ex[1]!=null).length\u003E0));\n\n\t//remove elements that are not present\n\tlet lettersToRemove=\"\";\n\tif(delete_chain.length\u003Epossibilities.length){\n\t\tfor (let i of delete_chain){\n\t\t\tif (possibilities.find((p)=\u003Ep[i]!=null)==undefined){\n\t\t\t\tlettersToRemove+=i;\n\t\t\t}\n\t\t}\n\t}\n\n\t//save tokens that have only one possibility\n\tlet nLettersToMantain=0;\n\tfor (let p of possibilities){\n\t\tlet currn=1;\n\t\tfor (let e in p){\n\t\t\tif (p[e] instanceof MultipleMeanings){\n\t\t\t\tcurrn=Math.max(currn,Object.entries(p[e]).length);\n\t\t\t}\n\t\t}\n\t\tnLettersToMantain+=currn;\n\t}\n\t\n\tlet safeLetters=\"\";\n\tlet compulsoryLetters=\"\";\n\tif(delete_chain.length\u003EnLettersToMantain){\n\t\tfor (let p of possibilities){\n\t\t\tif (Object.entries(p).filter((x)=\u003Ex[1]!=null).length ==1){\n\t\t\t\tsafeLetters+=Object.entries(p).filter((x)=\u003Ex[1]!=null)[0][0];\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\tfor (let c of _constraintsList){\n\t\tif (c.meaning.length!==1){\n\t\t\tcontinue;\n\t\t}\n\t\tif(!compulsoryLetters.includes(c.meaning[0])){\n\t\t\tcompulsoryLetters+=c.meaning[0];\n\t\t}\n\t}\n\n\n\n\t\t/**************** CHECK OF ALL ORDERS ***********************/\n\t\n\tfor (let i=0; i\u003CprefOptions.length; ++i){\n\t\tlet actPref=prefOptions[i];\n\t\tlet elementsFound={};\n\t\t\n\t\t\n\t\tlet localLettersToRemove=lettersToRemove;\n\t\t//remove elements according to the deletion chain\n\t\tfor (let i=0; i\u003Cdelete_chain.length; ++i){\n\t\t\tif (actPref.indexOf(delete_chain[i])===-1){\n\t\t\t\tlocalLettersToRemove+=delete_chain[i];\n\t\t\t}\n\t\t}\n\t\tfor(let i=0; delete_chain.length-localLettersToRemove.length\u003EnLettersToMantain \u0026\u0026 i\u003Cdelete_chain.length; ++i){\n\t\t\tif (localLettersToRemove.indexOf(delete_chain[i])== -1 \u0026\u0026 safeLetters.indexOf(delete_chain[i])==-1){\n\t\t\t\tlocalLettersToRemove+= delete_chain[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (let l of localLettersToRemove){\n\t\t\tactPref=actPref.replace(l,\"\");\n\t\t}\n\t\tlet actPrefIt=actPref[Symbol.iterator]();\n\t\tlet currActPrefObj=actPrefIt.next();\n\t\t\n\t\tlet ok=true;\n\t\tfor (let j=0; j\u003Cpossibilities.length \u0026\u0026 !currActPrefObj.done; ++j){\n\t\t\twhile (elementsFound[currActPrefObj.value]!=undefined){\n\t\t\t\tcurrActPrefObj=actPrefIt.next();\n\t\t\t\tif (currActPrefObj.done){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (currActPrefObj.done){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (possibilities[j]?.[currActPrefObj.value] instanceof MultipleMeanings){\n\t\t\t\tfor (let m in possibilities[j][currActPrefObj.value]){\n\t\t\t\t\telementsFound[m]=possibilities[j][currActPrefObj.value][m];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\telementsFound[currActPrefObj.value]=possibilities[j]?.[currActPrefObj.value];\n\t\t\t\tif (elementsFound[currActPrefObj.value] == null){\n\t\t\t\t\tok=false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tcurrActPrefObj=actPrefIt.next();\n\t\t}\n\t\tfor (let f of safeLetters){\n\t\t\tif (actPref.includes(f) \u0026\u0026 elementsFound[f]==null){\n\t\t\t\tok=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor (let f of compulsoryLetters){\n\t\t\tif (elementsFound[f]==null){\n\t\t\t\tok=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ok){\n\t\t\tlet r= formatOutput(elementsFound);\t\n\t\t\tif (isValidTime(r)){\n\t\t\t\treturn r;\n\t\t\t}\n\t\t}\n\t}\n\n\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1787",
                "Z11K2": "leggi Orario, multilingue, codice generico, js"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "read Time of day, generic code, javascript"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1787",
                "Z11K2": "Codice flessibile per rendere più semplice la localizzazione"
            }
        ]
    }
}