Calculates the distance between the two trees. @type tree1: list of Views @param tree1: Tree of Views @type tree2: list of Views @param tree2: Tree of Views @return: the distance
(tree1, tree2)
| 4525 | |
| 4526 | @staticmethod |
| 4527 | def distance(tree1, tree2): |
| 4528 | """ |
| 4529 | Calculates the distance between the two trees. |
| 4530 | |
| 4531 | @type tree1: list of Views |
| 4532 | @param tree1: Tree of Views |
| 4533 | @type tree2: list of Views |
| 4534 | @param tree2: Tree of Views |
| 4535 | @return: the distance |
| 4536 | """ |
| 4537 | ################################################################ |
| 4538 | # FIXME: this should copy the entire tree and then transform it # |
| 4539 | ################################################################ |
| 4540 | pickleableTree1 = ViewClient.__pickleable(tree1) |
| 4541 | pickleableTree2 = ViewClient.__pickleable(tree2) |
| 4542 | s1 = pickle.dumps(pickleableTree1) |
| 4543 | s2 = pickle.dumps(pickleableTree2) |
| 4544 | |
| 4545 | if DEBUG_DISTANCE: |
| 4546 | print("distance: calculating distance between", s1[:20], "and", s2[:20], file=sys.stderr) |
| 4547 | |
| 4548 | l1 = len(s1) |
| 4549 | l2 = len(s2) |
| 4550 | t = float(max(l1, l2)) |
| 4551 | |
| 4552 | if l1 == l2: |
| 4553 | if DEBUG_DISTANCE: |
| 4554 | print("distance: trees have same length, using Hamming distance", file=sys.stderr) |
| 4555 | return ViewClient.__hammingDistance(s1, s2) / t |
| 4556 | else: |
| 4557 | if DEBUG_DISTANCE: |
| 4558 | print("distance: trees have different length, using Levenshtein distance", file=sys.stderr) |
| 4559 | return levenshtein_distance(s1, s2) / t |
| 4560 | |
| 4561 | @staticmethod |
| 4562 | def __hammingDistance(s1, s2): |
no test coverage detected