Jaccard similarity on line-level tokens.
(diff1: PatchSet, diff2: PatchSet)
| 84 | |
| 85 | |
| 86 | def compute_code_sim_jaccard(diff1: PatchSet, diff2: PatchSet) -> float: |
| 87 | """Jaccard similarity on line-level tokens.""" |
| 88 | |
| 89 | def get_lines(patch): |
| 90 | return {str(f).splitlines() for f in patch} |
| 91 | |
| 92 | lines1 = get_lines(diff1) |
| 93 | lines2 = get_lines(diff2) |
| 94 | |
| 95 | if not lines1 and not lines2: |
| 96 | return 1.0 |
| 97 | if not lines1 or not lines2: |
| 98 | return 0.0 |
| 99 | |
| 100 | intersection = len(lines1 & lines2) |
| 101 | union = len(lines1 | lines2) |
| 102 | return intersection / union |
| 103 | |
| 104 | |
| 105 | def compute_code_similarity(diff1: PatchSet, diff2: PatchSet, similarity: str = "difflib") -> float: |
nothing calls this directly
no test coverage detected