From 5581bc59f74a715ba4c451d71bebf557b0deedd3 Mon Sep 17 00:00:00 2001 From: hsafaei Date: Wed, 1 Jul 2026 20:46:12 +0330 Subject: [PATCH] 1 --- app/majles/majles_conflict_ranks_v3.py | 11 +- app/majles/majles_conflict_works_async_v3.py | 447 +------------------ app/majles/majles_conflict_works_v3.py | 12 +- 3 files changed, 18 insertions(+), 452 deletions(-) diff --git a/app/majles/majles_conflict_ranks_v3.py b/app/majles/majles_conflict_ranks_v3.py index 7b63d59..e59a443 100644 --- a/app/majles/majles_conflict_ranks_v3.py +++ b/app/majles/majles_conflict_ranks_v3.py @@ -308,7 +308,7 @@ dict_version_weight = { "yourmind-p3": 1.2 }, "relation_identifications" : { - "oss120": 0.5, + "oss120": 0.8, "gemma4": 1, "oss120-v2": 0.8, "gemma4-v3": 1, @@ -364,6 +364,7 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map) ## ----------------------------------------------------------------------- version_keys_v3 = [ "su-gemma4_cd-ri-urmind_e-qwen3.6_285k_group_v3", + "su-gemma4_cd-ri-urmind_e-qwen3.6_285k_group_v3-2", ] ## ----------------------------------------------------------------------- @@ -376,12 +377,12 @@ body={ } } -C_avg_su, C_avg_cd, C_avg_rt = compute_avg_all(elastic, "mj_qa_conflict", body) +# C_avg_su, C_avg_cd, C_avg_rt = compute_avg_all(elastic, "mj_qa_conflict", body) # #-------------------------------------------------- # #-------------------------------------------------- C_avg_su = 1 -C_avg_cd = -1.0766904925102267 -C_avg_rt = 0.3042815398297548 +C_avg_cd = -1.0745626235324917 +C_avg_rt = 0.3143402034261242 # C_avg_rt = 0.30 @@ -408,7 +409,7 @@ body={ } -# re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body) +re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, body) # re_compute_conflict_ranks(elastic, "mj_qa_conflict", C_avg_su, C_avg_cd, C_avg_rt, 3, {}) ## ----------------------------------------------------------------------- diff --git a/app/majles/majles_conflict_works_async_v3.py b/app/majles/majles_conflict_works_async_v3.py index b40f00a..055b9c2 100644 --- a/app/majles/majles_conflict_works_async_v3.py +++ b/app/majles/majles_conflict_works_async_v3.py @@ -50,12 +50,12 @@ def get_evaluation_data(data): def run_to_procssing(list_files, index_name, file_jumps, host, password): results = [] for file in list_files: - result = asyncio.run(import_from_json(file, index_name, file_jumps, host, password)) + result = asyncio.run( import_data_from_json( file, index_name, file_jumps, host, password)) results.append(result) return results -async def import_conflict_to_elastic( +async def pack_files_to_elastic( input_path, index_name, file_jumps, host, password ): @@ -115,7 +115,7 @@ async def import_conflict_to_elastic( print("finish ⏹️✅") -async def import_from_json(file, index_name, file_jumps, host, password) -> list: +async def import_data_from_json(file, index_name, file_jumps, host, password) -> list: time = datetime.datetime.now().timestamp() file_name = file.split("/")[-1:][0] @@ -144,7 +144,8 @@ async def import_from_json(file, index_name, file_jumps, host, password) -> list previous_info = item["previous_info"] next_info = item["next_info"] - version_key = item["version_key"] + # version_key = item["version_key"] + version_key = "su-gemma4_cd-ri-urmind_e-qwen3.6_285k_group_v3-2" subject_unity = item["subject_unity"] if subject_unity["main_type"] == "no": @@ -218,442 +219,6 @@ async def import_from_json(file, index_name, file_jumps, host, password) -> list print("✅", file_name, ":", time) -def append_conflict_to_elastic( - elastic, - input_path, - index_name, - ref_key, - fields=[ - "subject_unity", - "conflict_detection", - "relation_identification", - "conflict_evaluation", - "conflict_final", - "llm_output", - ], - 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)) - ] - elif os.path.isfile(input_path): - list_files.append(input_path) - - 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)) - continue - - print("@" * 5, "file start...", file) - list_notfound = [] - bulk_data = [] - bulk_data_import = [] - failed_data = [] - total_count = 0 - - for item in data_all: - - _id = item["id"] - - # if _id == "qs2489164_v2-9.qs2365626_v2-7": - # print("qs2489164_v2-9.qs2365626_v2-7") - - import_state = False - _source = {} - res = None - try: - res = elastic.get_document(index_name, _id) - except: - list_notfound.append(_id) - 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"] - - next_info = item["next_info"] - qanon_title2 = next_info["qanon_title"] - qanon_id2 = next_info["qanon_id"] - - title_type1 = getTitleType(qanon_title1) - 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 - - _source = { - "previous_info": previous_info, - "next_info": next_info, - "conflict_tags": conflict_tags, - "version_key": version_key, - "subject_unitys": [], - "conflict_detections": [], - "conflict_type_detections": [], - "conflict_relation_identifications": [], - "conflict_evaluations": [], - "conflict_finals": [], - } - 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_unity = {} - conflict_detection = {} - conflict_type_detection = {} - conflict_relation_identification = {} - conflict_evaluation = {} - conflict_final = {} - - data = {} - if ( - "subject_unity" in item - and item["subject_unity"] - and "subject_unity" in fields - ): - main_type = "" - description = "" - reason = "" - 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: - main_type = ss["main_type"] - elif "has_subject_unity" in ss: - main_type = ss["has_subject_unity"] - - if "required_assumptions" in ss: - description = ss["required_assumptions"] - elif "description" in ss: - description = ss["description"] - - if ( - "matching_rules" in ss - and len(ss["matching_rules"]) - and "reasoning" in ss["matching_rules"][0] - ): - reason = ss["matching_rules"][0]["reasoning"] - elif "reason" in ss: - reason = ss["reason"] - cd = { - "ref_key": ref_key_adv, - "main_type": main_type, - "description": description, - "reason": reason, - } - - subject_unitys = clear_array_object_by(subject_unitys, ref_key_adv) - - subject_unitys.append(cd) - data["subject_unitys"] = subject_unitys - - if ( - "conflict_detection" in item - and item["conflict_detection"] - and "conflict_detection" in fields - ): - description = "" - 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: - has_conflict = ss["has_conflict"] - - if "explanation_of_conflict" in ss: - description = ss["explanation_of_conflict"] - elif "description" in ss: - description = ss["description"] - - cd = { - "ref_key": ref_key_adv, - "has_conflict": has_conflict, - "description": description, - } - - conflict_detections = clear_array_object_by( - conflict_detections, ref_key_adv - ) - - conflict_detections.append(cd) - data["conflict_detections"] = conflict_detections - - if ( - "conflict_type_detection" in item - and item["conflict_type_detection"] - and "conflict_type_detection" in fields - ): - main_type = "" - description = "" - 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: - main_type = ss["main_type"] - elif "conflict_type" in ss: - main_type = ss["conflict_type"] - - if "description" in ss: - description = ss["description"] - elif "explanation_of_type" in ss: - description = ss["explanation_of_type"] - cd = { - "ref_key": ref_key_adv, - "main_type": main_type, - "description": description, - } - - 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 - - if ( - "relation_identification" in item - and item["relation_identification"] - and "relation_identification" in fields - ): - main_type = "" - description = "" - 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: - main_type = ss["main_type"] - elif "relation_type" in ss: - main_type = ss["relation_type"] - - if "description" in ss: - description = ss["description"] - elif "reasoning" in ss: - description = ss["reasoning"] - - cd = { - "ref_key": ref_key_adv, - "main_type": main_type, - "description": description, - } - - 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 ( - "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 - ) - - ss = item["conflict_relation_type"] - if "main_type" in ss: - main_type = ss["main_type"] - elif "relation_type" in ss: - main_type = ss["relation_type"] - - if "description" in ss: - description = ss["description"] - elif "reasoning" in ss: - description = ss["reasoning"] - - cd = { - "ref_key": ref_key_adv, - "main_type": main_type, - "description": description, - } - - 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 - ) - - if ( - "conflict_evaluation" in item - 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 - ) - - item["conflict_evaluation"]["ref_key"] = 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 - ) - - ss = item["llm_output"] - if "main_type" in ss: - main_type = ss["main_type"] - elif "valid_relation_type" in ss: - main_type = ss["valid_relation_type"] - - if "description" in ss: - description = ss["description"] - elif "comments" in ss and len(ss["comments"]): - description = ss["comments"][0] - - if "validates" in ss: - validates = ss["validates"] - else: - validates = get_evaluation_data(ss) - - cd = { - "ref_key": ref_key_adv, - "validates": validates, - "main_type": main_type, - "description": description, - } - - conflict_evaluations = clear_array_object_by( - conflict_evaluations, ref_key_adv - ) - conflict_evaluations.append(cd) - data["conflict_evaluations"] = conflict_evaluations - - if ( - "conflict_final" in item - 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 - ) - - 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: - 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}) - elif data: - bulk_data.append({"_id": _id, "_source": data}) - - if len(bulk_data_import) > 200: - total_count += len(bulk_data_import) - print("=!" * 10, " import to_elastic , total=" + str(total_count)) - elastic.importBulkList(bulk_data_import, index_name) - bulk_data_import = [] - - if len(bulk_data) > 200: - total_count += len(bulk_data) - print("=" * 10, "to_elastic , total=" + str(total_count)) - elastic.updateBulkList(bulk_data, index_name) - bulk_data = [] - # break - - if len(bulk_data_import) > 0: - total_count += len(bulk_data_import) - print("=!" * 10, " import to_elastic , total=" + str(total_count)) - elastic.importBulkList(bulk_data_import, 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, index_name) - bulk_data = [] - - def clear_array_object_by(array, ref_key): array = [c for c in array if c["ref_key"] != ref_key] @@ -998,7 +563,7 @@ if __name__ == "__main__": input_path = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3" file_jumps = r"G:\Project2\102_gpu\v3_conflict\285k_group_v3_jump_files.json" asyncio.run( - import_conflict_to_elastic( + pack_files_to_elastic( input_path, "mj_qa_conflict", file_jumps, host, password ) ) diff --git a/app/majles/majles_conflict_works_v3.py b/app/majles/majles_conflict_works_v3.py index 37974ca..852464c 100644 --- a/app/majles/majles_conflict_works_v3.py +++ b/app/majles/majles_conflict_works_v3.py @@ -969,14 +969,14 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map) ## ----------------------------------------------------------------------- -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_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", +# input_path=r"G:\Project2\102_gpu\v3_conflict\17K_ev_oss120b\finall_data_finall_oss120b.json", # out_put_index_name="mj_qa_conflict", # ref_key="oss120", # fields=["conflict_evaluation"])