def add_text_block(self, tb: TextBlock) -> None: for font_size in self.font_size_stack[::-1]: if font_size is not None: tb.add_label(f"font-{font_size}") break for label_stack in self.label_stacks: for labels in label_stack: labels.add_to(tb) self.text_blocks.append(tb)
def make_doc(words_arr, num_anchor_words_arr=None, is_content_arr=None, label_arr=None): text_blocks = [] for idx, words in enumerate(words_arr): if isinstance(words, int): num_words = words text = ' '.join(default_words[:num_words]) else: text = words num_words = text.count(' ') try: num_anchor_words = num_anchor_words_arr[idx] except (TypeError, IndexError): num_anchor_words = 0 block = TextBlock(text, set(), num_words, num_anchor_words, 0, 0, idx) try: block.is_content = is_content_arr[idx] except (TypeError, IndexError): pass try: label = label_arr[idx] if label is None: pass elif isinstance(label, list): for l in label: block.add_label(l) else: block.add_label(label) except (TypeError, IndexError): pass text_blocks.append(block) return TextDocument(text_blocks)