fearlessbj4 commited on
Commit
42c70ab
1 Parent(s): 22dbe96

Upload /sim_case_sug_demo/g_h.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. sim_case_sug_demo/g_h.py +48 -48
sim_case_sug_demo/g_h.py CHANGED
@@ -196,7 +196,7 @@ def ansi_to_html_dis(_f,file_path,_tranpose=True):
196
 
197
  df=pd.DataFrame(_dict)
198
  html_table_blue_light = build_table(df, 'blue_light')
199
- #print(type(html_table_blue_light))
200
  injection="<meta charset=\"UTF-8\">"
201
  #"<td style = \"background-color: #D9E1F2;font-family: Century Gothic, sans-serif;font-size: medium;text-align: left;padding: 0px 20px 0px 0px;width: auto\">"
202
  html_table_blue_light=html_table_blue_light[:html_table_blue_light.find("<thead>")+7]+injection+html_table_blue_light[html_table_blue_light.find("<thead>")+7:]
@@ -226,7 +226,7 @@ def ansi_to_html(_f,file_path,_tranpose=True):
226
 
227
  df=pd.DataFrame(_dict)
228
  html_table_blue_light = build_table(df, 'blue_light')
229
- #print(type(html_table_blue_light))
230
  injection="<meta charset=\"UTF-8\">"
231
  #"<td style = \"background-color: #D9E1F2;font-family: Century Gothic, sans-serif;font-size: medium;text-align: left;padding: 0px 20px 0px 0px;width: auto\">"
232
  html_table_blue_light=html_table_blue_light[:html_table_blue_light.find("<thead>")+7]+injection+html_table_blue_light[html_table_blue_light.find("<thead>")+7:]
@@ -294,7 +294,7 @@ def ansi_to_image(ansi_text, font_size=20, image_path="./test.png"):
294
  segments = line.split('\033')
295
  anchor_bg_color=(255,255,255)
296
  for segment in segments:
297
- #print(segment)
298
  if segment and segment[-1]=='m':
299
  code= segment[:-1]
300
  anchor_bg_color = ANSI_BG_COLORS.get(f'\033{code}m', anchor_bg_color)
@@ -345,7 +345,7 @@ def suggesting_dis(the_pool,target_name,case_dict):
345
  v_plst_2=[_embedder.encode(_e) for _e in plst_2]
346
  v_dlst_2=[_embedder.encode(_e) for _e in dlst_2]
347
 
348
- print(clst_2)
349
 
350
  rt_lst=[]
351
  for i in tqdm(the_pool):
@@ -355,13 +355,13 @@ def suggesting_dis(the_pool,target_name,case_dict):
355
  id_lst_1=[id_lst[sen_lst.index(_e)] for _e in lst_1]
356
  vec_lst_1=[vec_lst[sen_lst.index(_e)] for _e in lst_1]#[_embedder.encode(_e) for _e in lst_1]
357
  clst_1=[corpus_clust_label[_e] for _e in id_lst_1]#[clust_search(_cluster_core_dict,_e,0.68) for _e in vec_lst_1]
358
- #print(clst_1)
359
  inset=sorted([_e for _e in set(clst_1)&set(clst_2) if _e!=-1])
360
  temp_ot={}
361
  if len(inset)>=max(1,inset_th):
362
  temp_ot["target"]=target_name
363
  temp_ot["inset"]=inset
364
- #print(len(inset))
365
  _img=img_resize(vec2img(vec_lst_1,clst_1,vec_lst_2,clst_2,clust_th),cnn_len)
366
  cnn_pred=cnn_model.predict(np.array([_img])/255)
367
 
@@ -378,7 +378,7 @@ def suggesting_dis(the_pool,target_name,case_dict):
378
  _con2.append([0]*emb_dim)
379
  _con1=np.array([_con1])
380
  _con2=np.array([_con2])
381
- print(len(_con1),len(_con2),len(_con2[0]))
382
  #_con1=list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_1))) if len(lst_1)<=bilstm_len else list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))[:bilstm_len*emb_dim]
383
  #_con2=list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_2))) if len(lst_2)<=bilstm_len else list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))[:bilstm_len*emb_dim]
384
  bilstm_pred=bilstm_model.predict([_con1,_con2])
@@ -386,14 +386,14 @@ def suggesting_dis(the_pool,target_name,case_dict):
386
 
