`
This commit is contained in:
@@ -413,7 +413,7 @@ def recursive_collect_child_sections(section_id, all_sections):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def extract_qanon_group_text(elastic, qanon_id, path_out="data/chunks/" ):
|
def extract_qanon_group_text(elastic, qanon_id, all_sections={}, path_out="data/chunks/" ):
|
||||||
text = ""
|
text = ""
|
||||||
body={
|
body={
|
||||||
"query": {
|
"query": {
|
||||||
@@ -428,28 +428,31 @@ def extract_qanon_group_text(elastic, qanon_id, path_out="data/chunks/" ):
|
|||||||
{"child_order": {"order": "asc"}}
|
{"child_order": {"order": "asc"}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
all_sections = {}
|
if not all_sections :
|
||||||
try:
|
try:
|
||||||
list_ = elastic.es_iterate_all_documents(index_name_o, )
|
list_ = elastic.es_iterate_all_documents(index_name_o, body)
|
||||||
for item in list_ :
|
for item in list_ :
|
||||||
all_sections[item["_id"]]=item["_source"]
|
all_sections[item["_id"]]=item["_source"]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
save_error(0, e)
|
print("Exception 1", str(e))
|
||||||
|
|
||||||
|
|
||||||
|
# original_sections = []
|
||||||
|
# qanon_sections_dict = {}
|
||||||
|
# for section_id in all_sections:
|
||||||
|
# if all_sections[section_id]['qanon_id'] == qanon_id:
|
||||||
|
# # ذخیره سکشن های اصلی هر قانون
|
||||||
|
# section_data = all_sections[section_id]
|
||||||
|
# section_data['section_id'] = section_id
|
||||||
|
# # ریختن تمام اطلاعات مربوط به هر سکشن در یک دیکشنری با کلید child_order
|
||||||
|
# qanon_sections_dict[int(all_sections[section_id]['child_order'])] = section_data
|
||||||
|
|
||||||
|
# # مرتب سازی سکشن های یک قانون بر اساس child_order
|
||||||
|
# qanon_sections_dict = dict(sorted(qanon_sections_dict.items()))
|
||||||
|
# for item in qanon_sections_dict:
|
||||||
|
# original_sections.append(qanon_sections_dict[item]['section_id'])
|
||||||
|
|
||||||
original_sections = []
|
|
||||||
qanon_sections_dict = {}
|
|
||||||
for section_id in all_sections:
|
|
||||||
if all_sections[section_id]['qanon_id'] == qanon_id:
|
|
||||||
# ذخیره سکشن های اصلی هر قانون
|
|
||||||
section_data = all_sections[section_id]
|
|
||||||
section_data['section_id'] = section_id
|
|
||||||
# ریختن تمام اطلاعات مربوط به هر سکشن در یک دیکشنری با کلید child_order
|
|
||||||
qanon_sections_dict[int(all_sections[section_id]['child_order'])] = section_data
|
|
||||||
|
|
||||||
# مرتب سازی سکشن های یک قانون بر اساس child_order
|
|
||||||
qanon_sections_dict = dict(sorted(qanon_sections_dict.items()))
|
|
||||||
for item in qanon_sections_dict:
|
|
||||||
original_sections.append(qanon_sections_dict[item]['section_id'])
|
|
||||||
# گرفتن تمام سکشن های مربوط به یک قانون
|
# گرفتن تمام سکشن های مربوط به یک قانون
|
||||||
all_chunk_sections = []
|
all_chunk_sections = []
|
||||||
qanoon_text = ''
|
qanoon_text = ''
|
||||||
@@ -457,7 +460,7 @@ def extract_qanon_group_text(elastic, qanon_id, path_out="data/chunks/" ):
|
|||||||
nlp_childs_ids = []
|
nlp_childs_ids = []
|
||||||
child_sections_ids = []
|
child_sections_ids = []
|
||||||
row_counter = 1
|
row_counter = 1
|
||||||
for row_order, section_id in enumerate(original_sections, 1):
|
for section_id, data in all_sections.items():
|
||||||
# لیست سکشن هایی که زیرجزء یک سکشن دیگر بوده اند در متغیر child_sections_ids قرار دارد و چک می کنیم که سکشن را در بازسازی متن قانون، تکرار نکنیم
|
# لیست سکشن هایی که زیرجزء یک سکشن دیگر بوده اند در متغیر child_sections_ids قرار دارد و چک می کنیم که سکشن را در بازسازی متن قانون، تکرار نکنیم
|
||||||
if section_id in child_sections_ids:
|
if section_id in child_sections_ids:
|
||||||
continue
|
continue
|
||||||
@@ -466,10 +469,13 @@ def extract_qanon_group_text(elastic, qanon_id, path_out="data/chunks/" ):
|
|||||||
# اضافه کردن سکشن های زیر مجموعه به لیست سکشن هایی که در دور بعد مجددا بررسی نشوند
|
# اضافه کردن سکشن های زیر مجموعه به لیست سکشن هایی که در دور بعد مجددا بررسی نشوند
|
||||||
child_sections_ids.extend(nlp_childs_ids)
|
child_sections_ids.extend(nlp_childs_ids)
|
||||||
|
|
||||||
qanoon_text += f"بخش (-- {row_counter} --)\n{all_sections[section_id]['content']}\n"
|
group_content =
|
||||||
for sub_id in nlp_childs_ids:
|
# qanoon_text += f"بخش (-- {row_counter} --)\n{all_sections[section_id]['content']}\n"
|
||||||
qanoon_text += f"{all_sections[sub_id]['content']}\n"
|
# for sub_id in nlp_childs_ids:
|
||||||
|
# qanoon_text += f"{all_sections[sub_id]['content']}\n"
|
||||||
|
|
||||||
nlp_childs_ids.clear()
|
nlp_childs_ids.clear()
|
||||||
|
|
||||||
qanoon_text += f'\n****************************************************\n'
|
qanoon_text += f'\n****************************************************\n'
|
||||||
row_counter += 1
|
row_counter += 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user