import json | |
import torch | |
import os | |
# file_path = '/home/yiming/ContrastDebugger/EXP/codesearch_query/Model/Epoch_1/index.json' | |
# # 打开并读取 JSON 文件 | |
# with open(file_path, 'r') as file: | |
# json_data = json.load(file) | |
# testset_label = None | |
# for i in range(len(json_data)): | |
# if testset_label != None: | |
# testset_label = torch.cat((testset_label, torch.tensor([0])), 0) | |
# else: | |
# testset_label = torch.tensor([0]) | |
# torch.save(testset_label, "/home/yiming/ContrastDebugger/EXP/codesearch_query/Training_data/training_dataset_label.pth") | |
input_file = "/home/yiming/ContrastDebugger/EXP/codesearch/Model/label_list.json" | |
output_file = "/home/yiming/ContrastDebugger/EXP/codesearch/Model/new_label_list.json" # 替换为输出文件的路径 | |
# 读取输入文件 | |
with open(input_file, "r") as f: | |
data = json.load(f) | |
# 提取每个数据的前十个字符 | |
processed_data = [item[:30] for item in data] | |
# 保存到新的 JSON 文件 | |
with open(output_file, "w") as f: | |
json.dump(processed_data, f) |