1
This commit is contained in:
@@ -7,4 +7,34 @@
|
|||||||
err message : 'full_path'
|
err message : 'full_path'
|
||||||
err date : 2026-02-17 13:19:08.603065
|
err date : 2026-02-17 13:19:08.603065
|
||||||
|
|
||||||
|
**************************************************
|
||||||
|
|
||||||
|
id : 0
|
||||||
|
filename : G:\Project2\dataParsers\app\majles\majles_conflict_works.py
|
||||||
|
function : fill_meta_data
|
||||||
|
err line no : 104
|
||||||
|
err line : list_ = elastic.es_iterate_all_documents(index_name_i, body)
|
||||||
|
err message : name 'index_name_i' is not defined
|
||||||
|
err date : 2026-05-11 13:10:26.559717
|
||||||
|
|
||||||
|
**************************************************
|
||||||
|
|
||||||
|
id : 0
|
||||||
|
filename : G:\Project2\dataParsers\app\monir\monir_teamwork.py
|
||||||
|
function : import_from_jahat_entities
|
||||||
|
err line no : 24
|
||||||
|
err line : list_ = elastic.es_iterate_all_documents(index_name, body)
|
||||||
|
err message : name 'index_name' is not defined
|
||||||
|
err date : 2026-05-12 15:05:48.540392
|
||||||
|
|
||||||
|
**************************************************
|
||||||
|
|
||||||
|
id : 0
|
||||||
|
filename : G:\Project2\dataParsers\app\majles\majles_conflict_works.py
|
||||||
|
function : genrate_excel_data
|
||||||
|
err line no : 598
|
||||||
|
err line : list_ = elastic.es_iterate_all_documents(out_put_index_name, body)
|
||||||
|
err message : name 'out_put_index_name' is not defined
|
||||||
|
err date : 2026-06-01 19:09:38.841180
|
||||||
|
|
||||||
**************************************************
|
**************************************************
|
||||||
|
|||||||
@@ -1009,6 +1009,23 @@ def save_error(id=0, e=Exception):
|
|||||||
file.write(error + '\n' + 50*'*' + '\n')
|
file.write(error + '\n' + 50*'*' + '\n')
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
def is_image_file(file_path):
|
||||||
|
if not file_path :
|
||||||
|
return False
|
||||||
|
|
||||||
|
ext = os.path.splitext(file_path)[1].lower()
|
||||||
|
|
||||||
|
image_extensions = {
|
||||||
|
'.jpg', '.jpeg', '.png', '.gif', '.bmp',
|
||||||
|
'.webp', '.tiff', '.svg', '.ico'
|
||||||
|
}
|
||||||
|
|
||||||
|
is_image = ext in image_extensions
|
||||||
|
return is_image
|
||||||
|
# # example
|
||||||
|
# info = is_image_file('/path/to/file.png')
|
||||||
|
# print(info)
|
||||||
|
|
||||||
# تابع برای تعیین نوع عنوان قانونی
|
# تابع برای تعیین نوع عنوان قانونی
|
||||||
def getTitleType(caption: str) -> str:
|
def getTitleType(caption: str) -> str:
|
||||||
# عادیسازی متن ورودی
|
# عادیسازی متن ورودی
|
||||||
@@ -1018,17 +1035,20 @@ def getTitleType(caption: str) -> str:
|
|||||||
if "موافقتنامه" in caption or "موافقت نامه" in caption or "کنوانسیون" in caption or \
|
if "موافقتنامه" in caption or "موافقت نامه" in caption or "کنوانسیون" in caption or \
|
||||||
"قرارداد بین المللی" in caption or "مقررات بین المللی" in caption or "الحاق دولت" in caption or \
|
"قرارداد بین المللی" in caption or "مقررات بین المللی" in caption or "الحاق دولت" in caption or \
|
||||||
"الحاق ایران" in caption or "قرارداد بین المللی" in caption or \
|
"الحاق ایران" in caption or "قرارداد بین المللی" in caption or \
|
||||||
caption.startswith("قانون عضویت دولت") or caption.startswith("قانون عضویت ایران") or caption.startswith("قانون اجازه عضویت"):
|
caption.startswith("قانون عضویت دولت") or caption.startswith("قانون عضویت ایران") or \
|
||||||
|
caption.startswith("قانون اجازه عضویت") or caption.startswith("قانون معاهده") or caption.startswith("قانون یادداشت تفاهم بین") :
|
||||||
|
|
||||||
return "موافقتنامه"
|
return "موافقتنامه"
|
||||||
elif caption.startswith("الحاق ") or caption.startswith("قانون الحاق ") or caption.startswith("قانون الحاقیه "):
|
elif caption.startswith("الحاق ") or caption.startswith("قانون الحاق ") or caption.startswith("قانون الحاقیه "):
|
||||||
return "الحاقی"
|
return "الحاقی"
|
||||||
elif re.match(r"^قانون اضافه.*قانون", caption):
|
elif re.match(r"^قانون اضافه.*قانون", caption):
|
||||||
return "الحاقی"
|
return "الحاقی"
|
||||||
elif caption.startswith("اصلاح ") or re.match(r"^قانون اصلاح(?:ی)? .*قانون", caption) or re.match(r"^لایحه قانونی اصلاح(?:ی)? .*لایحه", caption):
|
elif caption.startswith("اصلاح ") or re.match(r"^قانون اصلاح(?:ی)? .*(قانون|قوانین)", caption) or re.match(r"^لایحه قانونی اصلاح(?:ی)? .*لایحه", caption):
|
||||||
return "اصلاحی"
|
return "اصلاحی"
|
||||||
elif re.match(r"^قانون اصلاحیه.*قانون", caption):
|
elif re.match(r"^قانون اصلاحیه.*قانون", caption):
|
||||||
return "اصلاحی"
|
return "اصلاحی"
|
||||||
|
elif caption.startswith("اصلاحیه "):
|
||||||
|
return "اصلاحی"
|
||||||
elif re.match(r"^قانون تغییر.*قانون", caption):
|
elif re.match(r"^قانون تغییر.*قانون", caption):
|
||||||
return "اصلاحی"
|
return "اصلاحی"
|
||||||
elif caption.startswith("نظر تفسیری ") or caption.startswith("استفساریه ") or caption.startswith("تفسیر ") or caption.startswith("قانون تفسیر ") or caption.startswith("قانون استفساریه "):
|
elif caption.startswith("نظر تفسیری ") or caption.startswith("استفساریه ") or caption.startswith("تفسیر ") or caption.startswith("قانون تفسیر ") or caption.startswith("قانون استفساریه "):
|
||||||
@@ -1075,7 +1095,7 @@ def getTitleType(caption: str) -> str:
|
|||||||
else:
|
else:
|
||||||
return "اصلی"
|
return "اصلی"
|
||||||
|
|
||||||
|
# ["الحاقی","اصلاحی","تفسیری","نامه","لغو","حذفی","تمدیدی","شمولی","نسخی","مربوط"]
|
||||||
|
|
||||||
#////////////////////////////////////////////////////////////
|
#////////////////////////////////////////////////////////////
|
||||||
#////////////////////////////////////////////////////////////
|
#////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+1009
-16
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,9 @@ def recersive_sections(
|
|||||||
"""
|
"""
|
||||||
title = section.get("title", "").strip()
|
title = section.get("title", "").strip()
|
||||||
section_list = section.get("section_list", [])
|
section_list = section.get("section_list", [])
|
||||||
|
if not section_list :
|
||||||
|
section_list = section.get("sections", [])
|
||||||
|
|
||||||
description = section.get("definition", "").strip()
|
description = section.get("definition", "").strip()
|
||||||
tags = section.get("keywords", [])
|
tags = section.get("keywords", [])
|
||||||
|
|
||||||
@@ -66,6 +69,12 @@ def recersive_sections(
|
|||||||
|
|
||||||
# Process subsections (children)
|
# Process subsections (children)
|
||||||
subsections = section.get("subsections", [])
|
subsections = section.get("subsections", [])
|
||||||
|
if not subsections :
|
||||||
|
subsections = section.get("subnodes", [])
|
||||||
|
if not subsections :
|
||||||
|
subsections = section.get("sub_title", [])
|
||||||
|
|
||||||
|
|
||||||
if subsections :
|
if subsections :
|
||||||
for idx, subsec in enumerate(subsections, start=1):
|
for idx, subsec in enumerate(subsections, start=1):
|
||||||
recersive_sections(
|
recersive_sections(
|
||||||
@@ -280,17 +289,25 @@ def import_v2_section_list(elastic, all_codes, folder_path, index_name="mj_plan"
|
|||||||
data_tree = DataHelper.load_orjson(file_path)
|
data_tree = DataHelper.load_orjson(file_path)
|
||||||
if data_tree["title"] :
|
if data_tree["title"] :
|
||||||
code_name = data_tree["title"]
|
code_name = data_tree["title"]
|
||||||
|
code_name = code_name.replace("قانون جامع", "").strip()
|
||||||
|
|
||||||
if data_tree["subsections"] :
|
if "subsections" in data_tree :
|
||||||
root_node = data_tree["subsections"]
|
root_node = data_tree["subsections"]
|
||||||
|
|
||||||
|
if "sub_title" in data_tree :
|
||||||
|
root_node = data_tree["sub_title"]
|
||||||
|
|
||||||
|
if "subnodes" in data_tree :
|
||||||
|
root_node = data_tree["subnodes"]
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(output)
|
print(output)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
item_found = [item for item in all_codes if item.get("title") == code_name]
|
item_found = [item for item in all_codes if item.get("title") == code_name]
|
||||||
if not item_found :
|
if not item_found :
|
||||||
print("* " * 10, " error in code_name ", key, code_name)
|
print("* " * 10, " error in code_name ", code_name)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
@@ -326,6 +343,7 @@ def import_v2_section_list(elastic, all_codes, folder_path, index_name="mj_plan"
|
|||||||
return list_codes_imported
|
return list_codes_imported
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv(dotenv_path='config.env')
|
load_dotenv(dotenv_path='config.env')
|
||||||
|
|
||||||
host=os.getenv('HOST_160')
|
host=os.getenv('HOST_160')
|
||||||
@@ -350,20 +368,59 @@ with open("./data/codes49.json", "r", encoding="utf8") as f:
|
|||||||
|
|
||||||
|
|
||||||
## ---------------------------------------------------------
|
## ---------------------------------------------------------
|
||||||
# .\.env\Scripts\activate
|
|
||||||
# python -m app.majles.majles_plans_import
|
|
||||||
|
|
||||||
|
# #--- برای گلان خبره استفاده شد
|
||||||
|
# D49_TgV1
|
||||||
|
|
||||||
|
# #--- D49_oss120 پلان ai - نسخه 1
|
||||||
# import_v1(elastic, all_codes, "D49_oss120")
|
# import_v1(elastic, all_codes, "D49_oss120")
|
||||||
|
|
||||||
|
|
||||||
# list_codes_imported=[]
|
# list_codes_imported=[]
|
||||||
# file_path = r"G:\Project2\102_gpu\v3\plan_dict_def_keyword.json"
|
# file_path = r"G:\Project2\102_gpu\match_plan\v2_0\plan_dict_def_keyword.json"
|
||||||
# import_v2_full_tree(elastic, all_codes, file_path, "mj_plan", list_codes_imported, "D49_oss120_gemma")
|
# import_v2_full_tree(elastic, all_codes, file_path, "mj_plan", list_codes_imported, "D49_oss120_gemma")
|
||||||
|
|
||||||
|
|
||||||
folder_path = r"G:\Project2\102_gpu\match_plan\v2"
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v3.0"
|
||||||
list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_gemma_matched")
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_gemma_matched")
|
||||||
|
|
||||||
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v3.01"
|
||||||
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_gemma_matched_2")
|
||||||
|
|
||||||
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v3.02"
|
||||||
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_gemma_matched_3")
|
||||||
|
|
||||||
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v4"
|
||||||
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_matched_4")
|
||||||
|
|
||||||
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v4.1"
|
||||||
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_matched_4-1")
|
||||||
|
|
||||||
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v4.2"
|
||||||
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_matched_4-2")
|
||||||
|
|
||||||
|
# folder_path = r"G:\Project2\102_gpu\match_plan\v4.3"
|
||||||
|
# list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss120_matched_4-3")
|
||||||
|
|
||||||
|
|
||||||
|
folder_path = r"G:\Project2\102_gpu\match_plan\v5"
|
||||||
|
list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_gemma4_5")
|
||||||
|
|
||||||
|
folder_path = r"G:\Project2\102_gpu\match_plan\v5.1_gemma"
|
||||||
|
list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_gemma4_5_1")
|
||||||
|
|
||||||
|
folder_path = r"G:\Project2\102_gpu\match_plan\v5.1_oss"
|
||||||
|
list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_oss_5_1")
|
||||||
|
|
||||||
|
folder_path = r"G:\Project2\102_gpu\match_plan\v5.1_yourmind"
|
||||||
|
list_codes_imported = import_v2_section_list(elastic, all_codes, folder_path, "mj_plan", "D49_yourmind_5_1")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## ---------------------------------------------------------
|
||||||
|
## ---------------------------------------------------------
|
||||||
|
|
||||||
|
# .\.env\Scripts\activate
|
||||||
|
# python -m app.majles.majles_plans_import
|
||||||
|
|||||||
@@ -0,0 +1,519 @@
|
|||||||
|
import mariadb
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import uuid
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||||
|
|
||||||
|
|
||||||
|
from app.common.elastic_helper import ElasticHelper
|
||||||
|
from app.common.general_functions import *
|
||||||
|
from app.common.text_normalizer import TextNormalizer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def import_from_jahat_entities(elastic, index_name_i, index_name_o):
|
||||||
|
body={}
|
||||||
|
try:
|
||||||
|
list_ = elastic.es_iterate_all_documents(index_name_i, body)
|
||||||
|
except Exception as e:
|
||||||
|
save_error(0, e)
|
||||||
|
|
||||||
|
data = list(list_)
|
||||||
|
total = len(data)
|
||||||
|
count = 0
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
for mentry in data:
|
||||||
|
count += 1
|
||||||
|
entry = mentry["source"]
|
||||||
|
_id = entry.get("id", "")
|
||||||
|
type_id = entry.get("type_id", 0)
|
||||||
|
|
||||||
|
|
||||||
|
# type_id = 1 # مسائل اولیه
|
||||||
|
# type_id = 2 # مساله
|
||||||
|
# type_id = 3 # پاسخ
|
||||||
|
|
||||||
|
# فعلا مساله ها را وارد می کنیم
|
||||||
|
if not type_id in [1,2] :
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
title = entry.get("title", "")
|
||||||
|
|
||||||
|
files = entry.get("files", [])
|
||||||
|
product = entry.get("product", "")
|
||||||
|
description = entry.get("description", "")
|
||||||
|
text = entry.get("text", "")
|
||||||
|
|
||||||
|
method = entry.get("method", "")
|
||||||
|
target = entry.get("target", "")
|
||||||
|
summary = entry.get("summary", "")
|
||||||
|
links = entry.get("links", [])
|
||||||
|
|
||||||
|
subject = entry.get("subject", [])
|
||||||
|
# {
|
||||||
|
# "order": 0,
|
||||||
|
# "id": 884,
|
||||||
|
# "title": "نظام سلامت"
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "order": 0,
|
||||||
|
# "id": 888,
|
||||||
|
# "title": "کشاورزی"
|
||||||
|
# }
|
||||||
|
|
||||||
|
crition = entry.get("crition", [])
|
||||||
|
# "properties":{
|
||||||
|
# "id": { "type": "keyword" },
|
||||||
|
# "entity_id": { "type": "keyword" },
|
||||||
|
# "entity_title": { "type": "keyword" },
|
||||||
|
# "description": { "type": "text" }
|
||||||
|
# }
|
||||||
|
|
||||||
|
questions = entry.get("questions", [])
|
||||||
|
# "properties":{
|
||||||
|
# "id": { "type": "keyword" },
|
||||||
|
# "title": { "type": "text" },
|
||||||
|
# }
|
||||||
|
|
||||||
|
notes = entry.get("notes", [])
|
||||||
|
# "properties":{
|
||||||
|
# "id": { "type": "keyword" },
|
||||||
|
# "text": { "type": "text" },
|
||||||
|
# "resource": { "type": "text" },
|
||||||
|
# "description": { "type": "text" },
|
||||||
|
# "link": { "type": "text" },
|
||||||
|
# "file": { "type": "keyword" }
|
||||||
|
# }
|
||||||
|
|
||||||
|
necessity = entry.get("necessity", [])
|
||||||
|
# "properties":{
|
||||||
|
# "id": { "type": "keyword" },
|
||||||
|
# "description": { "type": "text" },
|
||||||
|
# "file": { "type": "keyword" },
|
||||||
|
# "title": {
|
||||||
|
# "type": "text",
|
||||||
|
# "fields": {
|
||||||
|
# "keyword": {
|
||||||
|
# "type": "keyword",
|
||||||
|
# "ignore_above": 256
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# entities = entry.get("entities", [])
|
||||||
|
|
||||||
|
#--- فیلدهای خالی یا بی ارزش
|
||||||
|
# html = entry.get("html", "")
|
||||||
|
# keywords = entry.get("keywords", [])
|
||||||
|
# tags = entry.get("tags", [])
|
||||||
|
# critionvalid = entry.get("critionvalid", [])
|
||||||
|
# validation = entry.get("validation", [])
|
||||||
|
# products = entry.get("products", [])
|
||||||
|
# state_id = entry.get("state_id", 0)
|
||||||
|
# Weight = entry.get("Weight", 0)
|
||||||
|
# score = entry.get("score", 0)
|
||||||
|
# date_edit = entry.get("date_edit", "")
|
||||||
|
|
||||||
|
time_edit = entry.get("time_edit", "")
|
||||||
|
date_create = entry.get("date_create", "")
|
||||||
|
|
||||||
|
user_edit = entry.get("user_edit", 0)
|
||||||
|
user_create = entry.get("user_create", 0)
|
||||||
|
user_log = entry.get("user_log", [])
|
||||||
|
|
||||||
|
file_main = {}
|
||||||
|
files_new = []
|
||||||
|
for file in files :
|
||||||
|
if "file" in file :
|
||||||
|
file["link"] = file["file"]
|
||||||
|
del file["file"]
|
||||||
|
|
||||||
|
if not file_main and is_image_file(file["link"]) :
|
||||||
|
file_main = file
|
||||||
|
else :
|
||||||
|
files_new.append(file)
|
||||||
|
|
||||||
|
relations = []
|
||||||
|
if crition :
|
||||||
|
for item in crition :
|
||||||
|
if not item["entity_title"] :
|
||||||
|
continue
|
||||||
|
title = item["entity_title"].replace("* ", "").strip()
|
||||||
|
new = {
|
||||||
|
"id": item["entity_id"],
|
||||||
|
"title": title,
|
||||||
|
"relation_type": "معیار صحت"
|
||||||
|
}
|
||||||
|
if "description" in item :
|
||||||
|
new["description"] = item["description"]
|
||||||
|
relations.append(new)
|
||||||
|
|
||||||
|
sections = []
|
||||||
|
if notes :
|
||||||
|
child_order = 0
|
||||||
|
for item in notes :
|
||||||
|
child_order = child_order + 1
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_no" + str(child_order),
|
||||||
|
"section_type" : "نکات",
|
||||||
|
"child_order" : child_order,
|
||||||
|
"title" : item["title"],
|
||||||
|
"description" : item["description"]
|
||||||
|
})
|
||||||
|
|
||||||
|
if necessity :
|
||||||
|
child_order = 0
|
||||||
|
for item in necessity :
|
||||||
|
child_order = child_order + 1
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_nc" + str(child_order),
|
||||||
|
"section_type" : "ضرورت",
|
||||||
|
"child_order" : child_order,
|
||||||
|
"title" : item["title"],
|
||||||
|
"file" : item["file"],
|
||||||
|
"description" : item["description"]
|
||||||
|
})
|
||||||
|
|
||||||
|
if description :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_de",
|
||||||
|
"section_type" : "بیان",
|
||||||
|
"description" : description
|
||||||
|
})
|
||||||
|
if text :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_tx",
|
||||||
|
"section_type" : "توضیح",
|
||||||
|
"description" : text
|
||||||
|
})
|
||||||
|
if product :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_pr",
|
||||||
|
"section_type" : "محصول",
|
||||||
|
"description" : product
|
||||||
|
})
|
||||||
|
|
||||||
|
if method :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_mt",
|
||||||
|
"section_type" : "روش",
|
||||||
|
"description" : method
|
||||||
|
})
|
||||||
|
if target :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_ta",
|
||||||
|
"section_type" : "هدف",
|
||||||
|
"description" : target
|
||||||
|
})
|
||||||
|
if summary :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_sm",
|
||||||
|
"section_type" : "چکیده",
|
||||||
|
"description" : summary
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# subject ??
|
||||||
|
data = {
|
||||||
|
"id" : _id,
|
||||||
|
"main_type" : "مساله",
|
||||||
|
"other_type" : "جهادعلمی",
|
||||||
|
"title" : title,
|
||||||
|
"file_main" : file_main,
|
||||||
|
"files" : files_new,
|
||||||
|
"sections" : sections,
|
||||||
|
"relations" : relations,
|
||||||
|
"links" : links,
|
||||||
|
"user_logs" : user_log,
|
||||||
|
"user_create" : user_create,
|
||||||
|
"user_edit" : user_edit,
|
||||||
|
"time_create" : date_create,
|
||||||
|
"time_edit" : time_edit,
|
||||||
|
}
|
||||||
|
|
||||||
|
bulk_data.append({"_id": _id, "_source": data})
|
||||||
|
|
||||||
|
|
||||||
|
if len(bulk_data) > 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
# break
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def import_from_crition_entities(elastic, index_name_i, index_name_o):
|
||||||
|
body={}
|
||||||
|
try:
|
||||||
|
list_ = elastic.es_iterate_all_documents(index_name_i, body)
|
||||||
|
except Exception as e:
|
||||||
|
save_error(0, e)
|
||||||
|
|
||||||
|
data = list(list_)
|
||||||
|
total = len(data)
|
||||||
|
count = 0
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
for mentry in data:
|
||||||
|
count += 1
|
||||||
|
entry = mentry["source"]
|
||||||
|
_id = entry.get("id", "")
|
||||||
|
type_id = entry.get("type_id", 4)
|
||||||
|
type_id = 4 # معیار
|
||||||
|
|
||||||
|
title = entry.get("title", "")
|
||||||
|
files = entry.get("files", [])
|
||||||
|
if isinstance(files, dict) :
|
||||||
|
files = [files]
|
||||||
|
|
||||||
|
unfavorite = entry.get("unfavorite", "")
|
||||||
|
if not isinstance(unfavorite, list) :
|
||||||
|
unfavorite = unfavorite.split("•")
|
||||||
|
|
||||||
|
favorite = entry.get("favorite", "")
|
||||||
|
if not isinstance(favorite, list) :
|
||||||
|
favorite = favorite.split("•")
|
||||||
|
|
||||||
|
text = entry.get("text", "")
|
||||||
|
description = entry.get("description", "")
|
||||||
|
summary = entry.get("summary", "")
|
||||||
|
|
||||||
|
result = entry.get("result", {})
|
||||||
|
# {
|
||||||
|
# "type": "پیامدهای ساختاری-نهادی در هر منطقه",
|
||||||
|
# "title": "ساختارهای توسعه حضور آزادانه، آگاهانه، مسئولانه و احسان و ایثارپایۀ مردم، با محوریت علماء دینی، و ارتباط صمیمانه و محبتآمیز با حاکمیت در مدیریت تحقق پیشرفت و سبک زندگی اسلامیـایرانی شکل گرفته و نهادینه شده است (چرخه حضور)."
|
||||||
|
# }
|
||||||
|
|
||||||
|
links = entry.get("links", [])
|
||||||
|
|
||||||
|
|
||||||
|
fish = entry.get("fish", [])
|
||||||
|
# {
|
||||||
|
# "text": "کار جهادی باید هدفمند، درست متوجه به آرمانها و هوشمندانه و عاقلانه و دشمنشکن باشد. یعنی به همان معنائی که ما مبارزه را در اصطلاح معمولی به کار میبریم: «دارم مبارزه میکنم؛ این یک مبارزه است.» این، یک تعبیر مصطلح است. در جهاد، این معنا هست.",
|
||||||
|
# "resource": "بیانات در بازدید از پژوهشکده رویان",
|
||||||
|
# "description": "",
|
||||||
|
# "date_text": "25/04/1386"
|
||||||
|
# }
|
||||||
|
|
||||||
|
subject = entry.get("subject", [])
|
||||||
|
# {
|
||||||
|
# "order": 0,
|
||||||
|
# "id": 884,
|
||||||
|
# "title": "نظام سلامت"
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "order": 0,
|
||||||
|
# "id": 888,
|
||||||
|
# "title": "کشاورزی"
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# entities = entry.get("entities", [])
|
||||||
|
|
||||||
|
#--- فیلدهای خالی یا بی ارزش
|
||||||
|
# html = entry.get("html", "")
|
||||||
|
# keywords = entry.get("keywords", [])
|
||||||
|
# tags = entry.get("tags", [])
|
||||||
|
# date_edit = entry.get("date_edit", "")
|
||||||
|
|
||||||
|
time_edit = entry.get("time_edit", "")
|
||||||
|
date_create = entry.get("date_create", "")
|
||||||
|
user_edit = entry.get("user_edit", 0)
|
||||||
|
user_create = entry.get("user_create", 0)
|
||||||
|
user_log = entry.get("user_log", [])
|
||||||
|
|
||||||
|
|
||||||
|
file_main = {}
|
||||||
|
files_new = []
|
||||||
|
for file in files :
|
||||||
|
if "file" in file :
|
||||||
|
file["link"] = file["file"]
|
||||||
|
del file["file"]
|
||||||
|
if not file_main and is_image_file(file["link"]) :
|
||||||
|
file_main = file
|
||||||
|
else :
|
||||||
|
files_new.append(file)
|
||||||
|
|
||||||
|
relations = []
|
||||||
|
sections = []
|
||||||
|
title_new = ""
|
||||||
|
|
||||||
|
if favorite :
|
||||||
|
child_order = 0
|
||||||
|
for item in favorite :
|
||||||
|
item = item.replace("•", "").strip(" *•")
|
||||||
|
if not item :
|
||||||
|
continue
|
||||||
|
if not title_new :
|
||||||
|
title_new = item
|
||||||
|
child_order = child_order + 1
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_fa" + str(child_order),
|
||||||
|
"section_type" : "مطلوب",
|
||||||
|
"child_order" : child_order,
|
||||||
|
"title" : item,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if unfavorite :
|
||||||
|
child_order = 0
|
||||||
|
for item in unfavorite :
|
||||||
|
item = item.replace("•", "").strip(" *•")
|
||||||
|
if not item :
|
||||||
|
continue
|
||||||
|
if not title_new :
|
||||||
|
title_new = item
|
||||||
|
child_order = child_order + 1
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_uf" + str(child_order),
|
||||||
|
"section_type" : "نامطلوب",
|
||||||
|
"child_order" : child_order,
|
||||||
|
"title" : item,
|
||||||
|
})
|
||||||
|
dict_title = {}
|
||||||
|
if fish :
|
||||||
|
child_order = 0
|
||||||
|
for item in fish :
|
||||||
|
child_order = child_order + 1
|
||||||
|
title = ""
|
||||||
|
if "resource" in item and item["resource"]:
|
||||||
|
title += item["resource"]
|
||||||
|
if "date_text" in item and item["date_text"]:
|
||||||
|
title += " " + item["date_text"]
|
||||||
|
title = title.strip()
|
||||||
|
|
||||||
|
dict_title[title] = 1
|
||||||
|
|
||||||
|
desc = ""
|
||||||
|
if "text" in item and item["text"]:
|
||||||
|
desc += item["text"]
|
||||||
|
if "description" in item and item["description"]:
|
||||||
|
desc += "\n" + item["description"]
|
||||||
|
|
||||||
|
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_fs" + str(child_order),
|
||||||
|
"section_type" : "منبع",
|
||||||
|
"child_order" : child_order,
|
||||||
|
"title" : title,
|
||||||
|
"description" : desc,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if description :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_de",
|
||||||
|
"section_type" : "بیان",
|
||||||
|
"description" : description
|
||||||
|
})
|
||||||
|
if text :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_tx",
|
||||||
|
"section_type" : "توضیح",
|
||||||
|
"description" : text
|
||||||
|
})
|
||||||
|
|
||||||
|
if summary :
|
||||||
|
sections.append({
|
||||||
|
"id" : _id + "_sm",
|
||||||
|
"section_type" : "چکیده",
|
||||||
|
"description" : summary
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# اصلاح عنوان خودکار قبلی
|
||||||
|
if title in dict_title and title_new :
|
||||||
|
title = title_new
|
||||||
|
|
||||||
|
|
||||||
|
# subject ??
|
||||||
|
data = {
|
||||||
|
"id" : _id,
|
||||||
|
"main_type" : "معیار",
|
||||||
|
"other_type" : "جهادعلمی",
|
||||||
|
"title" : title,
|
||||||
|
"files" : files_new,
|
||||||
|
"file_main" : file_main,
|
||||||
|
"sections" : sections,
|
||||||
|
"relations" : relations,
|
||||||
|
"links" : links,
|
||||||
|
"user_logs" : user_log,
|
||||||
|
"user_create" : user_create,
|
||||||
|
"user_edit" : user_edit,
|
||||||
|
"time_create" : date_create,
|
||||||
|
"time_edit" : time_edit,
|
||||||
|
}
|
||||||
|
|
||||||
|
bulk_data.append({"_id": _id, "_source": data})
|
||||||
|
|
||||||
|
|
||||||
|
if len(bulk_data) > 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o, True)
|
||||||
|
bulk_data = []
|
||||||
|
# break
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
load_dotenv(dotenv_path="config.env")
|
||||||
|
|
||||||
|
host = os.getenv("HOST_60")
|
||||||
|
password = os.getenv("HOST_60_PASS")
|
||||||
|
|
||||||
|
# host = os.getenv("HOST_133")
|
||||||
|
# password = os.getenv("HOST_133_PASS")
|
||||||
|
|
||||||
|
# print(host)
|
||||||
|
# print(password)
|
||||||
|
|
||||||
|
path_base_map = "G:/Project2/tavasi_160/src/repo/_other/"
|
||||||
|
|
||||||
|
# path_base_map = (
|
||||||
|
# "G:\Project2\tavasi_60\src\repo\_other/"
|
||||||
|
# )
|
||||||
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||||
|
text_normalize = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
|
elastic.createIndex( 'gn_teamwork', 'general', 'gn_teamwork' )
|
||||||
|
|
||||||
|
import_from_jahat_entities(elastic, "mn_jahat", "gn_teamwork")
|
||||||
|
|
||||||
|
import_from_crition_entities(elastic, "mn_crition", "gn_teamwork")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# .\.env\Scripts\activate
|
||||||
|
# python -m app.monir.monir_teamwork
|
||||||
Reference in New Issue
Block a user