387
  temp_ot["cnn_pred"]=float(cnn_pred[0][0])
388
  temp_ot["bilstm_pred"]=float(bilstm_pred[0][0])
389
- #print(cnn_pred)
390
- #print(bilstm_pred)
391
  x_e=[[bilstm_pred[0][0],cnn_pred[0][0]]]
392
  if bilstm_pred[0][0]>=0.75:
393
  ensemble_pred=logistic(x_r,y_r,x_e)
394
  temp_ot["ensemble_pred"]=float(ensemble_pred[0])
395
 
396
- #print(ensemble_pred)
397
 
398
  pre_lst_1=[[color_lst[inset.index(clst_1[_e]) % len(color_lst)],Fore.WHITE,lst_1[_e],Style.RESET_ALL] if clst_1[_e] in inset else [Style.RESET_ALL,lst_1[_e]] for _e in range(len(lst_1))]
399
  pre_lst_2=[[color_lst[inset.index(clst_2[_e]) % len(color_lst)],Fore.WHITE,lst_2[_e],Style.RESET_ALL] if clst_2[_e] in inset else [Style.RESET_ALL,lst_2[_e]] for _e in range(len(lst_2))]
@@ -401,7 +401,7 @@ def suggesting_dis(the_pool,target_name,case_dict):
401
  vlst_1=[[vec_lst_1[_e],pre_lst_1[_e][0]] for _e in range(len(pre_lst_1)) if len(pre_lst_1[_e])==4]
402
  vlst_2=[[vec_lst_2[_e],pre_lst_2[_e][0]] for _e in range(len(pre_lst_2)) if len(pre_lst_2[_e])==4]
403
 
404
- #print(lst_1)
405
 
406
  plst_1=replace_all("".join(corpus_pd_f[i.replace("_",",")][0]),key_lst,sp_key,1).split(sp_key)
407
 
@@ -428,10 +428,10 @@ def suggesting_dis(the_pool,target_name,case_dict):
428
  #if max_dp<max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)]):
429
  # max_dp=max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)])
430
 
431
- #print(plst_1)
432
- #print(plst_2)
433
- #print(dlst_1)
434
- #print(dlst_2)
435
  draw_lst_1=["".join(_e) for _e in pre_lst_1]
436
  draw_lst_2=["".join(_e) for _e in pre_lst_2]
437
 
@@ -441,11 +441,11 @@ def suggesting_dis(the_pool,target_name,case_dict):
441
  draw_lst_d2=["".join(_e) for _e in pre_lst_d2]
442
  #replace_all(temp_c,key_lst,",",0)
443
 
444
- #print(plst_1)
445
  tp_str=""
446
 
447
- #print("---------------------")
448
- #print(Fore.BLUE+str(i)+Style.RESET_ALL)
449
  temp_ot["case_id"]=i
450
  temp_ot["plaintiff_case1"]=[{"background_color":ANSI_COLORS[_e[0]],"font_color":ANSI_COLORS[_e[1]],"content":_e[-2]} if len(_e)==4 else {"background_color":ANSI_COLORS[Back.WHITE],"font_color":ANSI_COLORS[Fore.BLACK],"content":_e[-1]} for _e in pre_lst_p1]
451
  temp_ot["defendant_case1"]=[{"background_color":ANSI_COLORS[_e[0]],"font_color":ANSI_COLORS[_e[1]],"content":_e[-2]} if len(_e)==4 else {"background_color":ANSI_COLORS[Back.WHITE],"font_color":ANSI_COLORS[Fore.BLACK],"content":_e[-1]} for _e in pre_lst_d1]
@@ -489,7 +489,7 @@ def suggesting_dis(the_pool,target_name,case_dict):
489
 
490
  temp_ot["output"]=tp_str
491
  rt_lst.append(temp_ot)
492
- print(tp_str)
493
  ot=sorted(rt_lst,key=lambda x:x["ensemble_pred"],reverse=True)
494
  ot_lst=[i["output"] for i in ot[:sug_th]]
495
 
@@ -514,7 +514,7 @@ def suggesting(the_pool,target_name,case_dict):
514
  v_plst_2=[_embedder.encode(_e) for _e in plst_2]
515
 
516
 
517
- print(clst_2)
518
 
519
  rt_lst=[]
520
  for i in tqdm(the_pool):
