to-164
This commit is contained in:
Executable
+103
@@ -0,0 +1,103 @@
|
||||
import os, orjson, traceback
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
|
||||
|
||||
def load_orjson(path: str | Path):
|
||||
path = Path(path)
|
||||
with path.open("rb") as f: # باید باینری باز بشه برای orjson
|
||||
return orjson.loads(f.read())
|
||||
|
||||
|
||||
def save_orjson(path, data):
|
||||
with open(path, "wb") as f:
|
||||
f.write(
|
||||
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
|
||||
)
|
||||
|
||||
|
||||
def post_process_1():
|
||||
in_data = load_orjson(
|
||||
"/home1/ava3/init_mahdi/project/aiDataParser/task/translate_en_per/output/final_data_word-type-v1-gemma-3-27b-med.json"
|
||||
)
|
||||
f_data = []
|
||||
for item in in_data:
|
||||
|
||||
item["result"]
|
||||
_type = item["input"]["type"]
|
||||
if _type == "conflict_detection":
|
||||
_id = item["id"].split("--")[0]
|
||||
else:
|
||||
i1, i2, i3 = item["id"].split("-")
|
||||
_id = i1 + "-" + i2
|
||||
f_data.append(
|
||||
{
|
||||
"id": _id,
|
||||
"type": _type,
|
||||
"result": item["result"],
|
||||
}
|
||||
)
|
||||
|
||||
print(f"f_data {len(f_data)}")
|
||||
save_orjson(
|
||||
data=f_data,
|
||||
path="/home1/ava3/init_mahdi/project/aiDataParser/task/translate_en_per/finall_data.json",
|
||||
)
|
||||
|
||||
|
||||
def post_process_2(in_path, final_validity_path, o_path):
|
||||
in_data = load_orjson(in_path)
|
||||
# t1 = [i for i in in_data if "qs553886_v2-qs1597291_v2" == i["id"]][0]
|
||||
finall_data_confilict = load_orjson(final_validity_path)
|
||||
f_data = []
|
||||
map_conflict_detection = {}
|
||||
map_conflict_type_detection = {}
|
||||
for item in in_data:
|
||||
result = item["llm_output"]
|
||||
_type = item["type"]
|
||||
|
||||
if _type == "conflict_detection":
|
||||
_id = item["id"].split("--")[0]
|
||||
map_conflict_detection[_id] = result
|
||||
|
||||
else:
|
||||
# i1, i2, i3 = item["id"].split("-")[:-1]
|
||||
# _id = i1 + "-" + i2
|
||||
_id = item["id"].rsplit("-", 1)[0]
|
||||
# print(f"result {result}")
|
||||
map_conflict_type_detection[_id] = result
|
||||
|
||||
for i in finall_data_confilict:
|
||||
# print(f"{i}")
|
||||
item_explanation_of_conflict = map_conflict_detection.get(i["id"])
|
||||
if item_explanation_of_conflict:
|
||||
i["conflict_detection"]["explanation_of_conflict"] = item_explanation_of_conflict
|
||||
item_explanation_of_type = map_conflict_type_detection.get(i["id"])
|
||||
if item_explanation_of_type:
|
||||
i["conflict_type_detection"][
|
||||
"explanation_of_type"
|
||||
] = item_explanation_of_type
|
||||
# print(
|
||||
# f'explanation_of_conflict : {i["conflict_type_detection"]["explanation_of_type"]}'
|
||||
# )
|
||||
# break
|
||||
|
||||
f_data.append(i)
|
||||
|
||||
print(f"f_data {len(f_data)}")
|
||||
save_orjson(
|
||||
data=f_data,
|
||||
path=o_path,
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
post_process_2(
|
||||
in_path="/home1/ava3/init_mahdi/project/aiDataParser/task/translate_en_per/output_data_6152_full/final_data_word-type-v1-gemma-3-27b-med.json",
|
||||
final_validity_path="/home1/ava3/init_mahdi/project/rule_extractor/im_based/data/sequential/final_validity/output_6152.json",
|
||||
o_path="/home1/ava3/init_mahdi/project/rule_extractor/im_based/data/sequential/v2_6152_translated.json",
|
||||
)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
|
||||
# python -m aiDataParser.task.translate_en_per.post_proces
|
||||
Reference in New Issue
Block a user