MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / compute_code_sim_jaccard

Function compute_code_sim_jaccard

codeclash/analysis/code_evolve/main.py:86–102  ·  view source on GitHub ↗

Jaccard similarity on line-level tokens.

(diff1: PatchSet, diff2: PatchSet)

Source from the content-addressed store, hash-verified

84
85
86def 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
105def compute_code_similarity(diff1: PatchSet, diff2: PatchSet, similarity: str = "difflib") -> float:

Callers

nothing calls this directly

Calls 1

get_linesFunction · 0.85

Tested by

no test coverage detected