示例#1
0
    def __init__(self,
                 wikicode: Wikicode,
                 subordinates: List[Wikicode],
                 header_type: str = None,
                 idx: int = None,
                 metainfo=None,
                 lvl: int = 3):
        assert wikicode.startswith("=" * lvl) and not wikicode.startswith(
            "=" * (lvl + 1))  # assert that the level is correct
        if header_type is None:  # auto header type deduce
            breve: str = wikicode[
                lvl:]  # len("===") == 3 # "===Pronunciation===" --> "Pronunciation==="
            header_type = breve[:breve.index(
                "=" * lvl)]  # "Pronunciation===" -> "Pronunciation"

            if idx is None and header_type.startswith(
                    "Etymology "):  # auto idx deduce
                assert len(header_type) >= 11  # len("Etymology 1")
                idx = int(header_type[10:])
                assert idx and type(idx) == int
                header_type = "Etymology"
            defn_flag = header_type in poscodes.all
            if defn_flag and metainfo is None:
                metainfo = "Definition"

        self.wikicode = wikicode
        self.subordinates = subordinates
        self.idx = idx
        self.header_type = header_type
        self.metainfo = header_type if metainfo is None else metainfo  # TODO: make it into an enum
        self.lvl = lvl
示例#2
0
def is_defn(wc: Wikicode):

    return any(wc.startswith("===" + x)
               for x in all) or any(wc.startswith("====" + x)
                                    for x in all)  #TODO: support lvl5 headers