v3
This commit is contained in:
@@ -42,44 +42,55 @@ def get_evaluation_data(data):
|
||||
result.append("رد تشخیص نوع تعارض")
|
||||
return result
|
||||
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
|
||||
|
||||
def import_conflict_to_elastic(input_path, out_put_index_name, file_jump_ids):
|
||||
|
||||
|
||||
jump_ids = []
|
||||
if os.path.exists(file_jump_ids):
|
||||
with open(file_jump_ids, "r") as f:
|
||||
jump_ids = f.readlines()
|
||||
|
||||
with open(file_jump_ids, "r", encoding="utf-8") as f:
|
||||
jump_ids = [line.strip() for line in f if line.strip()]
|
||||
|
||||
list_files = []
|
||||
if os.path.isdir(input_path):
|
||||
list_files = [os.path.join(input_path, f) for f in os.listdir(input_path) if os.path.isfile(os.path.join(input_path, f))]
|
||||
list_files = [
|
||||
os.path.join(input_path, f)
|
||||
for f in os.listdir(input_path)
|
||||
if os.path.isfile(os.path.join(input_path, f))
|
||||
]
|
||||
elif os.path.isfile(input_path):
|
||||
list_files.append(input_path)
|
||||
|
||||
|
||||
file_count = 0
|
||||
total_import = 0
|
||||
for file in list_files :
|
||||
|
||||
for file in list_files:
|
||||
|
||||
data_all = []
|
||||
try:
|
||||
data_all = DataHelper.load_orjson(file)
|
||||
if isinstance(data_all[0], list) :
|
||||
if isinstance(data_all[0], list):
|
||||
data_all = data_all[0]
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print("********** error read data file json " , file , str(e))
|
||||
print("********** error read data file json ", file, str(e))
|
||||
continue
|
||||
|
||||
file_count +=1
|
||||
print("@"*5,"file start... file_count / count ", str(file_count), '/', len(data_all), file)
|
||||
|
||||
|
||||
file_count += 1
|
||||
print(
|
||||
"@" * 5,
|
||||
"file start... file_count / count ",
|
||||
str(file_count),
|
||||
"/",
|
||||
len(list_files),
|
||||
file,
|
||||
)
|
||||
|
||||
if file in jump_ids:
|
||||
continue
|
||||
|
||||
bulk_data = []
|
||||
failed_data = []
|
||||
total_count = 0
|
||||
@@ -87,82 +98,95 @@ def import_conflict_to_elastic(input_path, out_put_index_name, file_jump_ids):
|
||||
for item in data_all:
|
||||
|
||||
_id = item["id"]
|
||||
|
||||
if _id in jump_ids :
|
||||
|
||||
if _id in jump_ids:
|
||||
continue
|
||||
|
||||
|
||||
jump_ids.append(_id)
|
||||
|
||||
|
||||
previous_info = item["previous_info"]
|
||||
next_info = item["next_info"]
|
||||
version_key = item["version_key"]
|
||||
subject_unity = item["subject_unity"]
|
||||
|
||||
if subject_unity["main_type"] == "no" :
|
||||
|
||||
if subject_unity["main_type"] == "no":
|
||||
continue
|
||||
|
||||
|
||||
qanon_title1 = previous_info["qanon_title"]
|
||||
qanon_id1 = previous_info["qanon_id"]
|
||||
|
||||
|
||||
qanon_title2 = next_info["qanon_title"]
|
||||
qanon_id2 = next_info["qanon_id"]
|
||||
|
||||
|
||||
title_type1 = getTitleType(qanon_title1)
|
||||
title_type2 = getTitleType(qanon_title2)
|
||||
|
||||
previous_info["title_type"] = title_type1
|
||||
next_info["title_type"] = title_type2
|
||||
|
||||
|
||||
|
||||
previous_info["title_type"] = title_type1
|
||||
next_info["title_type"] = title_type2
|
||||
|
||||
conflict_detection = item["conflict_detection"]
|
||||
# conflict_type_detection = item["conflict_type_detection"]
|
||||
conflict_relation_identification = item["conflict_relation_type"]
|
||||
conflict_evaluation = item["conflict_evaluation"]
|
||||
conflict_final = item["conflict_final"]
|
||||
|
||||
|
||||
subject_unity["ref_key"] = "gemma4"
|
||||
|
||||
|
||||
es_data = {
|
||||
"id": _id,
|
||||
"version_key": version_key,
|
||||
"previous_info": previous_info,
|
||||
"next_info": next_info,
|
||||
"subject_unitys": [subject_unity]
|
||||
"subject_unitys": [subject_unity],
|
||||
}
|
||||
if conflict_detection :
|
||||
if conflict_detection:
|
||||
conflict_detection["ref_key"] = "openyourmind"
|
||||
es_data["conflict_detections"] = [conflict_detection]
|
||||
|
||||
if conflict_relation_identification :
|
||||
if conflict_relation_identification:
|
||||
conflict_relation_identification["ref_key"] = "openyourmind"
|
||||
es_data["conflict_relation_identifications"] = [conflict_relation_identification]
|
||||
es_data["conflict_relation_identifications"] = [
|
||||
conflict_relation_identification
|
||||
]
|
||||
|
||||
if conflict_evaluation :
|
||||
if conflict_evaluation:
|
||||
conflict_evaluation["ref_key"] = "qwen3-6"
|
||||
es_data["conflict_evaluations"] = [conflict_evaluation]
|
||||
|
||||
if conflict_final :
|
||||
if conflict_final:
|
||||
es_data["conflict_finals"] = [conflict_final]
|
||||
|
||||
bulk_data.append({"_id": _id, "_source": es_data})
|
||||
|
||||
|
||||
if len(bulk_data) > 200:
|
||||
total_count += len(bulk_data)
|
||||
print("=" * 10, "to_elastic , total=" + str(total_count) + " -- " + str(total_import))
|
||||
print(
|
||||
"=" * 10,
|
||||
"to_elastic , total="
|
||||
+ str(total_count)
|
||||
+ " -- "
|
||||
+ str(total_import),
|
||||
)
|
||||
elastic.importBulkList(bulk_data, out_put_index_name)
|
||||
bulk_data = []
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print("=" * 10, "to_elastic , total=" + str(total_count) + " -- " + str(total_import))
|
||||
print(
|
||||
"=" * 10,
|
||||
"to_elastic , total="
|
||||
+ str(total_count)
|
||||
+ " -- "
|
||||
+ str(total_import),
|
||||
)
|
||||
elastic.importBulkList(bulk_data, out_put_index_name)
|
||||
bulk_data = []
|
||||
total_import += total_count
|
||||
|
||||
with open(file_jump_ids, "w") as f:
|
||||
f.write("\n".join(jump_ids))
|
||||
|
||||
|
||||
total_import += total_count
|
||||
jump_ids.append(file)
|
||||
|
||||
with open(file_jump_ids, "w") as f:
|
||||
f.write("\n".join(jump_ids))
|
||||
|
||||
|
||||
def append_conflict_to_elastic(
|
||||
@@ -178,25 +202,29 @@ def append_conflict_to_elastic(
|
||||
"conflict_final",
|
||||
"llm_output",
|
||||
],
|
||||
ref_key_advance = {},
|
||||
import_if_not_found = False
|
||||
ref_key_advance={},
|
||||
import_if_not_found=False,
|
||||
):
|
||||
list_files = []
|
||||
if os.path.isdir(input_path):
|
||||
list_files = [os.path.join(input_path, f) for f in os.listdir(input_path) if os.path.isfile(os.path.join(input_path, f))]
|
||||
list_files = [
|
||||
os.path.join(input_path, f)
|
||||
for f in os.listdir(input_path)
|
||||
if os.path.isfile(os.path.join(input_path, f))
|
||||
]
|
||||
elif os.path.isfile(input_path):
|
||||
list_files.append(input_path)
|
||||
|
||||
for file in list_files :
|
||||
|
||||
for file in list_files:
|
||||
|
||||
data_all = []
|
||||
try:
|
||||
data_all = DataHelper.load_orjson(file)
|
||||
except Exception as e:
|
||||
print("********** error read data file json " , file , str(e))
|
||||
print("********** error read data file json ", file, str(e))
|
||||
continue
|
||||
|
||||
print("@"*5,"file start...", file)
|
||||
|
||||
print("@" * 5, "file start...", file)
|
||||
list_notfound = []
|
||||
bulk_data = []
|
||||
bulk_data_import = []
|
||||
@@ -210,19 +238,19 @@ def append_conflict_to_elastic(
|
||||
# if _id == "qs2489164_v2-9.qs2365626_v2-7":
|
||||
# print("qs2489164_v2-9.qs2365626_v2-7")
|
||||
|
||||
import_state = False
|
||||
import_state = False
|
||||
_source = {}
|
||||
res = None
|
||||
try:
|
||||
res = elastic.get_document(out_put_index_name, _id)
|
||||
except:
|
||||
list_notfound.append(_id)
|
||||
if not import_if_not_found :
|
||||
if not import_if_not_found:
|
||||
continue
|
||||
|
||||
|
||||
import_state = True
|
||||
version_key = item["version_key"]
|
||||
|
||||
|
||||
previous_info = item["previous_info"]
|
||||
qanon_title1 = previous_info["qanon_title"]
|
||||
qanon_id1 = previous_info["qanon_id"]
|
||||
@@ -235,16 +263,16 @@ def append_conflict_to_elastic(
|
||||
title_type2 = getTitleType(qanon_title2)
|
||||
conflict_tags = []
|
||||
if qanon_id1 == qanon_id2:
|
||||
conflict_tags.append("هم قانون")
|
||||
|
||||
previous_info["title_type"] = title_type1
|
||||
next_info["title_type"] = title_type2
|
||||
|
||||
conflict_tags.append("هم قانون")
|
||||
|
||||
previous_info["title_type"] = title_type1
|
||||
next_info["title_type"] = title_type2
|
||||
|
||||
_source = {
|
||||
"previous_info": previous_info,
|
||||
"next_info": next_info,
|
||||
"conflict_tags": conflict_tags,
|
||||
"version_key":version_key,
|
||||
"version_key": version_key,
|
||||
"subject_unitys": [],
|
||||
"conflict_detections": [],
|
||||
"conflict_type_detections": [],
|
||||
@@ -252,19 +280,40 @@ def append_conflict_to_elastic(
|
||||
"conflict_evaluations": [],
|
||||
"conflict_finals": [],
|
||||
}
|
||||
res = {
|
||||
"_id": id,
|
||||
"_source": _source
|
||||
}
|
||||
res = {"_id": id, "_source": _source}
|
||||
|
||||
# print("id start...", _id)
|
||||
|
||||
subject_unitys = res["_source"]["subject_unitys"] if "subject_unitys" in res["_source"] else []
|
||||
conflict_detections = res["_source"]["conflict_detections"] if "conflict_detections" in res["_source"] else []
|
||||
conflict_type_detections = res["_source"]["conflict_type_detections"] if "conflict_type_detections" in res["_source"] else []
|
||||
conflict_relation_identifications = res["_source"]["conflict_relation_identifications"] if "conflict_relation_identifications" in res["_source"] else []
|
||||
conflict_evaluations = res["_source"]["conflict_evaluations"] if "conflict_evaluations" in res["_source"] else []
|
||||
conflict_finals = res["_source"]["conflict_finals"] if "conflict_finals" in res["_source"] else []
|
||||
subject_unitys = (
|
||||
res["_source"]["subject_unitys"]
|
||||
if "subject_unitys" in res["_source"]
|
||||
else []
|
||||
)
|
||||
conflict_detections = (
|
||||
res["_source"]["conflict_detections"]
|
||||
if "conflict_detections" in res["_source"]
|
||||
else []
|
||||
)
|
||||
conflict_type_detections = (
|
||||
res["_source"]["conflict_type_detections"]
|
||||
if "conflict_type_detections" in res["_source"]
|
||||
else []
|
||||
)
|
||||
conflict_relation_identifications = (
|
||||
res["_source"]["conflict_relation_identifications"]
|
||||
if "conflict_relation_identifications" in res["_source"]
|
||||
else []
|
||||
)
|
||||
conflict_evaluations = (
|
||||
res["_source"]["conflict_evaluations"]
|
||||
if "conflict_evaluations" in res["_source"]
|
||||
else []
|
||||
)
|
||||
conflict_finals = (
|
||||
res["_source"]["conflict_finals"]
|
||||
if "conflict_finals" in res["_source"]
|
||||
else []
|
||||
)
|
||||
|
||||
subject_unity = {}
|
||||
conflict_detection = {}
|
||||
@@ -282,7 +331,11 @@ def append_conflict_to_elastic(
|
||||
main_type = ""
|
||||
description = ""
|
||||
reason = ""
|
||||
ref_key_adv = ref_key_advance["subject_unity"] if "subject_unity" in ref_key_advance else ref_key
|
||||
ref_key_adv = (
|
||||
ref_key_advance["subject_unity"]
|
||||
if "subject_unity" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
ss = item["subject_unity"]
|
||||
if "main_type" in ss:
|
||||
@@ -321,8 +374,11 @@ def append_conflict_to_elastic(
|
||||
and "conflict_detection" in fields
|
||||
):
|
||||
description = ""
|
||||
ref_key_adv = ref_key_advance["conflict_detection"] if "conflict_detection" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["conflict_detection"]
|
||||
if "conflict_detection" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
ss = item["conflict_detection"]
|
||||
if "has_conflict" in ss:
|
||||
@@ -339,7 +395,9 @@ def append_conflict_to_elastic(
|
||||
"description": description,
|
||||
}
|
||||
|
||||
conflict_detections = clear_array_object_by(conflict_detections, ref_key_adv)
|
||||
conflict_detections = clear_array_object_by(
|
||||
conflict_detections, ref_key_adv
|
||||
)
|
||||
|
||||
conflict_detections.append(cd)
|
||||
data["conflict_detections"] = conflict_detections
|
||||
@@ -351,8 +409,11 @@ def append_conflict_to_elastic(
|
||||
):
|
||||
main_type = ""
|
||||
description = ""
|
||||
ref_key_adv = ref_key_advance["conflict_type_detection"] if "conflict_type_detection" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["conflict_type_detection"]
|
||||
if "conflict_type_detection" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
ss = item["conflict_type_detection"]
|
||||
if "main_type" in ss:
|
||||
@@ -370,7 +431,9 @@ def append_conflict_to_elastic(
|
||||
"description": description,
|
||||
}
|
||||
|
||||
conflict_type_detections = clear_array_object_by(conflict_type_detections, ref_key_adv)
|
||||
conflict_type_detections = clear_array_object_by(
|
||||
conflict_type_detections, ref_key_adv
|
||||
)
|
||||
|
||||
conflict_type_detections.append(cd)
|
||||
data["conflict_type_detections"] = conflict_type_detections
|
||||
@@ -382,8 +445,11 @@ def append_conflict_to_elastic(
|
||||
):
|
||||
main_type = ""
|
||||
description = ""
|
||||
ref_key_adv = ref_key_advance["relation_identification"] if "relation_identification" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["relation_identification"]
|
||||
if "relation_identification" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
ss = item["relation_identification"]
|
||||
if "main_type" in ss:
|
||||
@@ -402,22 +468,27 @@ def append_conflict_to_elastic(
|
||||
"description": description,
|
||||
}
|
||||
|
||||
conflict_relation_identifications = clear_array_object_by(conflict_relation_identifications, ref_key_adv)
|
||||
conflict_relation_identifications = clear_array_object_by(
|
||||
conflict_relation_identifications, ref_key_adv
|
||||
)
|
||||
conflict_relation_identifications.append(cd)
|
||||
data["conflict_relation_identifications"] = (
|
||||
conflict_relation_identifications
|
||||
)
|
||||
|
||||
|
||||
# #--- در خروجی تغییر اسم داده شد conflict_relation_type = conflict_relation_identification
|
||||
if (
|
||||
if (
|
||||
"conflict_relation_type" in item
|
||||
and item["conflict_relation_type"]
|
||||
and "conflict_relation_type" in fields
|
||||
):
|
||||
main_type = ""
|
||||
description = ""
|
||||
ref_key_adv = ref_key_advance["conflict_relation_type"] if "conflict_relation_type" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["conflict_relation_type"]
|
||||
if "conflict_relation_type" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
ss = item["conflict_relation_type"]
|
||||
if "main_type" in ss:
|
||||
@@ -436,7 +507,9 @@ def append_conflict_to_elastic(
|
||||
"description": description,
|
||||
}
|
||||
|
||||
conflict_relation_identifications = clear_array_object_by(conflict_relation_identifications, ref_key_adv)
|
||||
conflict_relation_identifications = clear_array_object_by(
|
||||
conflict_relation_identifications, ref_key_adv
|
||||
)
|
||||
conflict_relation_identifications.append(cd)
|
||||
data["conflict_relation_identifications"] = (
|
||||
conflict_relation_identifications
|
||||
@@ -447,19 +520,28 @@ def append_conflict_to_elastic(
|
||||
and item["conflict_evaluation"]
|
||||
and "conflict_evaluation" in fields
|
||||
):
|
||||
ref_key_adv = ref_key_advance["conflict_evaluation"] if "conflict_evaluation" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["conflict_evaluation"]
|
||||
if "conflict_evaluation" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
item["conflict_evaluation"]["ref_key"] = ref_key_adv
|
||||
|
||||
conflict_evaluations = clear_array_object_by(conflict_evaluations, ref_key_adv)
|
||||
conflict_evaluations = clear_array_object_by(
|
||||
conflict_evaluations, ref_key_adv
|
||||
)
|
||||
conflict_evaluations.append(item["conflict_evaluation"])
|
||||
data["conflict_evaluations"] = conflict_evaluations
|
||||
elif "llm_output" in item and item["llm_output"] and "llm_output" in fields:
|
||||
main_type = ""
|
||||
description = ""
|
||||
validates = []
|
||||
ref_key_adv = ref_key_advance["conflict_evaluation"] if "conflict_evaluation" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["conflict_evaluation"]
|
||||
if "conflict_evaluation" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
ss = item["llm_output"]
|
||||
if "main_type" in ss:
|
||||
@@ -484,7 +566,9 @@ def append_conflict_to_elastic(
|
||||
"description": description,
|
||||
}
|
||||
|
||||
conflict_evaluations = clear_array_object_by(conflict_evaluations, ref_key_adv)
|
||||
conflict_evaluations = clear_array_object_by(
|
||||
conflict_evaluations, ref_key_adv
|
||||
)
|
||||
conflict_evaluations.append(cd)
|
||||
data["conflict_evaluations"] = conflict_evaluations
|
||||
|
||||
@@ -493,21 +577,25 @@ def append_conflict_to_elastic(
|
||||
and item["conflict_final"]
|
||||
and "conflict_final" in fields
|
||||
):
|
||||
ref_key_adv = ref_key_advance["conflict_final"] if "conflict_final" in ref_key_advance else ref_key
|
||||
|
||||
ref_key_adv = (
|
||||
ref_key_advance["conflict_final"]
|
||||
if "conflict_final" in ref_key_advance
|
||||
else ref_key
|
||||
)
|
||||
|
||||
item["conflict_final"]["ref_key"] = ref_key_adv
|
||||
|
||||
conflict_finals = clear_array_object_by(conflict_finals, ref_key_adv)
|
||||
conflict_finals.append(item["conflict_final"])
|
||||
data["conflict_finals"] = conflict_finals
|
||||
|
||||
if import_state :
|
||||
|
||||
if import_state:
|
||||
data["id"] = _id
|
||||
data["previous_info"] = _source["previous_info"]
|
||||
data["next_info"] = _source["next_info"]
|
||||
data["conflict_tags"] = _source["conflict_tags"]
|
||||
data["version_key"] = _source["version_key"]
|
||||
bulk_data_import.append({"_id": _id, "_source": data})
|
||||
bulk_data_import.append({"_id": _id, "_source": data})
|
||||
elif data:
|
||||
bulk_data.append({"_id": _id, "_source": data})
|
||||
|
||||
@@ -516,7 +604,7 @@ def append_conflict_to_elastic(
|
||||
print("=!" * 10, " import to_elastic , total=" + str(total_count))
|
||||
elastic.importBulkList(bulk_data_import, out_put_index_name)
|
||||
bulk_data_import = []
|
||||
|
||||
|
||||
if len(bulk_data) > 200:
|
||||
total_count += len(bulk_data)
|
||||
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||
@@ -529,21 +617,20 @@ def append_conflict_to_elastic(
|
||||
print("=!" * 10, " import to_elastic , total=" + str(total_count))
|
||||
elastic.importBulkList(bulk_data_import, out_put_index_name)
|
||||
bulk_data_import = []
|
||||
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||
elastic.updateBulkList(bulk_data, out_put_index_name)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
|
||||
|
||||
def clear_array_object_by(array, ref_key):
|
||||
array = [c for c in array if c["ref_key"] != ref_key]
|
||||
|
||||
|
||||
# تغییر کلید و حذف اضافات قبلی
|
||||
# array = [c for c in array if (c["ref_key"] != "oss120-p2-v2" and c["ref_key"] != "gemma4-p2-v2" )]
|
||||
|
||||
|
||||
return array
|
||||
|
||||
|
||||
@@ -572,7 +659,14 @@ def get_evaluation_data(data):
|
||||
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
def genrate_excel_data(elastic, file_ouput, index_name_o="mj_qa_conflict", key="subject_unitys", key_value="qwen3-6", base_url="http://192.168.23.160"):
|
||||
def genrate_excel_data(
|
||||
elastic,
|
||||
file_ouput,
|
||||
index_name_o="mj_qa_conflict",
|
||||
key="subject_unitys",
|
||||
key_value="qwen3-6",
|
||||
base_url="http://192.168.23.160",
|
||||
):
|
||||
|
||||
body = {
|
||||
"query": {
|
||||
@@ -581,19 +675,15 @@ def genrate_excel_data(elastic, file_ouput, index_name_o="mj_qa_conflict", key="
|
||||
{
|
||||
"nested": {
|
||||
"path": key,
|
||||
"query": {
|
||||
"term": {key+".ref_key": {"value": key_value}}
|
||||
}
|
||||
"query": {"term": {key + ".ref_key": {"value": key_value}}},
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"sort":[
|
||||
{"previous_info.ts_date": "desc"}
|
||||
]
|
||||
"sort": [{"previous_info.ts_date": "desc"}],
|
||||
}
|
||||
|
||||
|
||||
print(body)
|
||||
columns = [
|
||||
"ردیف",
|
||||
@@ -650,7 +740,7 @@ def genrate_excel_data(elastic, file_ouput, index_name_o="mj_qa_conflict", key="
|
||||
# ["Mike", 28, "Toronto"],
|
||||
# ["Emma", 35, "Sydney"],
|
||||
# ]
|
||||
|
||||
|
||||
data = list(list_)
|
||||
total = len(data)
|
||||
count = 0
|
||||
@@ -666,142 +756,172 @@ def genrate_excel_data(elastic, file_ouput, index_name_o="mj_qa_conflict", key="
|
||||
|
||||
next_info = entry.get("next_info", {})
|
||||
previous_info = entry.get("previous_info", {})
|
||||
|
||||
|
||||
subject_unitys = entry.get("subject_unitys", {})
|
||||
conflict_detections = entry.get("conflict_detections", {})
|
||||
conflict_type_detections = entry.get("conflict_type_detections", {})
|
||||
conflict_relation_identifications = entry.get("conflict_relation_identifications", {})
|
||||
conflict_relation_identifications = entry.get(
|
||||
"conflict_relation_identifications", {}
|
||||
)
|
||||
conflict_evaluations = entry.get("conflict_evaluations", {})
|
||||
conflict_finals = entry.get("conflict_finals", {})
|
||||
|
||||
|
||||
link = f'=HYPERLINK("{base_url}/refine/conflict/{_id}", "لینک")'
|
||||
|
||||
link = f'=HYPERLINK("{base_url}/refine/conflict/{_id}", "لینک")'
|
||||
|
||||
subject_rate = 0
|
||||
subject_oss120 = ""
|
||||
subject_qwen3_6 = ""
|
||||
subject_gemma4_p2= ""
|
||||
subject_oss120_p2= ""
|
||||
subject_qwen3_6p2= ""
|
||||
subject_openyourmind= ""
|
||||
|
||||
for su in subject_unitys :
|
||||
if su["ref_key"] == "oss120" :
|
||||
subject_gemma4_p2 = ""
|
||||
subject_oss120_p2 = ""
|
||||
subject_qwen3_6p2 = ""
|
||||
subject_openyourmind = ""
|
||||
|
||||
for su in subject_unitys:
|
||||
if su["ref_key"] == "oss120":
|
||||
subject_oss120 = su["main_type"]
|
||||
# subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6" :
|
||||
if su["ref_key"] == "qwen3-6":
|
||||
subject_qwen3_6 = su["main_type"]
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "gemma4-p2" :
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "gemma4-p2":
|
||||
subject_gemma4_p2 = su["main_type"]
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "oss120-p2" :
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "oss120-p2":
|
||||
subject_oss120_p2 = su["main_type"]
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6-p2" :
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6-p2":
|
||||
subject_qwen3_6p2 = su["main_type"]
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "openyourmind" :
|
||||
subject_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "openyourmind":
|
||||
subject_openyourmind = su["main_type"]
|
||||
subject_rate += getRate(su["main_type"])
|
||||
subject_rate += getRate(su["main_type"])
|
||||
|
||||
conflict_rate = 0
|
||||
conflict_oss120 = ""
|
||||
conflict_qwen3_6 = ""
|
||||
conflict_gemma4_p2= ""
|
||||
conflict_oss120_p2= ""
|
||||
conflict_qwen3_6p2= ""
|
||||
conflict_openyourmind= ""
|
||||
|
||||
for su in conflict_detections :
|
||||
if su["ref_key"] == "oss120" :
|
||||
conflict_gemma4_p2 = ""
|
||||
conflict_oss120_p2 = ""
|
||||
conflict_qwen3_6p2 = ""
|
||||
conflict_openyourmind = ""
|
||||
|
||||
for su in conflict_detections:
|
||||
if su["ref_key"] == "oss120":
|
||||
conflict_oss120 = str(su["has_conflict"])
|
||||
# conflict_rate += getRate(su["has_conflict"])
|
||||
if su["ref_key"] == "qwen3-6" :
|
||||
if su["ref_key"] == "qwen3-6":
|
||||
conflict_qwen3_6 = str(su["has_conflict"])
|
||||
conflict_rate += getRate(su["has_conflict"])
|
||||
if su["ref_key"] == "gemma4-p2" :
|
||||
if su["ref_key"] == "gemma4-p2":
|
||||
conflict_gemma4_p2 = str(su["has_conflict"])
|
||||
conflict_rate += getRate(su["has_conflict"])
|
||||
if su["ref_key"] == "oss120-p2" :
|
||||
if su["ref_key"] == "oss120-p2":
|
||||
conflict_oss120_p2 = str(su["has_conflict"])
|
||||
conflict_rate += getRate(su["has_conflict"])
|
||||
if su["ref_key"] == "qwen3-6-p2" :
|
||||
if su["ref_key"] == "qwen3-6-p2":
|
||||
conflict_qwen3_6p2 = str(su["has_conflict"])
|
||||
conflict_rate += getRate(su["has_conflict"])
|
||||
if su["ref_key"] == "openyourmind" :
|
||||
if su["ref_key"] == "openyourmind":
|
||||
conflict_openyourmind = str(su["has_conflict"])
|
||||
conflict_rate += getRate(su["has_conflict"])
|
||||
|
||||
|
||||
relation_rate = 0
|
||||
relation_oss120 = ""
|
||||
relation_qwen3_6 = ""
|
||||
relation_gemma4_p2= ""
|
||||
relation_oss120_p2= ""
|
||||
relation_qwen3_6p2= ""
|
||||
relation_openyourmind= ""
|
||||
|
||||
for su in conflict_relation_identifications :
|
||||
if su["ref_key"] == "oss120" :
|
||||
relation_gemma4_p2 = ""
|
||||
relation_oss120_p2 = ""
|
||||
relation_qwen3_6p2 = ""
|
||||
relation_openyourmind = ""
|
||||
|
||||
for su in conflict_relation_identifications:
|
||||
if su["ref_key"] == "oss120":
|
||||
relation_oss120 = su["main_type"]
|
||||
# relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6" :
|
||||
if su["ref_key"] == "qwen3-6":
|
||||
relation_qwen3_6 = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "gemma4-p2" :
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "gemma4-p2":
|
||||
relation_gemma4_p2 = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "oss120-p2" :
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "oss120-p2":
|
||||
relation_oss120_p2 = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6-p2" :
|
||||
relation_qwen3_6p2 = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "openyourmind" :
|
||||
relation_openyourmind = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
|
||||
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6-p2":
|
||||
relation_qwen3_6p2 = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "openyourmind":
|
||||
relation_openyourmind = su["main_type"]
|
||||
relation_rate += getRate(su["main_type"])
|
||||
|
||||
evalution_rate = 0
|
||||
evalution_oss120 = ""
|
||||
evalution_qwen3_6 = ""
|
||||
evalution_gemma4_p2= ""
|
||||
evalution_oss120_p2= ""
|
||||
evalution_qwen3_6p2= ""
|
||||
evalution_openyourmind= ""
|
||||
|
||||
for su in conflict_evaluations :
|
||||
if su["ref_key"] == "qwen3-6" :
|
||||
evalution_gemma4_p2 = ""
|
||||
evalution_oss120_p2 = ""
|
||||
evalution_qwen3_6p2 = ""
|
||||
evalution_openyourmind = ""
|
||||
|
||||
for su in conflict_evaluations:
|
||||
if su["ref_key"] == "qwen3-6":
|
||||
evalution_oss120 = su["main_type"]
|
||||
# evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6" :
|
||||
if su["ref_key"] == "qwen3-6":
|
||||
evalution_qwen3_6 = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "gemma4-p2" :
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "gemma4-p2":
|
||||
evalution_gemma4_p2 = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "oss120-p2" :
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "oss120-p2":
|
||||
evalution_oss120_p2 = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6-p2" :
|
||||
evalution_qwen3_6p2 = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "openyourmind" :
|
||||
evalution_openyourmind = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
|
||||
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "qwen3-6-p2":
|
||||
evalution_qwen3_6p2 = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
if su["ref_key"] == "openyourmind":
|
||||
evalution_openyourmind = su["main_type"]
|
||||
evalution_rate += getRate(su["main_type"])
|
||||
|
||||
item = [
|
||||
str(count), _id, link ,
|
||||
"", "", subject_rate, subject_oss120, subject_qwen3_6, subject_gemma4_p2, subject_oss120_p2, subject_qwen3_6p2, subject_openyourmind,
|
||||
"", "", conflict_rate, conflict_oss120, conflict_qwen3_6, conflict_gemma4_p2, conflict_oss120_p2, conflict_qwen3_6p2, conflict_openyourmind,
|
||||
"", "", relation_rate, relation_oss120, relation_qwen3_6, relation_gemma4_p2, relation_oss120_p2, relation_qwen3_6p2, relation_openyourmind,
|
||||
"", "", evalution_rate, evalution_oss120, evalution_qwen3_6, evalution_gemma4_p2, evalution_oss120_p2, evalution_qwen3_6p2, evalution_openyourmind,
|
||||
]
|
||||
str(count),
|
||||
_id,
|
||||
link,
|
||||
"",
|
||||
"",
|
||||
subject_rate,
|
||||
subject_oss120,
|
||||
subject_qwen3_6,
|
||||
subject_gemma4_p2,
|
||||
subject_oss120_p2,
|
||||
subject_qwen3_6p2,
|
||||
subject_openyourmind,
|
||||
"",
|
||||
"",
|
||||
conflict_rate,
|
||||
conflict_oss120,
|
||||
conflict_qwen3_6,
|
||||
conflict_gemma4_p2,
|
||||
conflict_oss120_p2,
|
||||
conflict_qwen3_6p2,
|
||||
conflict_openyourmind,
|
||||
"",
|
||||
"",
|
||||
relation_rate,
|
||||
relation_oss120,
|
||||
relation_qwen3_6,
|
||||
relation_gemma4_p2,
|
||||
relation_oss120_p2,
|
||||
relation_qwen3_6p2,
|
||||
relation_openyourmind,
|
||||
"",
|
||||
"",
|
||||
evalution_rate,
|
||||
evalution_oss120,
|
||||
evalution_qwen3_6,
|
||||
evalution_gemma4_p2,
|
||||
evalution_oss120_p2,
|
||||
evalution_qwen3_6p2,
|
||||
evalution_openyourmind,
|
||||
]
|
||||
print(item)
|
||||
|
||||
|
||||
data_out.append(item)
|
||||
|
||||
@@ -809,17 +929,19 @@ def genrate_excel_data(elastic, file_ouput, index_name_o="mj_qa_conflict", key="
|
||||
# Save to Excel
|
||||
df.to_excel(file_ouput, index=False)
|
||||
|
||||
|
||||
def getRate(main_type):
|
||||
if main_type == "yes":
|
||||
return 1
|
||||
return 1
|
||||
elif main_type == "yes_under_assumptions":
|
||||
return 0.7
|
||||
return 0.7
|
||||
elif main_type == "no":
|
||||
return 0
|
||||
return 0
|
||||
elif main_type == True:
|
||||
return 1
|
||||
else :
|
||||
return 0
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
## -----------------------------------------------------------------------
|
||||
|
||||
@@ -840,11 +962,29 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
|
||||
## ----------------------------------------------------
|
||||
input_path = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3"
|
||||
file_jump_ids = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3_jump_ids.json"
|
||||
import_conflict_to_elastic(input_path, "mj_qa_conflict", file_jump_ids)
|
||||
# input_path = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3"
|
||||
# file_jump_ids = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3_jump_ids.json"
|
||||
# import_conflict_to_elastic(input_path, "mj_qa_conflict", file_jump_ids)
|
||||
|
||||
|
||||
## -----------------------------------------------------------------------
|
||||
|
||||
append_conflict_to_elastic( elastic,
|
||||
input_path=r"G:\Project2\102_gpu\v3_conflict\17K_ev_gemma4\finall_data_finall_gemma4.json",
|
||||
out_put_index_name="mj_qa_conflict",
|
||||
ref_key="gemma4",
|
||||
fields=["conflict_evaluation"])
|
||||
|
||||
# append_conflict_to_elastic( elastic,
|
||||
# input_path=r"G:\Project2\102_gpu\v3_conflict\17K_ev_gemma4\finall_data_finall_oss120.json",
|
||||
# out_put_index_name="mj_qa_conflict",
|
||||
# ref_key="oss120",
|
||||
# fields=["conflict_evaluation"])
|
||||
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
## -----------------------------------------------------------------------
|
||||
# .\.env\Scripts\activate
|
||||
# python -m app.majles.majles_conflict_works_v3
|
||||
|
||||
Reference in New Issue
Block a user