diff --git a/move_index_to_other.py b/common/move_index_to_other.py similarity index 100% rename from move_index_to_other.py rename to common/move_index_to_other.py diff --git a/ai_json_move_to_index.py b/for_ai/ai_json_move_to_index.py similarity index 100% rename from ai_json_move_to_index.py rename to for_ai/ai_json_move_to_index.py diff --git a/concatenace_json.py b/for_ai/concatenace_json.py similarity index 100% rename from concatenace_json.py rename to for_ai/concatenace_json.py diff --git a/create_context_ai.py b/for_ai/create_context_ai.py similarity index 100% rename from create_context_ai.py rename to for_ai/create_context_ai.py diff --git a/create_relation_tags.py b/for_ai/create_relation_tags.py similarity index 100% rename from create_relation_tags.py rename to for_ai/create_relation_tags.py diff --git a/tokens_parse_spell.py b/for_ai/extract_tokens_parse_spell.py similarity index 100% rename from tokens_parse_spell.py rename to for_ai/extract_tokens_parse_spell.py diff --git a/ner_tagging_lists.py b/for_ai/ner_tagging_lists.py similarity index 100% rename from ner_tagging_lists.py rename to for_ai/ner_tagging_lists.py diff --git a/ostan_to_list.py b/repair_data/import_ostan_to_list.py similarity index 100% rename from ostan_to_list.py rename to repair_data/import_ostan_to_list.py diff --git a/import_sysnoym.py b/repair_data/import_sysnoym.py similarity index 94% rename from import_sysnoym.py rename to repair_data/import_sysnoym.py index ecc144d..aac7db0 100644 --- a/import_sysnoym.py +++ b/repair_data/import_sysnoym.py @@ -9,12 +9,6 @@ from common.elastic_helper import ElasticHelper from create_relation_tags import * from temp_refactor_gn_dataset import * -from temp_LawSection_content import * - -# cursor, cnxn = create_cursor() -# import_law_section_to_elastic(cursor) - - load_dotenv(dotenv_path='config.env') diff --git a/qanon_title_ids.txt b/repair_data/qanon_title_ids.txt similarity index 100% rename from qanon_title_ids.txt rename to repair_data/qanon_title_ids.txt diff --git a/qanon_title_ids_old1.txt b/repair_data/qanon_title_ids_old1.txt similarity index 100% rename from qanon_title_ids_old1.txt rename to repair_data/qanon_title_ids_old1.txt diff --git a/log_search_repair.py b/repair_data/repair_log_search_action.py similarity index 100% rename from log_search_repair.py rename to repair_data/repair_log_search_action.py diff --git a/temp_LawSection_content.py b/temp_LawSection_content.py deleted file mode 100644 index 7710b17..0000000 --- a/temp_LawSection_content.py +++ /dev/null @@ -1,180 +0,0 @@ -import json -import requests -from common.config_base import * -import pyodbc -import requests -from bs4 import BeautifulSoup -from html import escape -import json -from decimal import Decimal -import datetime -import time -from common.config_base import * -from common.general_functions import * -from common.text_normalizer import TextNormalizer - - -# cursor, cnxn = create_cursor() - -def import_law_section_to_elastic(cursor) : - - query = ''' - select - s.ID as sectionId - ,isnull(s.CAPTION,'') as title -- عنوان بخش: مثلا ماده 5 - ,isnull(s.F_PARENTID,0) as parentId - ,isnull(lss.CAPTION,'') as sectionStatus -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و - ,isnull(lss2.CAPTION,'') as qanon_etebar -- برای کل قانون نه جزء یا ماده خاص : ... منسوخه، معتبر، اصلاحی، موقت و - ,isnull(s.SECTIONTEXT,'') as sectionText -- متن ماده یا تبصره - ,isnull(s.SECTIONLEVEL,0) as sectionLevel -- نسبت به عنوان قانون نامرتب و دارای مقدار تکراری هم هست ؟؟؟ - ,isnull(nestedLawType.CAPTION,'') as lawType - --,isnull(nestedLawStatus.CAPTION,'') as lawStatus - ,isnull(s.TEXTORDER,0) as textOrder -- ترتیب نمایش مواد و تبصره ها - ,s.STATENO as stateNo -- ??? - ,isnull(s.SECTIONTYPENO,0) as sectionTypeNumber -- دوهزار رکورد با مقدار صفر دارد اما مقادیر دیگری نیز پذیرفته است ؟؟؟ - -- بیش از پنج هزار رکورد با مقدار بالاتر از 1500 دارد که چنین مقادیری در جدول سکشن_تایپ وجود ندارد پس با این جدول رابطه ندارد - ,isnull(l.CAPTION,'') as lawTitle -- عنوان قانون - ,isnull(l.ID,0) as lawId -- شناسه قانون - ,isnull(l.APPROVEDATE,'') as aproveDate -- تاریخ تصویب - ,isnull(l.EXPIREDATE,'') as expireDate -- تاریخ انقضا - --,isnull(s.F_LWPHASEID,0) as phaseId -- شناسه فاز - ,s.FULLPATH as sectionFullPath -- عنوان ماده یا تبصره - ,isnull(s.SECTIONTYPENOTEXT,'') as sectionType -- ??? استفساریه، کنوانسیون، موافقت نامه، اساسنامه، تفسیر، دوم ، سوم ، چهارم، دوازدهم، خالی، 1، 2، 3، 4 - ,isnull(s.FIRSTSATENO,0) as firstStateNo -- ??? بازه 0 تا 169 - ,isnull(s.LASTSTATENO,0) as lastStateNo -- ??? بازه 0 تا 112 - ,isnull(s.HIERARCHY,'') as hierarchy - ,isnull(s.DISPLAYINCONTENTS,0) as displayInContents -- ??? صد و پنجاه و سه رکورد دارای مقدار یک و بقیه یک میلیون رکورد مقدار 0 دارد - ,isnull(s.ISINTERPRETATION,0) as isInterpretation -- ??? چهارصد و پنجاه و سه رکورد با مقدار یک دارد و بقیه مقادیر نال است - ,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_TOPICID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM lwsectiontopic where [F_SECTIONID]=s.id) as topics - ,l.[ISLAW] -- قانون - ,l.[ISREGULATION] -- مقرره - ,l.[ISCORRECTIONLETTER] -- اصلاحیه - ,( - SELECT top (1) p3.CAPTION - FROM [lwPhase] p1 - left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID - left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id - where l.ID = p1.F_LWLAWID - order by p2.APPROVEDATE asc - ) as ts_ref -- مرجع تصویب - ,( - SELECT cbt.CAPTION - FROM lwLaw l2 - left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID - where l.ID = l2.id - ) as regulationType - - - from lwSection s - left join lwLawSectionStatus lss on s.F_CMBASETABLEID_SECTIONSTATUS = lss.ID - left join lwLaw l on s.F_LWLAWID = l.ID - left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS] - left JOIN ( - SELECT l2.F_LWBASETABLEID_LAWTYPE,l2.ID,cbt.CAPTION - FROM lwLaw l2 - left JOIN cmBasetable cbt ON l2.F_LWBASETABLEID_LAWTYPE = cbt.ID - ) AS nestedLawType ON s.F_LWLAWID = nestedLawType.ID - left JOIN ( - SELECT l2.[F_LWBASETABLEID_REGULATIONTYPE],l2.ID,cbt.CAPTION - FROM lwLaw l2 - left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID - ) AS nestedRegulationType ON s.F_LWLAWID = nestedRegulationType.ID - - where l.ISLAW = 1 - order by s.F_LWLAWID,textOrder - ''' - - - cursor.execute(query) - text_normal = TextNormalizer() - - # url = BASE_URL + "repo/majles/section/multi/add" - url = BASE_URL + "repo/majles/section/multi/update" - # dict_topic = json.loads(open("list_LWTopic.json").read()) - - headers = HEADERS - - total_count = 0 - bulk_data = [] - - t1= datetime.datetime.now() - print(t1) - i = 0 - while 1: - # print(i) - i=i+1 - row = cursor.fetchone() - if not row: - break - - # if i > 1000: - # break - # print(row.sectionId) - - html = '' - if isNeedHtml(row.sectionText) : - html = row.sectionText - - try: - soup = BeautifulSoup(row.sectionText, "html.parser") - text = soup.get_text("\n", strip=True) - # text = removeHtmlNoTableTag(row.sectionText) # خطا داره - except Exception as e: - text = row.sectionText - - - text = text_normal.normalize_qanon(text) - content_len = text.__len__() - word_len = len(text_normal.split_words(text)) - - eid='qs'+ str(row.sectionId) - - - data={ - 'id':eid, - 'content': text, - 'content_len': content_len, - 'word_len': word_len - } - - if len(bulk_data) >= 200: - total_count += len(bulk_data) - print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - - # limit POST Content-Length 8388608 - pops_data = [] - while len(payload) > 8388608 : - el = bulk_data.pop() - total_count -= 1 - pops_data.append(el) - print(' ' * 10, 'len(payload) ===', str(len(payload)), ' > 8388608 , len(pops_data)='+str(len(pops_data)) ) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - - - response = requests.request("POST", url, headers=headers, data=payload) - if response.status_code != 200 : - print('*' * 10, ' error : len(bulk_data)=', str(len(bulk_data)), ' bulk_data[0]='+ str(bulk_data[0]['id']) , ' bulk_data[-1]='+ str(bulk_data[-1]['id'])) - print(response.text) - bulk_data = pops_data - continue - - bulk_data = pops_data - # print(response) - # print(response.text) - # print(row.txt) - - bulk_data.append(data) - - - - if len(bulk_data) > 0: - total_count += len(bulk_data) - print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId , ', lawid_first=' + bulk_data[0]['qanon_id']) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - - - print('end success import_law_section_to_elastic') - t2= datetime.datetime.now() - print(t2-t1) diff --git a/temp_codes.py b/temp_codes.py index 352effc..4087d6b 100644 --- a/temp_codes.py +++ b/temp_codes.py @@ -7,12 +7,6 @@ from common.elastic_helper import ElasticHelper from create_relation_tags import * from temp_refactor_gn_dataset import * -from temp_LawSection_content import * - -# cursor, cnxn = create_cursor() -# import_law_section_to_elastic(cursor) - - load_dotenv(dotenv_path='config.env') diff --git a/temps/import_prev_qanon_info.py b/temps/import_prev_qanon_info.py index ae6d60f..0e98d97 100644 --- a/temps/import_prev_qanon_info.py +++ b/temps/import_prev_qanon_info.py @@ -7,11 +7,6 @@ from common.elastic_helper import ElasticHelper from create_relation_tags import * from temp_refactor_gn_dataset import * -from temp_LawSection_content import * - -# cursor, cnxn = create_cursor() -# import_law_section_to_elastic(cursor) - load_dotenv(dotenv_path='config.env') diff --git a/script.py b/test_script.py similarity index 100% rename from script.py rename to test_script.py