コード例 #1
0
def add_struct(pack: DataPack, struct_statements: List):
    for nif_range, rel, struct_type in struct_statements:
        r = get_resource_fragment(rel)
        if r == 'type':
            range_ = get_resource_attribute(nif_range, 'char')
            begin, end = [int(d) for d in range_.split(',')]

            if end > len(pack.text):
                # Some nif dataset are off by a bit, mostly when there are
                # new line characters, we cannot correct them.
                # but we need to make sure they don't go longer than the text.
                logging.info(
                    "NIF Structure end is %d by %s, "
                    "clipped to fit with the text.", end, nif_range)
                end = len(pack.text)

            if end <= begin:
                logging.info("Provided struct [%d:%d] is invalid.", begin, end)
                continue

            struct_ = get_resource_fragment(struct_type)

            if struct_ == 'Section':
                WikiSection(pack, begin, end)
            elif struct_ == 'Paragraph':
                WikiParagraph(pack, begin, end)
            elif struct_ == 'Title':
                WikiTitle(pack, begin, end)
            else:
                logging.warning("Unknown struct type: %s", struct_type)
コード例 #2
0
def add_struct(pack: DataPack, struct_statements: List):
    for nif_range, rel, struct_type in struct_statements:
        r = get_resource_fragment(rel)
        if r == 'type':
            range_ = get_resource_attribute(nif_range, 'char')
            begin, end = [int(d) for d in range_.split(',')]

            struct_ = get_resource_fragment(struct_type)

            if struct_ == 'Section':
                section = WikiSection(pack, begin, end)
                pack.add_entry(section)
            elif struct_ == 'Paragraph':
                para = WikiParagraph(pack, begin, end)
                pack.add_entry(para)
            elif struct_ == 'Title':
                title = WikiTitle(pack, begin, end)
                pack.add_entry(title)
            else:
                logging.warning("Unknown struct type: %s", struct_type)
コード例 #3
0
    def add_wiki_info(self, pack: DataPack, statements: List):
        for nif_range, rel, struct_type in statements:
            r = get_resource_fragment(rel)
            if r is not None and r == "type":
                range_ = get_resource_attribute(nif_range, "char")
                if range_ is None:
                    continue

                begin, end = [int(d) for d in range_.split(",")]

                if end > len(pack.text):
                    # Some nif dataset are off by a bit, mostly when there
                    # are new line characters, we cannot correct them.
                    # but we need to make sure they don't go longer than
                    # the text.
                    logging.info(
                        "NIF Structure end is %d by %s, "
                        "clipped to fit with the text.",
                        end,
                        nif_range,
                    )
                    end = len(pack.text)

                if end <= begin:
                    logging.info(
                        "Provided struct [%d:%d] is invalid.", begin, end
                    )
                    continue

                struct_ = get_resource_fragment(struct_type)

                if struct_ is not None:
                    if struct_ == "Section":
                        WikiSection(pack, begin, end)
                    elif struct_ == "Paragraph":
                        WikiParagraph(pack, begin, end)
                    elif struct_ == "Title":
                        WikiTitle(pack, begin, end)
                    else:
                        logging.warning("Unknown struct type: %s", struct_type)