@@ -524,13 +524,13 @@ def suggesting(the_pool,target_name,case_dict):
524
  id_lst_1=[id_lst[sen_lst.index(_e)] for _e in lst_1]
525
  vec_lst_1=[vec_lst[sen_lst.index(_e)] for _e in lst_1]#[_embedder.encode(_e) for _e in lst_1]
526
  clst_1=[corpus_clust_label[_e] for _e in id_lst_1]#[clust_search(_cluster_core_dict,_e,0.68) for _e in vec_lst_1]
527
- #print(clst_1)
528
  inset=sorted([_e for _e in set(clst_1)&set(clst_2) if _e!=-1])
529
  temp_ot={}
530
  if len(inset)>=max(1,inset_th):
531
  temp_ot["target"]=target_name
532
  temp_ot["inset"]=inset
533
- #print(len(inset))
534
  _img=img_resize(vec2img(vec_lst_1,clst_1,vec_lst_2,clst_2,clust_th),cnn_len)
535
  cnn_pred=cnn_model.predict(np.array([_img])/255)
536
 
@@ -547,18 +547,18 @@ def suggesting(the_pool,target_name,case_dict):
547
  _con2.append([0]*emb_dim)
548
  _con1=np.array([_con1])
549
  _con2=np.array([_con2])
550
- print(len(_con1),len(_con2),len(_con2[0]))
551
  #_con1=list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_1))) if len(lst_1)<=bilstm_len else list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))[:bilstm_len*emb_dim]
552
  #_con2=list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_2))) if len(lst_2)<=bilstm_len else list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))[:bilstm_len*emb_dim]
553
  bilstm_pred=bilstm_model.predict([_con1,_con2])
554
  temp_ot["cnn_pred"]=float(cnn_pred[0][0])
555
  temp_ot["bilstm_pred"]=float(bilstm_pred[0][0])
556
- #print(cnn_pred)
557
- #print(bilstm_pred)
558
  x_e=[[bilstm_pred[0][0],cnn_pred[0][0]]]
559
  ensemble_pred=logistic(x_r,y_r,x_e)
560
  temp_ot["ensemble_pred"]=float(ensemble_pred[0])
561
- #print(ensemble_pred)
562
 
563
  pre_lst_1=[[color_lst[inset.index(clst_1[_e]) % len(color_lst)],Fore.WHITE,lst_1[_e],Style.RESET_ALL] if clst_1[_e] in inset else [Style.RESET_ALL,lst_1[_e]] for _e in range(len(lst_1))]
564
  pre_lst_2=[[color_lst[inset.index(clst_2[_e]) % len(color_lst)],Fore.WHITE,lst_2[_e],Style.RESET_ALL] if clst_2[_e] in inset else [Style.RESET_ALL,lst_2[_e]] for _e in range(len(lst_2))]
@@ -566,7 +566,7 @@ def suggesting(the_pool,target_name,case_dict):
566
  vlst_1=[[vec_lst_1[_e],pre_lst_1[_e][0]] for _e in range(len(pre_lst_1)) if len(pre_lst_1[_e])==4]
567
  vlst_2=[[vec_lst_2[_e],pre_lst_2[_e][0]] for _e in range(len(pre_lst_2)) if len(pre_lst_2[_e])==4]
568
 
569
- #print(lst_1)
570
 
571
  plst_1=replace_all("".join(corpus_pd_f[i.replace("_",",")][0]),key_lst,sp_key,1).split(sp_key)
572
 
@@ -589,10 +589,10 @@ def suggesting(the_pool,target_name,case_dict):
589
  #if max_dp<max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)]):
590
  # max_dp=max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)])
591
 
592
- #print(plst_1)
593
- #print(plst_2)
594
- #print(dlst_1)
595
- #print(dlst_2)
596
  draw_lst_1=["".join(_e) for _e in pre_lst_1]
597
  draw_lst_2=["".join(_e) for _e in pre_lst_2]
598
 
@@ -601,11 +601,11 @@ def suggesting(the_pool,target_name,case_dict):
601
 
602
  #replace_all(temp_c,key_lst,",",0)
603
 
604
- #print(plst_1)
605
  tp_str=""
606
 
607
- #print("---------------------")
608
- #print(Fore.BLUE+str(i)+Style.RESET_ALL)
609
  temp_ot["case_id"]=i
610
 
