| 31 | |
| 32 | |
| 33 | class CustomConfig(Config): |
| 34 | @staticmethod |
| 35 | def maximum(*sequences): |
| 36 | """Get maximum possible value |
| 37 | """ |
| 38 | return max(map(len, sequences)) |
| 39 | |
| 40 | def normalized_distance(self, *sequences): |
| 41 | """Get distance from 0 to 1 |
| 42 | """ |
| 43 | return float(distance.levenshtein(*sequences)) / self.maximum(*sequences) |
| 44 | |
| 45 | def rename(self, node1, node2): |
| 46 | """Compares attributes of trees""" |
| 47 | if (node1.tag != node2.tag) or (node1.colspan != node2.colspan) or (node1.rowspan != node2.rowspan): |
| 48 | return 1. |
| 49 | if node1.tag == 'td': |
| 50 | if node1.content or node2.content: |
| 51 | return self.normalized_distance(node1.content, node2.content) |
| 52 | return 0. |
| 53 | |
| 54 | |
| 55 | class TEDS(object): |