|
|
import os |
|
|
import json |
|
|
|
|
|
def save_to_json(data, filename): |
|
|
with open(filename, 'w', encoding='utf-8') as f: |
|
|
json.dump(data, f, ensure_ascii=False, indent=4) |
|
|
print(f"save to {filename}, data len: {len(data)}") |
|
|
def load_json(file_path): |
|
|
with open(file_path, "r", encoding="utf-8") as f: |
|
|
data = json.load(f) |
|
|
print(f"load from {file_path}, data len: {len(data)}") |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
input_folder = "/share/project/sunshuang/deep_search/data_syn/data/mixed_data/splits" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classified_data = { |
|
|
"1-hop": [], |
|
|
"2-hop": [], |
|
|
"3-hop": [], |
|
|
"4-hop": [], |
|
|
"5-hop": [], |
|
|
"other": [] |
|
|
} |
|
|
|
|
|
new_data = [] |
|
|
|
|
|
for filename in sorted(os.listdir(input_folder)): |
|
|
|
|
|
if filename == "tagged_domain_keypoints": |
|
|
continue |
|
|
if "tagged" in filename and filename.endswith(".json"): |
|
|
file_path = os.path.join(input_folder, filename) |
|
|
print(filename) |
|
|
|
|
|
with open(file_path, "r", encoding="utf-8") as f: |
|
|
data = json.load(f) |
|
|
|
|
|
|
|
|
for item in data: |
|
|
|
|
|
tag_qwq = item.get("tag_qwq", "") |
|
|
reasoning_graph = tag_qwq.split("</think>")[-1].split("Graph:")[-1].split("Area:")[0].strip() |
|
|
|
|
|
|
|
|
hop = None |
|
|
if "1-hop" in reasoning_graph: |
|
|
hop = "1-hop" |
|
|
item["hop"] = 1 |
|
|
elif "2-hop" in reasoning_graph: |
|
|
hop = "2-hop" |
|
|
item["hop"] = 2 |
|
|
elif "3-hop" in reasoning_graph: |
|
|
hop = "3-hop" |
|
|
item["hop"] = 3 |
|
|
elif "4-hop" in reasoning_graph: |
|
|
hop = "4-hop" |
|
|
item["hop"] = 4 |
|
|
elif "5-hop" in reasoning_graph: |
|
|
hop = "5-hop" |
|
|
item["hop"] = 5 |
|
|
else: |
|
|
hop = "other" |
|
|
item["hop"] = -1 |
|
|
new_data.append(item) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data_1 = load_json("/share/project/sunshuang/deep_search/data_syn/data/mixed_data/splits/tagged_domain_keypoints/merged_tagged_domain_keypoints_keywords_count.json") |
|
|
|
|
|
assert len(new_data) == len(data_1) |
|
|
for item, item_1 in zip(new_data, data_1): |
|
|
assert item["idx"] == item_1["idx"], f"{item['idx']} {item_1['idx']}" |
|
|
assert item["Question"] == item_1["Question"] |
|
|
|
|
|
item_1["hop"] = item["hop"] |
|
|
|
|
|
save_to_json(data_1, "/share/project/sunshuang/deep_search/data_syn/data/mixed_data/splits/tagged_domain_keypoints/merged_tagged_domain_keypoints_keywords_count_hop.json") |