611
  temp_ot["plaintiff_case1"]=[{"background_color":ANSI_COLORS[_e[0]],"font_color":ANSI_COLORS[_e[1]],"content":_e[-2]} if len(_e)==4 else {"background_color":ANSI_COLORS[Back.WHITE],"font_color":ANSI_COLORS[Fore.BLACK],"content":_e[-1]} for _e in pre_lst_p1]
@@ -642,7 +642,7 @@ def suggesting(the_pool,target_name,case_dict):
642
 
643
  temp_ot["output"]=tp_str
644
  rt_lst.append(temp_ot)
645
- print(tp_str)
646
  ot=sorted(rt_lst,key=lambda x:x["ensemble_pred"],reverse=True)
647
  ot_lst=[i["output"] for i in ot[:sug_th]]
648
 
@@ -794,11 +794,11 @@ import gradio as gr
794
  def case_sug_dis(file_name,plaintiff,defendant,p_point,d_point,dispute_list):
795
  global new_pd_f,new_point_f,corpus_dict
796
 
797
- #print(file_name)
798
- #print(point_f)
799
- #print(list(pd_f.keys()).index(file_name))
800
  if file_name not in new_pd_f:
801
- print("file not found")
802
  file_name="user_input"
803
  else:
804
  plaintiff=new_pd_f[file_name][0]
@@ -821,8 +821,8 @@ def case_sug_dis(file_name,plaintiff,defendant,p_point,d_point,dispute_list):
821
  dispute="\n".join(dispute_list)
822
  #ot=[Back.BLUE+dispute+Style.RESET_ALL]*10
823
  output_list=[]
824
- print("-----")
825
- print(len(ot_dict))
826
  out_path="./out_of_range.html"
827
  for i in range(sug_th):
828
  if i<len(ot_dict):
@@ -836,11 +836,11 @@ def case_sug_dis(file_name,plaintiff,defendant,p_point,d_point,dispute_list):
836
  def case_sug(file_name,plaintiff,p_point):
837
  global new_pd_f,new_point_f,corpus_dict
838
 
839
- print(file_name)
840
- #print(point_f)
841
- #print(list(pd_f.keys()).index(file_name))
842
  if file_name not in new_pd_f:
843
- print("file not found")
844
  file_name="user_input"
845
  else:
846
  plaintiff=new_pd_f[file_name][0]
@@ -852,15 +852,15 @@ def case_sug(file_name,plaintiff,p_point):
852
  p_point=p_point.split("。") if type(p_point)==type("111") else p_point
853
  _pool=[i for i in corpus_dict]
854
  _case_dict={"plaintiff":plaintiff,"p_point":p_point}
855
- print(_case_dict,[type(_case_dict[_e]) for _e in _case_dict])
856
  ot,ot_dict=suggesting(_pool,file_name,_case_dict)
857
 
858
 
859
 
860
  #ot=[Back.BLUE+dispute+Style.RESET_ALL]*10
861
  output_list=[]
862
- print("-----")
863
- print(len(ot_dict))
864
  out_path="./out_of_range.html"
865
  for i in range(sug_th):
866
  if i<len(ot_dict):
 
196
 
197
  df=pd.DataFrame(_dict)
198
  html_table_blue_light = build_table(df, 'blue_light')
199
+ ##print(type(html_table_blue_light))
200
  injection="<meta charset=\"UTF-8\">"
201
  #"<td style = \"background-color: #D9E1F2;font-family: Century Gothic, sans-serif;font-size: medium;text-align: left;padding: 0px 20px 0px 0px;width: auto\">"
202
  html_table_blue_light=html_table_blue_light[:html_table_blue_light.find("<thead>")+7]+injection+html_table_blue_light[html_table_blue_light.find("<thead>")+7:]
 
226
 
227
  df=pd.DataFrame(_dict)
228
  html_table_blue_light = build_table(df, 'blue_light')
229
+ ##print(type(html_table_blue_light))
230
  injection="<meta charset=\"UTF-8\">"
231
  #"<td style = \"background-color: #D9E1F2;font-family: Century Gothic, sans-serif;font-size: medium;text-align: left;padding: 0px 20px 0px 0px;width: auto\">"
232
  html_table_blue_light=html_table_blue_light[:html_table_blue_light.find("<thead>")+7]+injection+html_table_blue_light[html_table_blue_light.find("<thead>")+7:]
 
