Z24947

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z24947"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z23961",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z23961( Z23961K1 ) {\n\tvar input=Z23961K1;\n\tconst separators=[\" \",\"\\t\",\"/\",\"\\\\\",\"'\",'\"',\"|\"];\n\tconst prefOptions=[\"dmye\",\"yemd\",\"yedm\",\"mdye\"];\n \n\tfunction languageSpecificOptions(){\n\n\t\tdefineLiterals({\n\t\t\tac:-1n,\n\t\t\tdc:1n,\n\t\t\taec:-1n,\n\t\t\tec:1n,\n\t\t\tad:1n,\n\t\t\tbc:-1n,\n\t\t\tbce:-1n,\n\t\t\tce:1n,\n\t\t},ERA,LETTER_BY_LETTER);\n\t\t\n\t\tdefineLiterals({\n\t\t\tgennaio:0n,\n\t\t\tfebbraio:1n,\n\t\t\tmarzo:2n,\n\t\t\taprile:3n,\n\t\t\tmaggio:4n,\n\t\t\tgiugno:5n,\n\t\t\tluglio:6n,\n\t\t\tagosto:7n,\n\t\t\tsettembre:8n,\n\t\t\tottobre:9n,\n\t\t\tnovembre:10n,\n\t\t\tdicembre:11n\n\t\t}, MONTH);\n\t\t\n\t}\n\n\tconst DAY =0;\n\tconst MONTH=1;\n\tconst YEAR=2;\n\tconst ERA=3;\n\n\tconst BEFORE=10;\n\tconst AFTER=20;\n\tconst BEFORE_OR_AFTER=30;\n\n\tconst LENIENT=Symbol();\n\tconst NORMAL=Symbol();\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)==\"number\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\tfor (let m of meaning){\n\t\t\tswitch(m){\n\t\t\t\tcase 0: _day=bestGuess[0]; break;\n\t\t\t\tcase 1: _month=bestGuess[0]; break;\n\t\t\t\tcase 2: _year=bestGuess[0]; break;\n\t\t\t\tcase 3: _era=bestGuess[0]; break;\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)==\"number\"){\n\t\t\tmeaning=[meaning];\n\t\t}\n\t\tfor (let m of meaning){\n\t\t\tswitch(m){\n\t\t\t\tcase 0: _day=bestGuess[0]; break;\n\t\t\t\tcase 1: _month=bestGuess[0]; break;\n\t\t\t\tcase 2: _year=bestGuess[0]; break;\n\t\t\t\tcase 3: _era=bestGuess[0]; break;\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)==\"number\"){\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)==\"number\"){\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 BigInt(res);\n\t\t}\n\t\treturn null;\n\t}\n\n\n\tfunction forceToYear(s){\n\t\tlet res=(/-?\\+?[0-9]+/.exec(s))?.[0];\n\t\tif (res==null){\n\t\t\treturn false;\n\t\t}\n\t\t//Wikifunctions.Debug(res);\n\t\tif (res.length\u003E2) return true;\n\t\tif (res[0]==\"-\" || res[0]==\"+\") return true;\n\t\treturn false;\n\t}\n\n\t\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\t\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//Order of possibilities: dmye\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 _day=null;\n\t\tvar _month=null;\n\t\tvar _year=null;\n\t\tvar _era=null;\n\t\tvar _forced=null;\n\t\tvar _isToBeIgnored=false;\n\n\t\t//////////\n\n\t\tlanguageSpecificOptions();\n\n\t\tlet p=[];\n\t\t//day\n\t\tp.push(_day ?? ((n!=null \u0026\u0026 n\u003E0n \u0026\u0026 n\u003C=31n) ? n : null));\n\t\t//month\n\t\tp.push(_month ?? ((n!=null \u0026\u0026 n\u003E0n \u0026\u0026 n\u003C=12n) ? n-1n :null));\n\t\t//year\n\t\tp.push(_year ?? n);\n\t\t//epoch\n\t\tp.push(_era);\n\n\t\tif (_forced!=null){\n\t\t\tfor (let j=0; j\u003C=3; ++j){\n\t\t\t\tif (_forced.find((v)=\u003E(v==j)) == undefined){\n\t\t\t\t\tp[j]=null;\t\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (forceToYear(elements[iAtt])){\n\t\t\tp[0]=null;\n\t\t\tp[1]=null;\n\t\t\tp[3]=null;\n\t\t}\n\n\t\tif (!_isToBeIgnored)\n\t\t\tpossibilities.push(p);\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}\n\t\t\t}\n\t\t}\n\t}\n\n\tpossibilities=possibilities.filter((v)=\u003E(v[0]!=null || v[1]!=null || v[2]!=null || v[3]!=null));\n\n\tfor (let i=0; i\u003CprefOptions.length; ++i){\n\t\tlet actPref=prefOptions[i];\n\t\tlet d,m,y,e;\n\t\tif (possibilities.length\u003C4) actPref=actPref.replace(\"e\",\"\");\n\t\tfor (let j=0; j\u003CactPref.length; ++j){\n\t\t\tswitch(actPref[j]){\n\t\t\t\tcase \"d\":{\n\t\t\t\t\td=possibilities[j]?.[0]; break;\n\t\t\t\t}\n\t\t\t\tcase \"m\":{\n\t\t\t\t\tm=possibilities[j]?.[1]; break;\n\t\t\t\t}\n\t\t\t\tcase \"y\":{\n\t\t\t\t\ty=possibilities[j]?.[2]; break;\n\t\t\t\t}\n\t\t\t\tcase \"e\":{\n\t\t\t\t\te=possibilities[j]?.[3];break;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (d!=null \u0026\u0026 m!=null \u0026\u0026 y!=null){\n\t\t\tlet year;\n\t\t\tif (e!=null){\n\t\t\t\tyear = e==-1n ? -(y\u003C0n ? -y : y)+1n : (y\u003C0n ? -y : y);\n\t\t\t} else{\n\t\t\t\tyear=y;\n\t\t\t}\n\n\t\t\t// Wikifunctions.Debug({\n\t\t\t// \tK3: d,\n\t\t\t// \tK2: m,\n\t\t\t// \tK1: year\n\t\t\t// });\n\n\t\t\treturn{\n\t\t\t\tK3: Number(d),\n\t\t\t\tK2: Number(m),\n\t\t\t\tK1: (year)\n\t\t\t};\n\t\t}\n\t}\n\n\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1787",
                "Z11K2": "leggi data gregoriana italiana, refactored, js"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "read Gregorian date, refactored, it, js"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}