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