Team Ai
Apppublic

JetBrains-Research/commit-message-editing-visualization

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
generate_annotated_diffs.py39 linesDownload Raw Back to root
1import diff_match_patch as dmp_module2from tqdm import tqdm3 4from api_wrappers import hf_data_loader5 6 7def get_annotated_diff(start_text, end_text):8    dmp = dmp_module.diff_match_patch()9    dmp_mapping = {-1: "-", 0: None, 1: "+"}10 11    diff = dmp.diff_main(start_text, end_text)12    dmp.diff_cleanupSemantic(diff)13 14    result = [[w, dmp_mapping[t]] for t, w in diff]15 16    return result17 18 19def annotated_diff_for_row(row):20    if "commit_msg_start" in row:21        start = row["commit_msg_start"]22    else:23        start = row["G_text"]24    if "commit_msg_end" in row:25        end = row["commit_msg_end"]26    else:27        end = row["E_text"]28    return get_annotated_diff(start, end)29 30 31def data_with_annotated_diffs():32    tqdm.pandas()33 34    df = hf_data_loader.load_synthetic_as_pandas()35    df = df.loc[df.is_related].copy()36    annotated = df.progress_apply(annotated_diff_for_row, axis=1)37    df["annotated_diff"] = annotated38    return df39