294
  segments = line.split('\033')
295
  anchor_bg_color=(255,255,255)
296
  for segment in segments:
297
+ ##print(segment)
298
  if segment and segment[-1]=='m':
299
  code= segment[:-1]
300
  anchor_bg_color = ANSI_BG_COLORS.get(f'\033{code}m', anchor_bg_color)
 
345
  v_plst_2=[_embedder.encode(_e) for _e in plst_2]
346
  v_dlst_2=[_embedder.encode(_e) for _e in dlst_2]
347
 
348
+ #print(clst_2)
349
 
350
  rt_lst=[]
351
  for i in tqdm(the_pool):
 
355
  id_lst_1=[id_lst[sen_lst.index(_e)] for _e in lst_1]
356
  vec_lst_1=[vec_lst[sen_lst.index(_e)] for _e in lst_1]#[_embedder.encode(_e) for _e in lst_1]
357
  clst_1=[corpus_clust_label[_e] for _e in id_lst_1]#[clust_search(_cluster_core_dict,_e,0.68) for _e in vec_lst_1]
358
+ ##print(clst_1)
359
  inset=sorted([_e for _e in set(clst_1)&set(clst_2) if _e!=-1])
360
  temp_ot={}
361
  if len(inset)>=max(1,inset_th):
362
  temp_ot["target"]=target_name
363
  temp_ot["inset"]=inset
364
+ ##print(len(inset))
365
  _img=img_resize(vec2img(vec_lst_1,clst_1,vec_lst_2,clst_2,clust_th),cnn_len)
366
  cnn_pred=cnn_model.predict(np.array([_img])/255)
367
 
 
378
  _con2.append([0]*emb_dim)
379
  _con1=np.array([_con1])
380
  _con2=np.array([_con2])
381
+ #print(len(_con1),len(_con2),len(_con2[0]))
382
  #_con1=list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_1))) if len(lst_1)<=bilstm_len else list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))[:bilstm_len*emb_dim]
383
  #_con2=list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_2))) if len(lst_2)<=bilstm_len else list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))[:bilstm_len*emb_dim]
384
  bilstm_pred=bilstm_model.predict([_con1,_con2])
 
386
 
387
  temp_ot["cnn_pred"]=float(cnn_pred[0][0])
388
  temp_ot["bilstm_pred"]=float(bilstm_pred[0][0])
389
+ ##print(cnn_pred)
390
+ ##print(bilstm_pred)
391
  x_e=[[bilstm_pred[0][0],cnn_pred[0][0]]]
392
  if bilstm_pred[0][0]>=0.75:
393
  ensemble_pred=logistic(x_r,y_r,x_e)
394
  temp_ot["ensemble_pred"]=float(ensemble_pred[0])
395
 
396
+ ##print(ensemble_pred)
397
 
398
  pre_lst_1=[[color_lst[inset.index(clst_1[_e]) % len(color_lst)],Fore.WHITE,lst_1[_e],Style.RESET_ALL] if clst_1[_e] in inset else [Style.RESET_ALL,lst_1[_e]] for _e in range(len(lst_1))]
399
  pre_lst_2=[[color_lst[inset.index(clst_2[_e]) % len(color_lst)],Fore.WHITE,lst_2[_e],Style.RESET_ALL] if clst_2[_e] in inset else [Style.RESET_ALL,lst_2[_e]] for _e in range(len(lst_2))]
 
401
  vlst_1=[[vec_lst_1[_e],pre_lst_1[_e][0]] for _e in range(len(pre_lst_1)) if len(pre_lst_1[_e])==4]
402
  vlst_2=[[vec_lst_2[_e],pre_lst_2[_e][0]] for _e in range(len(pre_lst_2)) if len(pre_lst_2[_e])==4]
403
 
404
+ ##print(lst_1)
405
 
406
  plst_1=replace_all("".join(corpus_pd_f[i.replace("_",",")][0]),key_lst,sp_key,1).split(sp_key)
407
 
 
428
  #if max_dp<max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)]):
429
  # max_dp=max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)])
430
 
431
+ ##print(plst_1)
432
+ ##print(plst_2)
433
+ ##print(dlst_1)
434
+ ##print(dlst_2)
435
  draw_lst_1=["".join(_e) for _e in pre_lst_1]
436
  draw_lst_2=["".join(_e) for _e in pre_lst_2]
