You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
2.0 KiB
51 lines
2.0 KiB
1 year ago
|
import json
|
||
|
import logging.handlers
|
||
|
from concurrent_log_handler import ConcurrentRotatingFileHandler
|
||
|
|
||
|
try:
|
||
|
log_fmt = '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'
|
||
|
formatter = logging.Formatter(log_fmt)
|
||
|
handler = ConcurrentRotatingFileHandler('./logs/log.log', maxBytes=10000000, backupCount=10,encoding='utf-8')
|
||
|
handler.setFormatter(formatter)
|
||
|
logging.basicConfig(level=logging.INFO)
|
||
|
log = logging.getLogger(__name__)
|
||
|
log.addHandler(handler)
|
||
|
except Exception as error:
|
||
|
result_dict = {"code": 500,"error_msg":"日志文件打开失败"}
|
||
|
|
||
|
#读取配置文件
|
||
|
try:
|
||
|
file = open("./config/config.json", "rb")
|
||
|
fileJson = json.load(file)
|
||
|
from_pretrained_path = fileJson["from_pretrained_path"] #预训练模型地址
|
||
|
model_path = fileJson["model_path"] #模型地址
|
||
|
|
||
|
file.close()
|
||
|
except Exception as error:
|
||
|
log.error("config error:{}".format(error),exc_info = True)
|
||
|
|
||
|
class config_class():
|
||
|
def __init__(self,model_name):
|
||
|
file = open("./config/config.json", "rb")
|
||
|
fileJson = json.load(file)
|
||
|
self.from_pretrained_path = fileJson["from_pretrained_path"] # 预训练模型地址
|
||
|
self.model_path = fileJson["model_path"]+"/"+model_name # 模型地址
|
||
|
self.tag_file_path=self.model_path+"/标签.txt"
|
||
|
def reload_ner_tag(self):
|
||
|
ner_tag_list=["O"]
|
||
|
with open(self.tag_file_path,"r",encoding="utf-8") as f:
|
||
|
line_list=f.readlines()
|
||
|
line_list_len=len(line_list)
|
||
|
for line_list_number in range(line_list_len):
|
||
|
ner_tag_list.append("A"+str(line_list_number+1))
|
||
|
return ner_tag_list
|
||
|
def reload_ner_tag_json(self):
|
||
|
ner_tag_json={}
|
||
|
with open(self.tag_file_path,"r",encoding="utf-8") as f:
|
||
|
line_list=f.readlines()
|
||
|
line_list_len=len(line_list)
|
||
|
for line_list_number in range(line_list_len):
|
||
|
line=line_list[line_list_number]
|
||
|
line=line.replace("\n","")
|
||
|
ner_tag_json["A"+str(line_list_number+1)]=line
|
||
|
return ner_tag_json
|