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

Method load_html_tree

eval/eval_table_to_html.py:78–101  ·  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

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