437
 
 
441
  draw_lst_d2=["".join(_e) for _e in pre_lst_d2]
442
  #replace_all(temp_c,key_lst,",",0)
443
 
444
+ ##print(plst_1)
445
  tp_str=""
446
 
447
+ ##print("---------------------")
448
+ ##print(Fore.BLUE+str(i)+Style.RESET_ALL)
449
  temp_ot["case_id"]=i
450
  temp_ot["plaintiff_case1"]=[{"background_color":ANSI_COLORS[_e[0]],"font_color":ANSI_COLORS[_e[1]],"content":_e[-2]} if len(_e)==4 else {"background_color":ANSI_COLORS[Back.WHITE],"font_color":ANSI_COLORS[Fore.BLACK],"content":_e[-1]} for _e in pre_lst_p1]
451
  temp_ot["defendant_case1"]=[{"background_color":ANSI_COLORS[_e[0]],"font_color":ANSI_COLORS[_e[1]],"content":_e[-2]} if len(_e)==4 else {"background_color":ANSI_COLORS[Back.WHITE],"font_color":ANSI_COLORS[Fore.BLACK],"content":_e[-1]} for _e in pre_lst_d1]
 
489
 
490
  temp_ot["output"]=tp_str
491
  rt_lst.append(temp_ot)
492
+ #print(tp_str)
493
  ot=sorted(rt_lst,key=lambda x:x["ensemble_pred"],reverse=True)
494
  ot_lst=[i["output"] for i in ot[:sug_th]]
495
 
 
514
  v_plst_2=[_embedder.encode(_e) for _e in plst_2]
515
 
516
 
517
+ #print(clst_2)
518
 
519
  rt_lst=[]
520
  for i in tqdm(the_pool):
 
524
  id_lst_1=[id_lst[sen_lst.index(_e)] for _e in lst_1]
525
  vec_lst_1=[vec_lst[sen_lst.index(_e)] for _e in lst_1]#[_embedder.encode(_e) for _e in lst_1]
526
  clst_1=[corpus_clust_label[_e] for _e in id_lst_1]#[clust_search(_cluster_core_dict,_e,0.68) for _e in vec_lst_1]
527
+ ##print(clst_1)
528
  inset=sorted([_e for _e in set(clst_1)&set(clst_2) if _e!=-1])
529
  temp_ot={}
530
  if len(inset)>=max(1,inset_th):
531
  temp_ot["target"]=target_name
532
  temp_ot["inset"]=inset
533
+ ##print(len(inset))
534
  _img=img_resize(vec2img(vec_lst_1,clst_1,vec_lst_2,clst_2,clust_th),cnn_len)
535
  cnn_pred=cnn_model.predict(np.array([_img])/255)
536
 
 
547
  _con2.append([0]*emb_dim)
548
  _con1=np.array([_con1])
549
  _con2=np.array([_con2])
550
+ #print(len(_con1),len(_con2),len(_con2[0]))
551
  #_con1=list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_1))) if len(lst_1)<=bilstm_len else list(np.array(vec_lst_1).reshape(len(lst_1)*emb_dim))[:bilstm_len*emb_dim]
552
  #_con2=list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))+[0]*(emb_dim*(bilstm_len-len(lst_2))) if len(lst_2)<=bilstm_len else list(np.array(vec_lst_2).reshape(len(lst_2)*emb_dim))[:bilstm_len*emb_dim]
553
  bilstm_pred=bilstm_model.predict([_con1,_con2])
554
  temp_ot["cnn_pred"]=float(cnn_pred[0][0])
555
  temp_ot["bilstm_pred"]=float(bilstm_pred[0][0])
556
+ ##print(cnn_pred)
557
+ ##print(bilstm_pred)
558
  x_e=[[bilstm_pred[0][0],cnn_pred[0][0]]]
559
  ensemble_pred=logistic(x_r,y_r,x_e)
560
  temp_ot["ensemble_pred"]=float(ensemble_pred[0])
561
+ ##print(ensemble_pred)
562
 
563
  pre_lst_1=[[color_lst[inset.index(clst_1[_e]) % len(color_lst)],Fore.WHITE,lst_1[_e],Style.RESET_ALL] if clst_1[_e] in inset else [Style.RESET_ALL,lst_1[_e]] for _e in range(len(lst_1))]
