Converts HTML tree to the format required by apted
(self, node, parent=None)
| 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 |