Z18358

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z18358"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z18335",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z610",
            "Z16K2": "import re\nimport json\n\ndef clean_text(text):\n    \"\"\"\n    Remove invisible or directionality control characters from the text.\n    \"\"\"\n    # Regular expression for stripping invisible characters and control characters\n    invisible_chars = re.compile(r'[\\u200e\\u200f\\u202a-\\u202e]+$')\n    return invisible_chars.sub(*, text.strip())\n\ndef Z18335(Z18335K1):\n    \"\"\"\n    Parse the wikitext into a list of JSON objects based on the MWON format.\n    \"\"\"\n    wikitext = Z18335K1\n    # Remove all ==Level 2 headers== without affecting the rest of the text\n    wikitext = re.sub(r'^==[^=]+==$', *, wikitext, flags=re.MULTILINE)\n\n    sections = []\n    level3_sections = re.split(r'===\\s*(.*?)\\s*===', wikitext)\n    level3_sections = level3_sections[1:]  # Discard everything before the first Level 3 header\n\n    for i in range(0, len(level3_sections), 2):\n        section_id = clean_text(level3_sections[i].strip())\n        content = level3_sections[i+1].strip()\n        section_obj = {\"id\": section_id}\n\n        # Process the bullet points and key-value pairs\n        lines = content.split('\n')\n        key = None\n        for line in lines:\n            line = clean_text(line.strip())\n            if line.startswith('* '):\n                if ':' in line:\n                    key, value = line[2:].split(':', 1)\n                    key = clean_text(key.strip())\n                    value = clean_text(value.strip())\n                    if not value:\n                        section_obj[key] = []\n                    else:\n                        section_obj[key] = value\n                else:\n                    key = clean_text(line[2:].strip())\n                    if key not in section_obj:\n                        section_obj[key] = []\n            elif line.startswith('** ') and key:\n                section_obj[key].append(clean_text(line[3:].strip()))\n            elif line:\n                # Text after the key-value pairs\n                cleaned_line = clean_text(line)\n                if \"section body\" not in section_obj:\n                    section_obj[\"section body\"] = cleaned_line\n                else:\n                    section_obj[\"section body\"] += f\" {cleaned_line}\"\n\n        # Clean up and consolidate the object\n        if key in section_obj and isinstance(section_obj[key], list) and not section_obj[key]:\n            del section_obj[key]  # Remove empty lists if they were not populated\n\n        sections.append(section_obj)\n\n    return json.dumps(sections)"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "Python implementation V1"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1430",
                "Z11K2": "Wikitext-Konfigurationsseite parsen in Python"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}