-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomparison.py
More file actions
28 lines (25 loc) · 890 Bytes
/
Copy pathcomparison.py
File metadata and controls
28 lines (25 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
"""Token-level similarity HTML report (paper reproduction script)."""
from graphcodebert_interpretability import compare, highlight_html, set_seed
CODE_A = """
def process_numbers(numbers):
even_numbers = []
for num in numbers:
if is_even(num):
even_numbers.append(calculate_factorial(num))
return even_numbers
"""
CODE_B = """
def filter_numbers(nums):
odd_numbers = []
for val in nums:
if is_odd(val):
odd_numbers.append(compute_factorial(val))
return odd_numbers
"""
if __name__ == "__main__":
set_seed(42)
result = compare(CODE_A, CODE_B, name_a="Source Code 1", name_b="Source Code 2")
with open("code_similarity.html", "w", encoding="utf-8") as handle:
handle.write(highlight_html(result, similarity_threshold=0.8))
print(f"Final similarity score: {result.score:.2f}")