564
  pre_lst_2=[[color_lst[inset.index(clst_2[_e]) % len(color_lst)],Fore.WHITE,lst_2[_e],Style.RESET_ALL] if clst_2[_e] in inset else [Style.RESET_ALL,lst_2[_e]] for _e in range(len(lst_2))]
 
566
  vlst_1=[[vec_lst_1[_e],pre_lst_1[_e][0]] for _e in range(len(pre_lst_1)) if len(pre_lst_1[_e])==4]
567
  vlst_2=[[vec_lst_2[_e],pre_lst_2[_e][0]] for _e in range(len(pre_lst_2)) if len(pre_lst_2[_e])==4]
568
 
569
+ ##print(lst_1)
570
 
571
  plst_1=replace_all("".join(corpus_pd_f[i.replace("_",",")][0]),key_lst,sp_key,1).split(sp_key)
572
 
 
589
  #if max_dp<max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)]):
590
  # max_dp=max([len(plst_1),len(plst_2),len(dlst_1),len(dlst_2)])
591
 
592
+ ##print(plst_1)
593
+ ##print(plst_2)
594
+ ##print(dlst_1)
595
+ ##print(dlst_2)
596
  draw_lst_1=["".join(_e) for _e in pre_lst_1]
597
  draw_lst_2=["".join(_e) for _e in pre_lst_2]
598
 
 
601
 
602
  #replace_all(temp_c,key_lst,",",0)
603
 
604
+ ##print(plst_1)
605
  tp_str=""
606
 
607
+ ##print("---------------------")
608
+ ##print(Fore.BLUE+str(i)+Style.RESET_ALL)
609
  temp_ot["case_id"]=i
610
 
611
  temp_ot["plaintiff_case1"]=[{"background_color":ANSI_COLORS[_e[0]],"font_color":ANSI_COLORS[_e[1]],"content":_e[-2]} if len(_e)==4 else {"background_color":ANSI_COLORS[Back.WHITE],"font_color":ANSI_COLORS[Fore.BLACK],"content":_e[-1]} for _e in pre_lst_p1]
 
642
 
643
  temp_ot["output"]=tp_str
644
  rt_lst.append(temp_ot)
645
+ #print(tp_str)
646
  ot=sorted(rt_lst,key=lambda x:x["ensemble_pred"],reverse=True)
647
  ot_lst=[i["output"] for i in ot[:sug_th]]
648
 
 
794
  def case_sug_dis(file_name,plaintiff,defendant,p_point,d_point,dispute_list):
795
  global new_pd_f,new_point_f,corpus_dict
796
 
797
+ ##print(file_name)
798
+ ##print(point_f)
799
+ ##print(list(pd_f.keys()).index(file_name))
800
  if file_name not in new_pd_f:
801
+ #print("file not found")
802
  file_name="user_input"
803
  else:
804
  plaintiff=new_pd_f[file_name][0]
 
821
  dispute="\n".join(dispute_list)
822
  #ot=[Back.BLUE+dispute+Style.RESET_ALL]*10
823
  output_list=[]
824
+ #print("-----")
825
+ #print(len(ot_dict))
826
  out_path="./out_of_range.html"
827
  for i in range(sug_th):
828
  if i<len(ot_dict):
 
836
  def case_sug(file_name,plaintiff,p_point):
837
  global new_pd_f,new_point_f,corpus_dict
838
 
839
+ #print(file_name)
840
+ ##print(point_f)
841
+ ##print(list(pd_f.keys()).index(file_name))
842
  if file_name not in new_pd_f:
843
+ #print("file not found")
844
  file_name="user_input"
845
  else:
846
  plaintiff=new_pd_f[file_name][0]
 
852
  p_point=p_point.split("。") if type(p_point)==type("111") else p_point
853
  _pool=[i for i in corpus_dict]
854
  _case_dict={"plaintiff":plaintiff,"p_point":p_point}
855
+ #print(_case_dict,[type(_case_dict[_e]) for _e in _case_dict])
856
  ot,ot_dict=suggesting(_pool,file_name,_case_dict)
857
 
858
 
859
 
860
  #ot=[Back.BLUE+dispute+Style.RESET_ALL]*10
861
  output_list=[]
862
+ #print("-----")
863
+ #print(len(ot_dict))
864
  out_path="./out_of_range.html"
865
  for i in range(sug_th):
866
  if i<len(ot_dict):