Z26418

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z26418"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z25683",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z25683( Z25683K1 ) {\n\tvar input=Z25683K1;\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\t\n\t\tdefineLiterals({\n\t\t\tmorning:AM,\n\t\t\tafternoon:PM\n\t\t},AMPM,NORMAL);\n\t\t\n\t\tdefineLiterals({\n\t\t\tnoon:12,\n\t\t\t\"12 noon\":12,\n\t\t\tmidday:12,\n\t\t\t\"12 midday\": 12,\n\t\t\tmidnight:0,\n\t\t\t\"12 midnight\":0,\n\t\t},HOUR,NORMAL);\n\t\t\n\t\tdefineConstraint([\"h\"],HOUR,AFTER);\n\t\tdefineConstraint([\"m\",\"'\"],MINUTE,AFTER);\n\t\tdefineConstraint([\"s\",'\"',\"''\"],SECOND,AFTER);\n\t}\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\tconst delete_chain=\"smah\";\n\n\tconst HOUR='h';\n\tconst MINUTE='m';\n\tconst SECOND='s';\n\tconst AMPM='a';\n\n\tconst AM=Symbol();\n\tconst PM=Symbol();\n\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\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\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\t_currGuess[m]=bestGuess[0];\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\t_currGuess[m]=bestGuess[0];\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\n\n\n\t\n\t/**************** START TOKENISATION ***********************/\n\n\tinput=input.replaceAll(/-|—|‒|–|—|⸺|⸺/g,\"-\");\n\n\tvar isoRegex=/(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+)|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d)|(\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d)/;\n\tif (isoRegex.exec(input)){\n\t\tinput=input.split(\"T\")[0];\n\t\tvar list=input.split(/(?\u003C=.)-(?=.)/);\n\t\t//Wikifunctions.Debug(list);\n\t\treturn {\n\t\t\tK1: BigInt(list[0]),\n\t\t\tK2: list[1]-1,\n\t\t\tK3: list[2]\n\t\t};\n\t}\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\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\t// elSeparato.push(/-?\\+?[0-9]+/.exec(elements[i]));\n\t\t// elSeparato.push(elements[i].split(/-?\\+?[0-9]+/));\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 safeLetters=\"\";\n\tif(delete_chain.length\u003Epossibilities.length){\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];\n\t\t\t}\n\t\t}\n\t}\n\n\n\n\t//remove elements according to the deletion chain\n\tfor(let i=0; delete_chain.length-lettersToRemove.length\u003Epossibilities.length \u0026\u0026 i\u003Cdelete_chain.length; ++i){\n\t\tif (lettersToRemove.indexOf(delete_chain[i])== -1 \u0026\u0026 safeLetters.indexOf(delete_chain[i])==-1){\n\t\t\tlettersToRemove+= delete_chain[i];\n\t\t}\n\t}\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\tfor (let l of lettersToRemove){\n\t\t\tactPref=actPref.replace(l,\"\");\n\t\t}\n\t\t\n\t\tlet ok=true;\n\t\tfor (let j=0; j\u003CactPref.length; ++j){\n\t\t\telementsFound[actPref[j]]=possibilities[j]?.[actPref[j]];\n\t\t\tif (elementsFound[actPref[j]] == 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\treturn formatOutput(elementsFound);\t\n\t\t}\n\t}\n\n\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1787",
                "Z11K2": "leggi Orario, en, js, codice generico"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "read Time of day, English, javascript"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}