MCPcopy Create free account
hub / github.com/chatdoc-com/OCRFlux / load_html_tree

Method load_html_tree

eval/eval_table_to_html_olmocr.py:79–102  ·  view source on GitHub ↗

Converts HTML tree to the format required by apted

(self, node, parent=None)

Source from the content-addressed store, hash-verified

77 self.__tokens__ += list(node.tail)
78
79 def load_html_tree(self, node, parent=None):
80 ''' Converts HTML tree to the format required by apted
81 '''
82 global __tokens__
83 if node.tag == 'td':
84 if self.structure_only:
85 cell = []
86 else:
87 self.__tokens__ = []
88 self.tokenize(node)
89 cell = self.__tokens__[1:-1].copy()
90 new_node = TableTree(node.tag,
91 int(node.attrib.get('colspan', '1')),
92 int(node.attrib.get('rowspan', '1')),
93 cell, *deque())
94 else:
95 new_node = TableTree(node.tag, None, None, None, *deque())
96 if parent is not None:
97 parent.children.append(new_node)
98 if node.tag != 'td':
99 for n in node.getchildren():
100 self.load_html_tree(n, new_node)
101 if parent is None:
102 return new_node
103
104 def evaluate(self, pred, true):
105 ''' Computes TEDS score between the prediction and the ground truth of a

Callers 1

evaluateMethod · 0.95

Calls 2

tokenizeMethod · 0.95
TableTreeClass · 0.70

Tested by

no test coverage detected