77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
import os
|
|
import re
|
|
import random
|
|
from dotenv import load_dotenv
|
|
from text_normalizer import TextNormalizer
|
|
# from general import *
|
|
from general_functions import *
|
|
from 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')
|
|
|
|
|
|
host=os.getenv('HOST_160')
|
|
password=os.getenv('HOST_160_PASS')
|
|
|
|
print(host)
|
|
# print(password)
|
|
|
|
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
|
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
|
|
|
|
|
|
|
def import_synonym_virstaran_min(elastic, file_input, index_name_o):
|
|
|
|
lines = []
|
|
with open(file_input, 'r', encoding='utf-8') as file:
|
|
# نوشتن خطا در فایل
|
|
lines = file.readlines()
|
|
|
|
row = 0
|
|
for item in lines :
|
|
item = item.strip()
|
|
if not item :
|
|
continue
|
|
|
|
|
|
words = []
|
|
for w in item.split(','):
|
|
w = re.sub(r"\uFEFF|\u00AD|\u00AC", "\u200C", w)
|
|
w = w.strip("\u200C").strip()
|
|
words.append(w)
|
|
|
|
if len(words) == 0 :
|
|
continue
|
|
|
|
row = row + 1
|
|
|
|
if ( row % 10 ) == 0 :
|
|
print( 'row = ', row, '/', len(lines))
|
|
#eid = 'syn_vr_' + random.randrange(10000)
|
|
eid = 'syn_vr_' + str(10000+row)
|
|
data = {
|
|
'id' : eid,
|
|
"main_type": "synonym",
|
|
"ref_key": "virastaran",
|
|
'words' : words
|
|
}
|
|
|
|
try:
|
|
resp = elastic.update_index_doc(False, index_name_o, eid, data)
|
|
except Exception as e:
|
|
save_error(id, e)
|
|
|
|
|
|
elastic.createIndex("gn_synonym", '', "gn_synonym" )
|
|
|
|
file_excel = './data/fa_virastarn_min.txt'
|
|
import_synonym_virstaran_min(elastic, file_excel, "gn_synonym" ) |