paln tcode
This commit is contained in:
@@ -0,0 +1,352 @@
|
||||
[
|
||||
{
|
||||
"title": "آب",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 1,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "آمار، برنامه و بودجه",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 2,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "آموزش و پرورش",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 3,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "آموزش عالی، پژوهش و فناوری",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 4,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "آیین دادرسی مدنی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 5,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "آیین دادرسی اداری",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 6,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "آیین دادرسی کیفری",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 7,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "اداری و استخدامی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 8,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "اموال و معاملات دولتی",
|
||||
"projectid": 8,
|
||||
"meta": "(با زیرفصل اجرای سیاستهای کلی اصل44)",
|
||||
"otherid": 9,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "اطلاعات، امنیت و نظامی، انتظامی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 10,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "امور زیربنایی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 11,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "انتخابات",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 12,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "اوقاف، اماکن دینی و امور مذهبی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 13,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "ایثارگران",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 14,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "بانکداری",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 15,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "برق و انرژیهای نوین",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 16,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "بیمه",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 17,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "پولی و مالی",
|
||||
"projectid": 8,
|
||||
"meta": " (با زیرفصلهای سرمایه گذاری داخلی وخارجی ـ بازار سرمایه)",
|
||||
"otherid": 18,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تأمین اجتماعی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 19,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تجارت",
|
||||
"projectid": 8,
|
||||
"meta": "(اعم از تجارت داخلی و خارجی)",
|
||||
"otherid": 20,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تشکلهای مدنی و احزاب",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 21,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تشکیلات و امور اداری قوه قضائیه",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 22,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تعاون",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 23,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تعزیرات حکومتی",
|
||||
"projectid": 8,
|
||||
"meta": "(مجازاتهای غیرقضایی)",
|
||||
"otherid": 24,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "تقسیمات کشوری و مدیریت محلی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 25,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "ثبت اسناد و املاک",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 26,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "حمل و نقل",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 27,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "خانواده",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 28,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "رسانه",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 29,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "سلامت",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 30,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "صنعت",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 31,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "ارتباطات و فناوری اطلاعات",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 32,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "فرهنگ و هنر",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 33,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "کار",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 34,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "کشاورزی و دامپروری",
|
||||
"projectid": 8,
|
||||
"meta": "(منابع طبیعی)",
|
||||
"otherid": 35,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "کیفری",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 36,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "مالکیت فکری",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 37,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "مالیات",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 38,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "محاسبات عمومی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 39,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "محیط زیست",
|
||||
"projectid": 8,
|
||||
"meta": "(اراضی مربوط به محیط زیست (خاک) زیر این کد قرار میگیرد)",
|
||||
"otherid": 40,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "مدنی و امور حسبی",
|
||||
"projectid": 8,
|
||||
"meta": " (ثبت احوال،تابعیت واتباع خارجی از سرفصلهای این کد است)",
|
||||
"otherid": 41,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "مسکن و شهرسازی",
|
||||
"projectid": 8,
|
||||
"meta": " (اراضی مربوط به مسکن و شهرسازی زیر این کد قرار میگیرد)",
|
||||
"otherid": 42,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "مصرف",
|
||||
"projectid": 8,
|
||||
"meta": " (با زیرفصل قانون سازمان ملی استاندارد، سایر قوانین و مقررات استاندارد در زیر هر یک از کدهای مربوطه قرار می گیرد)",
|
||||
"otherid": 43,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "معدن",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 44,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "مناطق آزاد و ویژه اقتصادی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 45,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "میراث فرهنگی، گردشگری و صنایع دستی",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 46,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "نظام قانونگذاری",
|
||||
"projectid": 8,
|
||||
"meta": " (که شامل سه سرفصل مجلس شورای اسلامی متشکل از (تقنین و نظارت)، شورای نگهبان، مجمع تشخیص مصلحت نظام)",
|
||||
"otherid": 47,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "نظامهای صنفی و حرفهای",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 48,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "نفت و گاز",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 49,
|
||||
"listtype": 0
|
||||
},
|
||||
{
|
||||
"title": "ورزش",
|
||||
"projectid": 8,
|
||||
"meta": "",
|
||||
"otherid": 50,
|
||||
"listtype": 0
|
||||
}
|
||||
]
|
||||
+149
-57
@@ -50,6 +50,10 @@ def get_qanon_title_sample(text):
|
||||
text = text_normalizer.hamzah_normal(text)
|
||||
text = text_normalizer.alaem_normal(text)
|
||||
text = re.sub(r"( |\u200C)+", "", text)
|
||||
|
||||
if text.startswith('فصل'):
|
||||
# در آدرس دهی چون براساس شماره ماده هست فصل مهم نیست. چون شماره ماده کلی هست
|
||||
text = re.sub(r"^(فصل[^>]>)+", "", text)
|
||||
return text
|
||||
|
||||
def get_section_title_sample(text):
|
||||
@@ -406,6 +410,52 @@ def get_qanon_date(title):
|
||||
|
||||
return qanon_title, ts_date, ts_ref
|
||||
|
||||
def get_section_correct(title):
|
||||
title=title.strip().strip(' #=').strip()
|
||||
|
||||
if title == 'کل قانون' or title == 'متن قانون' or title == 'متن' or title == 'تمام قانون' or title == 'کل مصوبه':
|
||||
return ['all']
|
||||
|
||||
title=title.replace('"', '')
|
||||
title=title.replace('اصلاحی', '')
|
||||
title = re.sub(r"(\(|\)|\>|\<|-|ـ)+", "", title)
|
||||
|
||||
subs = title.split('،')
|
||||
result = []
|
||||
for item in subs :
|
||||
item=re.sub(r"(جزء|بند|ماده|فصل|مبحث|ردیف|جدول|تبصره|پیوست|قسمت)", r"#\1", item)
|
||||
items = item.split('#')
|
||||
items.reverse()
|
||||
item = '> '.join(items).strip(' >').replace(' ', '')
|
||||
item = text_normalizer.word_digit_correction(item)
|
||||
result.append(item)
|
||||
|
||||
return result
|
||||
|
||||
def get__all_section_qanon(elastic, index_name, qanon_id):
|
||||
body = {
|
||||
"_source" : ["ref_id"],
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"term": {
|
||||
"qanon_id": {
|
||||
"value": qanon_id
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
s_res = elastic.es.search(index=index_name, body=body)
|
||||
result = []
|
||||
for item in s_res["hits"]["hits"] :
|
||||
result.append(item["_id"])
|
||||
return result
|
||||
|
||||
|
||||
def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_id , file_log, result_path = ""):
|
||||
|
||||
df = pd.read_excel(file_excel, sheet_name=0)
|
||||
@@ -486,69 +536,113 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
||||
else:
|
||||
state = 'قانون-جستجو'
|
||||
|
||||
# # اگر شناسه قانون یافت شد، برای شناسه جزء جستجو کند ...
|
||||
# if not qanon_id == 0 :
|
||||
# section_title = text_normalizer.normalize_search_qanon(str(section_title))
|
||||
# section_id, score, section_item = searchSectionId(elastic, "mj_qa_section", qanon_id , section_title)
|
||||
# # - اگر شناسه یافت شده جزء قابل اطمینان نبود خطا ثبت شود
|
||||
# if score < 90 :
|
||||
# dic_error_section_title[str(qanon_id)+'=='+section_title]=count
|
||||
# print('='*10 , str(count) , ' section error', qanon_id, ' --> ', section_title )
|
||||
# file.write('---- section error ---' + str(qanon_id) + ' ----- ' + section_title + '\n')
|
||||
# section_id = 0
|
||||
# state = 'خطا-جزء'
|
||||
# else :
|
||||
# state = 'صحیح'
|
||||
# اگر شناسه قانون یافت شد، برای شناسه جزء جستجو کند ...
|
||||
section_title = text_normalizer.normalize_search_qanon(str(section_title))
|
||||
result_section_title = get_section_correct(section_title)
|
||||
result_section_id = []
|
||||
if qanon_id != 0 :
|
||||
|
||||
for section_title in result_section_title:
|
||||
if section_title == 'all' :
|
||||
state = 'صحیح'
|
||||
result_section_id.append('all')
|
||||
continue
|
||||
|
||||
section_id, score, section_item = searchSectionId(elastic, "mj_qa_section", qanon_id , section_title)
|
||||
# - اگر شناسه یافت شده جزء قابل اطمینان نبود خطا ثبت شود
|
||||
if score < 90 :
|
||||
dic_error_section_title[str(qanon_id)+'=='+section_title]=count
|
||||
print('='*10 , str(count) , ' section error', qanon_id, ' --> ', section_title )
|
||||
file.write('---- section error ---' + str(qanon_id) + ' ----- ' + section_title + '\n')
|
||||
section_id = 0
|
||||
state = 'خطا-جزء'
|
||||
elif state == '':
|
||||
state = 'صحیح'
|
||||
|
||||
result_section_id.append(section_id)
|
||||
|
||||
# ذخیره شناسه ها و وضعیت برای اکسل جدید
|
||||
row[column_count+1]=qanon_id
|
||||
row[column_count+2]=section_id
|
||||
row[column_count+2]= '#'.join(str(item) for item in result_section_id)
|
||||
row[column_count+3]=state
|
||||
row[column_count+4]=qanon_title +'#'+ ts_date +'#'+ ts_ref
|
||||
row[column_count+5]='#'.join(result_section_title)
|
||||
rows_list_new.append(row)
|
||||
|
||||
data={}
|
||||
# # ذخیره کد در الاستیک برای شناسه های یافت شده
|
||||
# if section_id and section_id != 0:
|
||||
# item = elastic.get_doctument(index_name_o,section_id)
|
||||
# tcode_mains = []
|
||||
# tcode_subs = []
|
||||
# if "tcode_mains" in item['_source'] :
|
||||
# tcode_mains= item['_source']["tcode_mains"]
|
||||
# if "tcode_subs" in item['_source'] :
|
||||
# tcode_subs= item['_source']["tcode_subs"]
|
||||
|
||||
tstate = 'نامعتبر'
|
||||
c_name = 'وضعیت اعتبار'
|
||||
if c_name in column_names :
|
||||
tstate = row[c_name].replace('#', '').replace('=', '')
|
||||
if tstate.startswith('نامعتبر') :
|
||||
tstate = 'نامعتبر-' + tstate
|
||||
|
||||
# code = {
|
||||
# "label" : tcode_label,
|
||||
# "id" : tcode_id
|
||||
# }
|
||||
# if code_state :
|
||||
# tcode_mains.append(code)
|
||||
# else:
|
||||
# tcode_subs.append(code)
|
||||
# data={
|
||||
# '_id':section_id,
|
||||
# '_source' : {
|
||||
# 'tcode_mains': tcode_mains,
|
||||
# 'tcode_subs': tcode_subs,
|
||||
# }
|
||||
# }
|
||||
# bulk_data.append(data)
|
||||
treason = ''
|
||||
c_name = 'مستند عدم اعتبار'
|
||||
if c_name in column_names :
|
||||
treason = row[c_name].replace('#','\n').replace('=','\n')
|
||||
|
||||
description = ''
|
||||
c_name = 'توضیحات'
|
||||
if c_name in column_names :
|
||||
description = row[c_name].replace('*', '')
|
||||
|
||||
# ذخیره کد در الاستیک برای شناسه های یافت شده
|
||||
for section_id in result_section_id :
|
||||
|
||||
if section_id == '' or section_id == 0 :
|
||||
continue
|
||||
|
||||
if section_id =='all':
|
||||
tstate = tstate + ' کل '
|
||||
result = get__all_section_qanon(elastic, index_name_o, qanon_id)
|
||||
for sid in result :
|
||||
tvalid_state={
|
||||
"tstate": tstate.strip(),
|
||||
"description": description,
|
||||
"treason": treason,
|
||||
# "treason_type": treason_type
|
||||
}
|
||||
|
||||
data={
|
||||
'_id':sid,
|
||||
'_source' : {
|
||||
'tvalid_state': tvalid_state
|
||||
}
|
||||
}
|
||||
bulk_data.append(data)
|
||||
break
|
||||
|
||||
tvalid_state={
|
||||
"tstate": tstate.strip(),
|
||||
"description": description,
|
||||
"treason": treason,
|
||||
# "treason_type": treason_type
|
||||
}
|
||||
|
||||
data={
|
||||
'_id':section_id,
|
||||
'_source' : {
|
||||
'tvalid_state': tvalid_state
|
||||
}
|
||||
}
|
||||
bulk_data.append(data)
|
||||
|
||||
|
||||
# # انتقال دسته جمعی کدها به الاستیک
|
||||
# if len(bulk_data) >= 200:
|
||||
# total_count += len(bulk_data)
|
||||
# print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(count))
|
||||
# elastic.updateBulkList(bulk_data, index_name_o)
|
||||
# bulk_data = []
|
||||
# انتقال دسته جمعی کدها به الاستیک
|
||||
if len(bulk_data) >= 200:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(count))
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
|
||||
# if len(bulk_data) > 0:
|
||||
# total_count += len(bulk_data)
|
||||
# print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(count) )
|
||||
# elastic.updateBulkList(bulk_data, index_name_o)
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(count) )
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
|
||||
|
||||
# columns=['جزء', 'مصوب', 'قانون', 'اصلی', 'ردیف', 'شناسه قانون', 'شناسه جزء', 'وضعیت پردازش']
|
||||
@@ -556,6 +650,7 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
||||
column_names.append(column_count+2)
|
||||
column_names.append(column_count+3)
|
||||
column_names.append(column_count+4)
|
||||
column_names.append(column_count+5)
|
||||
columns= column_names
|
||||
new_df = pd.DataFrame(rows_list_new, columns=columns)
|
||||
if result_path == '' :
|
||||
@@ -623,10 +718,7 @@ def importCodesToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_i
|
||||
qanon_title = row[column_names[2]]
|
||||
code_state = row[column_names[3]]
|
||||
row_number = row[column_names[4]]
|
||||
if code_state :
|
||||
print ( 'ddddddddddddddcode_state' , code_state)
|
||||
else :
|
||||
print ( 'ccccccccccccccode_state' , code_state)
|
||||
|
||||
qanon_id = 0
|
||||
section_id = 0
|
||||
state = ''
|
||||
@@ -819,8 +911,8 @@ def run_Etebar_directory(elastic, directory, output):
|
||||
w1 = text_normalizer.split_words(code_name)[0]
|
||||
log_file = output + "/log_r_"+w1+".txt"
|
||||
file_path = os.path.join(directory, file)
|
||||
if code_name != 'کشاورزی' :
|
||||
continue
|
||||
# if code_name != 'سلامت' :
|
||||
# continue
|
||||
|
||||
try:
|
||||
os.makedirs(output, exist_ok=True)
|
||||
@@ -855,9 +947,9 @@ path_base_map = "G:/Project2/gateway2_main/repo/_other/"
|
||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
|
||||
# run_Codes_directory(elastic, "./data/tcodes", "./data/tcodes/result")
|
||||
run_Codes_directory(elastic, "./data/tcodes", "./data/tcodes/result")
|
||||
|
||||
run_Etebar_directory(elastic, "./data/tetebar", "./data/tetebar/result")
|
||||
# run_Etebar_directory(elastic, "./data/tetebar", "./data/tetebar/result")
|
||||
|
||||
# importCodesToElastic(elastic, "./data/tcodes/مسکن و شهرسازی.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r3.txt")
|
||||
# importCodesToElastic(elastic, "./data/tcodes/آمار، برنامه و بودجه.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r_آمار.txt")
|
||||
|
||||
+101
-18
@@ -1,6 +1,7 @@
|
||||
import pandas as pd
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
from text_normalizer import TextNormalizer
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
@@ -13,14 +14,17 @@ def read_excel_data(file_path ,sheet_name):
|
||||
df = pd.read_excel(file_path , sheet_name=sheet_name)
|
||||
df.fillna("", inplace=True)
|
||||
data = df.to_dict(orient="records")
|
||||
column_names = df.columns.tolist()
|
||||
|
||||
|
||||
text_normal = TextNormalizer()
|
||||
for row in data:
|
||||
row["CAPTION"] = text_normal.normalize_qanon(row["عنوان"])
|
||||
row["ID"] = int(row["ردیف"])
|
||||
row["F_PARENTID"] = int(row["سطح"]) - 1 if row["سطح"] > 1 else 0
|
||||
row["LEVEL"] = int(row["سطح"])
|
||||
row["CODE"] = row.get("کد", "")
|
||||
return data
|
||||
return data, column_names
|
||||
|
||||
# def insert_project():
|
||||
|
||||
@@ -37,7 +41,7 @@ def insert_project(sheet_name):
|
||||
print(f"❌ Sheet name '{sheet_name}' not found in JSON data.")
|
||||
return None
|
||||
|
||||
def insert_real(rows, projectid, IDS_DICT, childs,otherid):
|
||||
def insert_real_old(rows, projectid, IDS_DICT, childs,otherid):
|
||||
remains = []
|
||||
|
||||
for row in rows:
|
||||
@@ -96,38 +100,117 @@ def insert_real(rows, projectid, IDS_DICT, childs,otherid):
|
||||
|
||||
return remains
|
||||
|
||||
def insert_real(rows, projectid, IDS_DICT, column_names,otherid):
|
||||
remains = []
|
||||
dic_level_parent = {1:0}
|
||||
child_count = {}
|
||||
prev_level = 0
|
||||
prev_id = 0
|
||||
new_row_list=[]
|
||||
column_count = len(column_names)
|
||||
|
||||
for row in rows:
|
||||
|
||||
row_id = row["ID"]
|
||||
caption = row["CAPTION"]
|
||||
level = row["LEVEL"]
|
||||
parent = 0
|
||||
if level == 1 :
|
||||
parent = 0
|
||||
elif level == prev_level+1 :
|
||||
parent = prev_id
|
||||
dic_level_parent[level]=prev_id
|
||||
elif level in dic_level_parent:
|
||||
parent = dic_level_parent[level]
|
||||
else :
|
||||
print("error", level, row_id)
|
||||
|
||||
|
||||
child_order = child_count.get(parent, 0) + 1
|
||||
child_count[parent] = child_order
|
||||
|
||||
row[column_count+1] = parent
|
||||
row[column_count+2] = child_order
|
||||
|
||||
new_row_list.append(row)
|
||||
|
||||
# آمادهسازی درخواست
|
||||
body = {
|
||||
"title": caption,
|
||||
"projectid": projectid,
|
||||
"otherid": otherid,
|
||||
"meta": row.get("CODE", ""),
|
||||
"child_order": child_order,
|
||||
"listtype": 0,
|
||||
"parent": parent,
|
||||
}
|
||||
|
||||
prev_level = level
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
BASE_URL + 'list/' + ADD_ITEM_ROUTE,
|
||||
data=body,
|
||||
headers=HEADERS
|
||||
)
|
||||
response.raise_for_status()
|
||||
res_json = response.json()
|
||||
new_id = res_json["data"][0]["id"]
|
||||
print(f"✅ {row_id}: {caption} -> ID={new_id}")
|
||||
prev_id = new_id
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to insert {caption}: {e}")
|
||||
remains.append(row)
|
||||
continue
|
||||
|
||||
IDS_DICT[str(row_id)] = {
|
||||
"id": new_id,
|
||||
**body
|
||||
}
|
||||
|
||||
return new_row_list
|
||||
|
||||
def process_excel_data(file_path , sheet_name):
|
||||
data = read_excel_data(file_path , sheet_name)
|
||||
data = sorted(data, key=lambda x: x["ID"])
|
||||
print(f"❗️ Parent not found for F_PARENTID={data}")
|
||||
row_list, column_names = read_excel_data(file_path , sheet_name)
|
||||
row_list = sorted(row_list, key=lambda x: x["ID"])
|
||||
print(f"❗️ Parent not found for F_PARENTID={row_list}")
|
||||
IDS_DICT = {}
|
||||
childs = {}
|
||||
|
||||
projectid = insert_project(sheet_name)
|
||||
otherid = insert_project(sheet_name)-100
|
||||
otherid = projectid-100
|
||||
if not projectid:
|
||||
return
|
||||
|
||||
print("🚀 شروع درج دادهها")
|
||||
remains = insert_real(data, projectid, IDS_DICT, childs , otherid)
|
||||
rows_list_new = insert_real(row_list, projectid, IDS_DICT, column_names , otherid)
|
||||
|
||||
count = 1
|
||||
while remains and count < 3:
|
||||
print(f"\n🔁 تلاش مجدد {count}: باقیمانده {len(remains)} آیتم")
|
||||
remains = insert_real(remains, projectid, IDS_DICT, childs ,otherid)
|
||||
count += 1
|
||||
column_count=len(column_names)
|
||||
column_names.append(column_count+1)
|
||||
column_names.append(column_count+2)
|
||||
columns=column_names
|
||||
new_df = pd.DataFrame(rows_list_new, columns=columns)
|
||||
result_path = os.path.dirname(file_path)
|
||||
|
||||
file_name = sheet_name
|
||||
file_excel2 = result_path +'/پلن-'+ file_name + '.xlsx'
|
||||
|
||||
# print('rows_list_new', str(len(rows_list_new)), ' --> ', file_excel2)
|
||||
# new_df.to_excel(file_excel2, index=False, engine='openpyxl')
|
||||
|
||||
|
||||
json_file_path = f'{sheet_name}.json'
|
||||
with open(json_file_path, "w", encoding="utf-8") as file:
|
||||
json.dump(IDS_DICT, file, ensure_ascii=False, indent=4)
|
||||
# json_file_path = f'{sheet_name}.json'
|
||||
# with open(json_file_path, "w", encoding="utf-8") as file:
|
||||
# json.dump(IDS_DICT, file, ensure_ascii=False, indent=4)
|
||||
|
||||
print(f"\n✅ تمام دادهها ثبت شدند و در {sheet_name} ذخیره شدند.")
|
||||
# print(f"\n✅ تمام دادهها ثبت شدند و در {sheet_name} ذخیره شدند.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
file_path = "data/Plan.xlsx"
|
||||
# sheet_name = 'آموزش و پرورش'
|
||||
sheet_name = 'مناطق آزاد و ویژه اقتصادی'
|
||||
# sheet_name = 'فرهنگ و هنر'
|
||||
# sheet_name = 'مناطق آزاد و ویژه اقتصادی'
|
||||
sheet_name = 'فرهنگ و هنر'
|
||||
process_excel_data(file_path , sheet_name)
|
||||
|
||||
|
||||
|
||||
+36
-4
@@ -20,14 +20,44 @@ def read_excel_data(file_path ):
|
||||
row["META"] = row.get("توضیحات", "")
|
||||
return data
|
||||
|
||||
def insert_project():
|
||||
def insert_project(title, id=''):
|
||||
projectid = 8 # فرض کنید projectid ثابت است
|
||||
return projectid
|
||||
|
||||
|
||||
def insertProejct(title, id=''):
|
||||
# ایجاد فهرست جدید
|
||||
url = "project/add"
|
||||
|
||||
item = {
|
||||
"id": id,
|
||||
"title": title,
|
||||
"type": 3,
|
||||
"item_state": 1,
|
||||
"ispublic" : 1,
|
||||
}
|
||||
|
||||
result = requests.post(BASE_URL + 'list/' + url, data=item, headers = HEADERS)
|
||||
res = json.loads(result.text)
|
||||
if result.status_code == 200 :
|
||||
# print(result.text)
|
||||
New_ID = res["data"]["id"]
|
||||
print(str('project added =' + str(New_ID)))
|
||||
projectid = New_ID
|
||||
return projectid
|
||||
else :
|
||||
New_ID = res["data"]["id"]
|
||||
print(str('project exist=' + str(New_ID)))
|
||||
projectid = New_ID
|
||||
# print(res)
|
||||
return projectid
|
||||
|
||||
|
||||
|
||||
def process_excel_data(file_path, send_to_server=True):
|
||||
data = read_excel_data(file_path)
|
||||
data = sorted(data, key=lambda x: x["ID"])
|
||||
projectid = insert_project()
|
||||
projectid = insert_project('کدهای تنقیح 50 باب', 8)
|
||||
id_counter = 1 # برای fake_id
|
||||
local_id_map = {} # برای نگهداشتن ID ساختگی در حالت تست
|
||||
output_data = [] # لیستی برای ذخیره خروجی نهایی
|
||||
@@ -36,6 +66,8 @@ def process_excel_data(file_path, send_to_server=True):
|
||||
row_id = row["ID"]
|
||||
meta = row.get("META", "")
|
||||
|
||||
insertProejct('پلان ' + caption, 100+row_id)
|
||||
|
||||
# در حالت تست، parent_id از local map خونده میشه
|
||||
payload = {
|
||||
"title": caption,
|
||||
@@ -66,7 +98,7 @@ def process_excel_data(file_path, send_to_server=True):
|
||||
fake_id = id_counter
|
||||
local_id_map[row_id] = fake_id
|
||||
id_counter += 1
|
||||
print(f"🧪 TEST MODE: Would insert => {payload} | Fake ID: {fake_id}")
|
||||
# print(f"🧪 TEST MODE: Would insert => {payload} | Fake ID: {fake_id}")
|
||||
output_data.append(payload)
|
||||
file_name = "mmm1.json"
|
||||
with open(file_name, "w", encoding="utf-8") as file:
|
||||
@@ -76,4 +108,4 @@ def process_excel_data(file_path, send_to_server=True):
|
||||
if __name__ == "__main__":
|
||||
file_path = "data/کدهای 50 گانه.xlsx"
|
||||
|
||||
process_excel_data(file_path ,send_to_server=True ) # False for test
|
||||
process_excel_data(file_path ,send_to_server=False ) # False for test
|
||||
@@ -23,8 +23,9 @@ def import_lawreg_lwphase_info(cursor):
|
||||
break
|
||||
|
||||
|
||||
rr = {"id" : int(row.ID), 'title': row.CAPTION}
|
||||
ORG_DICT[str(int(row.ID))] = {"id" : row.ID, 'title': row.CAPTION}
|
||||
text = text_normal.normalize_qanon(row.CAPTION)
|
||||
rr = {"id" : int(row.ID), 'title': text}
|
||||
ORG_DICT[str(int(row.ID))] = {"id" : row.ID, 'title': text}
|
||||
|
||||
|
||||
query = '''
|
||||
|
||||
@@ -332,6 +332,7 @@ class TextNormalizer:
|
||||
# text = re.sub(r"([^\d \/\\]+?)(\d)", r"\1 \2", text)
|
||||
# text = re.sub(r"(\d+)([^\d \/\\]+?)", r"\1 \2", text)
|
||||
text = re.sub(r"[^\/](\d+)([\u0600-\u06FF\u0750-\u077F]+?)", r"\1 \2", text)
|
||||
text = re.sub(r"([\u0600-\u06FF\u0750-\u077F]+?)(\d+)", r"\1 \2", text)
|
||||
|
||||
|
||||
# ر54ر44ر135
|
||||
|
||||
Reference in New Issue
Block a user