## import os import re os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices' os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' import splittxt import tools import predict import tensorflow ## class Oral: def __init__(self, ImagingFindings, ImagingConclusion, verbose = True): self.verbose = verbose self._Conclusion = '' self._Finding = '' self.inversed = False if '送检淋巴结' in ImagingConclusion: self._Conclusion = ImagingConclusion self._Finding = ImagingFindings else: self._Conclusion = ImagingFindings self._Finding = ImagingConclusion self.inversed = True self.conclusion_replaced_word = '' self.findind_replaced_word = '' if "大于" in self._Conclusion: self.conclusion_replaced_word = "大于" if "小于" in self._Conclusion: self.conclusion_replaced_word = "小于" if "大于等于" in self._Conclusion: self.conclusion_replaced_word = "大于等于" if "小于等于" in self._Conclusion: self.conclusion_replaced_word = "小于等于" if ">" in self._Conclusion: self.conclusion_replaced_word = ">" if "大于" in self._Finding: self.findind_replaced_word = "大于" if "小于" in self._Finding: self.findind_replaced_word = "小于" if "大于等于" in self._Finding: self.findind_replaced_word = "大于等于" if "小于等于" in self._Finding: self.findind_replaced_word = "小于等于" if ">" in self._Finding: self.findind_replaced_word = ">" self._Conclusion = self._Conclusion.strip('"').strip() \ .replace("大于", ">").replace("小于", "<").replace("大于等于", "≥").replace("小于等于", "≤").replace(">", ">").replace( "<", "<") self._Finding = self._Finding.strip('"').strip() \ .replace("大于", ">").replace("小于", "<").replace("大于等于", "≥").replace("小于等于", "≤").replace(">", ">").replace( "<", "<") self.ImmunohistochemistryContent = '' self.MolecularResultsContent = '' self.Degree = '' self.CuttingEdgePathologyOther = '' self.CuttingEdgePathology = '' _, CuttingEdge1, _, MolecularResults1, Immunohistochemistry1 = splittxt.splittxt( self._Conclusion) _, CuttingEdge2, _, MolecularResults2, Immunohistochemistry2 = splittxt.splittxt( self._Finding) self.ConclusionCuttingEdge = CuttingEdge1 + CuttingEdge2 self.ConclusionMolecularResults = MolecularResults1 + MolecularResults2 if Immunohistochemistry1 != Immunohistochemistry2: self.ConclusionImmunohistochemistry = Immunohistochemistry1 + Immunohistochemistry2 else: self.ConclusionImmunohistochemistry = Immunohistochemistry1 # self.ConclusionFrist, self.ConclusionCuttingEdge, self.ConclusionMolecularResults, self.ConclusionImmunohistochemistry = splittxt.splittxt( # self._Conclusion + self._Finding) # self.FindingFrist, self.FindingCuttingEdge, self.FindingMolecularResults, self.FindingImmunohistochemistry = splittxt.splittxt( # self._Finding + self._Conclusion) if self.ConclusionCuttingEdge != "": self.CuttingEdgePathology = tools.CuttingEdgePathology(self.ConclusionCuttingEdge) # 术后病理切缘 self.CuttingEdgePathologyOther = "" if self.CuttingEdgePathology == "其他情况": CuttingEdgeID = tools.FindChar(self.ConclusionCuttingEdge)[0] + 1 self.CuttingEdgePathologyOther = self.ConclusionCuttingEdge[CuttingEdgeID:] # 其他术后病理切缘情况 self.Degree = tools.findDegree(self.ConclusionCuttingEdge) # 黏膜上皮异常增生程度 # print(self.Degree) self.Degree = self.getDegree(self.Degree) if self.CuttingEdgePathologyOther == '': self.CuttingEdgePathologyOther = '无' # 分子结果 if self.ConclusionMolecularResults != "": MolecularResultsID = tools.FindChar(self.ConclusionMolecularResults)[0] self.MolecularResultsContent = self.ConclusionMolecularResults[MolecularResultsID:] # 分子结果 if self.MolecularResultsContent == "": self.MolecularResultsContent = "无" # 免疫组化 # print(self.ConclusionImmunohistochemistry) if self.ConclusionImmunohistochemistry != "": self.Immunohistochemistryisornot = "有" # 免疫组化有无 # print(self.Immunohistochemistryisornot) # ImmunohistochemistryID = tools.FindChar(self.ConclusionImmunohistochemistry)[0] # print(tools.FindChar(self.ConclusionImmunohistochemistry)) # print(self.ConclusionImmunohistochemistry) # print(self.ConclusionImmunohistochemistry[ImmunohistochemistryID:]) # self.ImmunohistochemistryContent = self.ConclusionImmunohistochemistry[ImmunohistochemistryID:] # 免疫组化结果 self.ImmunohistochemistryContent = self.ConclusionImmunohistochemistry # 免疫组化结果 else: self.Immunohistochemistryisornot = "无" # 免疫组化有无 # self.print_original_data() self.ConclusionFrist, _, self.ConclusionCuttingLymph, _, _ = splittxt.splittxt( self._Conclusion) self.FindingFrist, _, self.FindingCuttingLymph, _, _ = splittxt.splittxt( self._Finding) self.ConclusionFrist = self.ConclusionFrist.replace('肿物', '肿块').replace('\n', '。') tensorflow.keras.backend.clear_session() if self.verbose: print(self.ConclusionFrist + self.ConclusionCuttingLymph) ans, y_pre = predict.predict(self.ConclusionFrist + self.ConclusionCuttingLymph) self._y_pre = predict.output(self.ConclusionFrist + self.ConclusionCuttingLymph, y_pre) if self.verbose: self.print_list_item(ans) self.FindingFrist = self.FindingFrist.replace('肿物', '肿块').replace('\n', '。') tensorflow.keras.backend.clear_session() if self.verbose: print(self.FindingFrist + self.FindingCuttingLymph) ans_o, y_pre_o = predict.predict(self.FindingFrist + self.FindingCuttingLymph) self._y_pre_o = predict.output(self.FindingFrist + self.FindingCuttingLymph, y_pre_o) if self.verbose: self.print_list_item(ans_o) tensorflow.keras.backend.clear_session() if self.verbose: print(self.ConclusionCuttingLymph) ans_lymph, y_pre_lymph = predict.predict(self.ConclusionCuttingLymph) self._y_pre_lymph = predict.output(self.ConclusionCuttingLymph, y_pre_lymph) # if self.verbose: # self.print_list_item(ans_lymph) def _get_entity_with_O(self, y_pre, with_o): all = [] if with_o: for i in range(len(y_pre)): if i == 0: # print('O', ImagingConclusionFrist[0:y_pre[i][2]].replace('\n', ' '), str(0), str(y_pre[i][2])) # print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3]) all.append({'tag': 'O', 'words': self.FindingFrist[0:y_pre[i][2]].replace('\n', ' '), 'h': 0, 'r': y_pre[i][2]}) all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]}) else: O_h = y_pre[i - 1][3] + 1 O_r = y_pre[i][2] # print('O', ImagingConclusionFrist[O_h:O_r].replace('\n', ' '), str(y_pre[i - 1][3] + 1), str(y_pre[i][2])) # print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3]) all.append({'tag': 'O', 'words': self.FindingFrist[O_h:O_r].replace('\n', ' '), 'h': y_pre[i - 1][3] + 1, 'r': y_pre[i][2]}) all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]}) else: for i in range(len(y_pre)): if i == 0: # print('O', ImagingConclusionFrist[0:y_pre[i][2]].replace('\n', ' '), str(0), str(y_pre[i][2])) # print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3]) all.append({'tag': 'O', 'words': self.ConclusionFrist[0:y_pre[i][2]].replace('\n', ' '), 'h': 0, 'r': y_pre[i][2]}) all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]}) else: O_h = y_pre[i - 1][3] + 1 O_r = y_pre[i][2] # print('O', ImagingConclusionFrist[O_h:O_r].replace('\n', ' '), str(y_pre[i - 1][3] + 1), str(y_pre[i][2])) # print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3]) all.append({'tag': 'O', 'words': self.ConclusionFrist[O_h:O_r].replace('\n', ' '), 'h': y_pre[i - 1][3] + 1, 'r': y_pre[i][2]}) all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]}) return all def max_size(self, type): haveSIZE = False for i in self._get_entity_with_O(self._y_pre, False): if i['tag'] == 'SIZE': haveSIZE = True all = [] if not haveSIZE: all = self._get_entity_with_O(self._y_pre_o, True) else: all = self._get_entity_with_O(self._y_pre, False) # for i in all: # print(i) max = 0 max_i = 0 numbers = [] types = [] for i in range(0, len(all)): if type in all[i]['words']: types.append(all[i]['words']) if all[i]['tag'] == 'SIZE' and len(types) != 0: numbers.append(tools.exactNumber(all[i]['words'])) types = [] if len(numbers) == 0: return "" for arr_i in range(0, len(numbers)): for num in numbers[arr_i]: if (re.match("^\d+?\.\d+?$", str(num)) or num.isdigit()) and ( re.match("^\d+?\.\d+?$", str(max)) or num.isdigit()): if float(num) > float(max): max = num max_i = arr_i s = '' for num in numbers[max_i]: s += str(num) + '*' return s.strip("*").strip("cm") def get_DOI(self): haveDOI = False for i in self._get_entity_with_O(self._y_pre_o, True): if i['tag'] == 'DOI': haveDOI = True all = [] if not haveDOI: all = self._get_entity_with_O(self._y_pre, False) else: all = self._get_entity_with_O(self._y_pre_o, True) DOI_txt = '' # all = self._get_entity_with_O(self._y_pre, False) # for i in all: # print(i) for i in all: if i['tag'] == 'DOI': DOI_txt += i['words'] + '\n' return DOI_txt def get_pT(self): pT_txt = '' haveDOI = False for i in self._get_entity_with_O(self._y_pre_o, True): if i['tag'] == 'DOI': haveDOI = True all = [] if not haveDOI: all = self._get_entity_with_O(self._y_pre, False) else: all = self._get_entity_with_O(self._y_pre_o, True) for i in all: if i['tag'] == 'DOI': pT_txt += tools.pT(i['words']) + '\n' return pT_txt def get_differentiation(self): differentiation_txt = '' differentiations = [] all = self._get_entity_with_O(self._y_pre, False) # print('self._y_pre:') for i in all: # print(i) if i['tag'] == 'LEVEL': _, ans = tools.differentiation(i['words']) differentiations.append(ans) # differentiation_txt += ans + '\n' all = self._get_entity_with_O(self._y_pre_o, True) # print('self._y_pre_o:') for i in all: # print(i) if i['tag'] == 'LEVEL': _, ans = tools.differentiation(i['words']) differentiations.append(ans.strip()) if ('中-低分化' in (self.ConclusionFrist + self.ConclusionCuttingLymph)) or ( '中-低分化' in (self.FindingFrist + self.FindingCuttingLymph)): differentiations.append("Ⅱ级中分化") differentiations.append("Ⅲ级低分化") differentiations = set(differentiations) for i in differentiations: differentiation_txt += i + '\n' return differentiation_txt def get_invasion(self, type): all = self._get_entity_with_O(self._y_pre, False) for i in all: if i['tag'] == 'INVASION': if type in i['words']: return '是' return '否' def getENE(self): all = self._get_entity_with_O(self._y_pre, False) for i in all: if i['tag'] == 'ENE': return '有' return '无' def getDegree(self, dgr): if '-' in dgr: dgr_list = dgr.split('-') for i in range(len(dgr_list)): if "度" not in dgr_list[i]: dgr_list[i] += "度" rt_dgr = "" for i in dgr_list: rt_dgr += i rt_dgr += '\n' rt_dgr.strip('\n') return rt_dgr else: return dgr def getANATOMY(self): all = self._get_entity_with_O(self._y_pre, False) have_anatomy = False for i in all: if i['tag'] == 'ANATOMY': have_anatomy = True if not have_anatomy: all = self._get_entity_with_O(self._y_pre_o, True) count_i = 0 count_o = 0 anatomy_list_init = [] for i in all: if i['tag'] == 'ANATOMY': if ('I' in i['words'] or 'V' in i['words'] or i['words'] == '左' or i['words'] == '右') and ( 'DOI' not in i['words'] and 'b' not in i['words'] and 'a' not in i['words'] and 'A' not in i[ 'words'] and 'B' not in i['words']): count_i += 1 anatomy_list_init.append(i['words']) # if i['words'] == '右' or i['words'] == '左': # rt_txt += i['words'] # else: # rt_txt += i['words'] + '、' else: count_o += 1 # print(anatomy_list_init) anatomy_list_rt = [] l_or_r = '' for i in range(len(anatomy_list_init)): if anatomy_list_init[i] == '左' or anatomy_list_init[i] == '右': l_or_r = anatomy_list_init[i] elif ('左' not in anatomy_list_init[i] and '右' not in anatomy_list_init[i]) and ( 'I' in anatomy_list_init[i] or 'V' in anatomy_list_init[i]): if l_or_r != '': anatomy_list_rt.append(l_or_r + anatomy_list_init[i].strip('区').strip('淋巴结') + '区') else: count_o += 1 elif '左' in anatomy_list_init[i] or '右' in anatomy_list_init[i]: anatomy_list_rt.append(anatomy_list_init[i].strip('区').strip('淋巴结') + '区') anatomy_set_rt = set(anatomy_list_rt) # print(anatomy_set_rt) rt_txt = '' for i in anatomy_set_rt: rt_txt += (i + '、') if count_o != 0: if count_i == 0: rt_txt = (rt_txt.strip('、') + '其他') else: rt_txt = (rt_txt.strip('、') + '、其他') return rt_txt.strip('、') def getANATOMY_o(self): all = self._get_entity_with_O(self._y_pre, False) have_anatomy = False for i in all: if i['tag'] == 'ANATOMY': have_anatomy = True if not have_anatomy: all = self._get_entity_with_O(self._y_pre_o, True) rt_txt = '' anatomy_o_list = [] anatomy_list = [] for i in all: if i['tag'] == 'ANATOMY': if ('I' in i['words'] or 'V' in i['words'] or i['words'] == '左' or i['words'] == '右') and ( 'DOI' not in i['words'] and 'b' not in i['words'] and 'a' not in i['words'] and 'A' not in i[ 'words'] and 'B' not in i['words']): anatomy_list.append(i['words']) continue else: anatomy_o_list.append(i['words']) l_or_r = '' for i in range(len(anatomy_list)): if anatomy_list[i] == '左' or anatomy_list[i] == '右': l_or_r = anatomy_list[i] elif ('左' not in anatomy_list[i] and '右' not in anatomy_list[i]) and ( 'I' in anatomy_list[i] or 'V' in anatomy_list[i]): if l_or_r == '': anatomy_o_list.append(anatomy_list[i]) elif '左' in anatomy_list[i] or '右' in anatomy_list[i]: continue # print(anatomy_o_list) if len(anatomy_o_list) == 0: return '无' anatomy_o_list = set(anatomy_o_list) for i in anatomy_o_list: if ('I' in i or 'V' in i) and ('区' not in i): rt_txt += i + '区、' else: rt_txt += i + '、' return rt_txt.strip('、') def get_histological_type(self): all = self._get_entity_with_O(self._y_pre, False) # print(all) count_s = 0 count_o = 0 rt_txt = '' for i in all: if i['tag'] == 'SQUAMOUS': count_s += 1 if i['tag'] == 'OTHER': if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[ 'words']) and ('鳞状细胞' not in i['words']): count_o += 1 all = self._get_entity_with_O(self._y_pre_o, True) # print(all) for i in all: if i['tag'] == 'SQUAMOUS': count_s += 1 if i['tag'] == 'OTHER': if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[ 'words']) and ('鳞状细胞' not in i['words']): # print(i['words']) count_o += 1 if '鳞状细胞癌' in self._Conclusion or '鳞状细胞癌' in self._Finding: count_s += 1 if count_s > 0: rt_txt += '鳞状细胞癌\n' if count_o > 0: rt_txt += '其他' if count_o == 0 and count_s == 0: rt_txt = '无' return rt_txt.strip('、') def get_other_type(self): all = self._get_entity_with_O(self._y_pre, False) # for i in all: # print(i) rt_txt = '' count = 0 entity = [] for i in all: if i['tag'] == 'OTHER': count += 1 if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[ 'words']) and ('鳞状细胞' not in i['words']): entity.append(i['words']) all = self._get_entity_with_O(self._y_pre_o, True) for i in all: if i['tag'] == 'OTHER': count += 1 if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[ 'words']) and ('鳞状细胞' not in i['words']): entity.append(i['words']) entity = set(entity) for i in entity: rt_txt += i + '\n' return '无' if count == 0 else rt_txt def get_number(self): # all = get_entity_with_O(y_pre) count = 0 # for i in self._y_pre: # print(i) for i in range(1, len(self._y_pre)): if self._y_pre[i][0] == 'NUMBER' and self._y_pre[i - 1][0] == 'ANATOMY': # print(y_pre[i][1]) if '各' in self._y_pre[i][1]: # print(self._y_pre[i][1]) count_a = 0 for j in range(1, len(self._y_pre)): if self._y_pre[j][0] == 'ANATOMY': count_a += 1 # print(self._y_pre[i][1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip( # '枚').strip('各')) count = float(self._y_pre[i][1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip( '枚').strip('各')) * count_a return count n = self._y_pre[i][1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip('枚').strip('各') if '/' in n: count += float(n.split('/')[1]) if (len(tools.exactNumber( str(n.split('/')[1]))) != 0) and n.split('/')[1] != '' and ((re.match( "^\d+?\.\d+?$", str(n.split('/')[1]))) or str(n.split('/')[1]).isdigit()) \ else float(0) else: count += float(n) if (len(tools.exactNumber(str(n)))) and ( re.match("^\d+?\.\d+?$", str(n)) or str(n).isdigit()) != 0 else float(0) return count def get_p_number(self): count = 0 num_list = [] for item in self._y_pre_lymph: if item[0] == "NUMBER": num_list.append(item) if item[0] == "PN": if item[1] == '阳性(+)' or item[1] == '阳性(+)' or item[1] == '阳性' or item[1] == '(+)' or item[ 1] == '(+)' or item[1] == '+': # print(num_list) if len(num_list) == 0: pass else: # self.print_y_pred() for p_item in num_list: n_str = p_item[1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip( '枚').strip('各') # print(n_str) if '/' in n_str: # print(n_str.split('/')[0]) # if len(tools.exactNumber(str(n_str.split('/')[0]))) != 0: # print("*") # if n_str.split('/')[0] != '': # print("**") # if (re.match("^\d+?\.\d+?$", str(n_str.split('/')[0]))) or str(n_str.split('/')[0]).isdigit(): # print("***") count += float(n_str.split('/')[0]) if (len(tools.exactNumber( str(n_str.split('/')[0]))) != 0) and n_str.split('/')[0] != '' and ((re.match( "^\d+?\.\d+?$", str(n_str.split('/')[0]))) or str(n_str.split('/')[0]).isdigit()) \ else float(0) else: count += float(n_str) if (len(tools.exactNumber(str(n_str))) != 0) and ( (re.match("^\d+?\.\d+?$", str(n_str))) or str(n_str).isdigit()) else float(0) elif item[1] == '阴性(-)' or item[1] == '阴性(-)' or item[1] == '阴性' or item[1] == '(-)' or item[ 1] == '(-)' or item[1] == '-': num_list = [] return count def get_p_max(self): p_list = [] p_list_tmp = [] size_list = [] size_list_tmp = [] # print('----------') for item in self._y_pre_lymph: if item[0] == "ANATOMY": p_list_tmp.append(item) if item[0] == "SIZE": size_list_tmp.append(item) if item[0] == "NUMBER" and '/' in item[1]: if len(p_list_tmp) == 0: pass else: for p_item in p_list_tmp: p_list.append(p_item) for size_item in size_list_tmp: size_list.append(size_item[1]) p_list_tmp = [] size_list_tmp = [] if item[0] == "PN": if item[1] == '阳性(+)' or item[1] == '阳性(+)' or item[1] == '阳性' or item[1] == '(+)' or item[ 1] == '(+)' or item[1] == '+': if len(p_list_tmp) == 0: pass else: for p_item in p_list_tmp: p_list.append(p_item) for size_item in size_list_tmp: size_list.append(size_item[1]) p_list_tmp = [] size_list_tmp = [] else: p_list_tmp = [] size_list_tmp = [] # print(p_list) # print(size_list) if len(p_list) != 0: contains_single_left = False contains_single_right = False for i in p_list: if i[1] == '左': contains_single_left = True if i[1] == '右': contains_single_right = True if contains_single_left or contains_single_right == True: p_list = self._handle_single(p_list) # for i in p_list: # print(i) # print('-------------') # self.print_y_pred_o() p_anatomy = '' for i in range(len(self._y_pre_o)): if self._y_pre_o[i][0] == 'ANATOMY': p_anatomy = self._y_pre_o[i][1].strip().strip('区') if self._y_pre_o[i][0] == 'SIZE': # print(y_pre_o[i][1]) if p_anatomy != '': for j in range(0, len(p_list)): # print(p_list[j][1].strip().strip('区')) if p_list[j][1].strip().strip('区')[0] == '左' or p_list[j][1].strip().strip('区')[0] == '右': if p_anatomy[0] != p_list[j][1].strip().strip('区')[0]: p_anatomy = p_list[j][1].strip().strip('区')[0] + p_anatomy # print(p_anatomy) # print(p_list[j][1].strip().strip('区')) # print(p_anatomy) if p_list[j][1].strip().strip('区') == p_anatomy: size_list.append(self._y_pre_o[i][1]) p_anatomy = '' all_size = [] # print(size_list) for i in size_list: for j in tools.exactNumber(i): all_size.append(j) for i in range(len(all_size)): if re.match("^\d+?\.\d+?$", all_size[i]) or all_size[i].isdigit(): all_size[i] = float(all_size[i]) # print(all_size) if len(all_size) != 0: return max(all_size) return 0 # print(len(size_list)) def _handle_single(self, p_list): rt_list = [] lr = '' for i in p_list: if i[1] == '左' or i[1] == '右': lr = i[1] else: rt_list += [[i[0], lr + i[1], i[2], i[3]]] return rt_list def get_pN(self): # if type(self.get_p_max())== int or type(self.get_p_max())== float: # print(self.get_p_max()) return tools.pN(self.get_p_number(), float(self.get_p_max()), self.getENE()) def findSJ(self): if '送检淋巴结' in self._Conclusion: return '是' else: return '否' def get_Info(self): print("术后病理切缘:") print(str(self.CuttingEdgePathology).strip()) print("其他术后病理切缘情况:") print(str(self.CuttingEdgePathologyOther).strip()) print("黏膜上皮异常增生程度:") print(str(self.Degree).strip()) print("分子结果:") print(str(self.MolecularResultsContent).strip()) print("免疫组化:") print(str(self.Immunohistochemistryisornot).strip()) print("免疫组化结果:") print(str(self.ImmunohistochemistryContent).strip()) print("送检组织大小cm:") print(str(self.max_size("组织")).strip()) print("肿块大小:") print(str(self.max_size("肿块")).strip()) print("浸润深度(DOI)mm:") print(str(self.get_DOI()).strip()) print("pT:") print(str(self.get_pT()).strip()) print("分化程度") print(str(self.get_differentiation()).strip()) print("神经侵犯:") print(str(self.get_invasion('神经')).strip()) print("血管侵犯:") print(str(self.get_invasion('血管')).strip()) print("淋巴结包膜外ENE(+):") print(str(self.getENE()).strip()) print("送检淋巴结部位:") print(str(self.getANATOMY().strip('、')).strip()) print("其他送检淋巴结部位:") print(str(self.getANATOMY_o().strip('、')).strip()) print("组织学类型:") print(str(self.get_histological_type()).strip()) print("其他组织学类型:") print(str(self.get_other_type()).strip()) if self.findSJ() == '是': print('送检淋巴结数目:') print(str(self.get_number()).strip()) print("阳性淋巴结数量:") print(str(self.get_p_number()).strip()) print("阳性淋巴结最大直径cm:") print(str(self.get_p_max()).strip()) print("pN:") print(str(self.get_pN()).strip()) def print_original_data(self): print(self._Finding) print(self._Conclusion) def print_y_pred(self): for i in self._y_pre: print(i) def print_y_pred_o(self): for i in self._y_pre_o: print(i) def get_entity(self): finding_list = [] conclusion_list = [] if self.inversed == True: for i in self._y_pre: finding_list.append({'tag': i[0], 'words': i[1]}) for i in self._y_pre_o: conclusion_list.append({'tag': i[0], 'words': i[1]}) else: for i in self._y_pre_o: finding_list.append({'tag': i[0], 'words': i[1]}) for i in self._y_pre: conclusion_list.append({'tag': i[0], 'words': i[1]}) return finding_list, conclusion_list, self.findind_replaced_word, self.conclusion_replaced_word, self.ImmunohistochemistryContent, self.MolecularResultsContent def print_list_item(self, l): for i in l: print(i) def get_json(self): if self.verbose: self.print_y_pred() print("-----------------") self.print_y_pred_o() print("-----------------") self.get_Info() return { "送检组织大小cm": str(self.max_size("组织")).strip(), "肿块大小": str(self.max_size("肿块")).strip(), "组织学类型": str(self.get_histological_type()).strip(), "其他组织学类型": str(self.get_other_type()).strip(), "分化程度": str(self.get_differentiation()).strip(), "浸润深度(DOI)mm": str(self.get_DOI()).strip(), "pT": str(self.get_pT()).strip(), "神经侵犯": str(self.get_invasion('神经')).strip(), "血管侵犯": str(self.get_invasion('血管')).strip(), "术后病理切缘": str(self.CuttingEdgePathology).strip(), "其他术后病理切缘情况": str(self.CuttingEdgePathologyOther).strip(), "黏膜上皮异常增生程度": str(self.Degree).strip(), "免疫组化": str(self.Immunohistochemistryisornot).strip(), "免疫组化结果": str(self.ImmunohistochemistryContent).strip(), "分子结果": str(self.MolecularResultsContent).strip(), "是否送检淋巴结": str(self.findSJ()).strip(), "送检淋巴结部位": str(self.getANATOMY()).strip() if str(self.findSJ()).strip() == '是' else '', "其他送检淋巴结部位": str(self.getANATOMY_o().strip('、')).strip() if str(self.findSJ()).strip() == '是' else '', "送检淋巴结数目": str(self.get_number()).strip() if str(self.findSJ()).strip() == '是' else '', "阳性淋巴结数目": str(self.get_p_number()).strip() if str(self.findSJ()).strip() == '是' else '', "阳性淋巴结最大直径cm": str(self.get_p_max()).strip() if str(self.findSJ()).strip() == '是' else '', "淋巴结包膜外ENE(+)": str(self.getENE()).strip() if str(self.findSJ()).strip() == '是' else '', "pN": str(self.get_pN()).strip() if str(self.findSJ()).strip() == '是' else '', } ## if __name__ == '__main__': Finding = """ "1、一带黏膜组织,1.8*0.8*0.5cm。灰黄。(2全)。 2、送检切缘:“前、后、左、右、底”均0.5cm。" """ Conclusion = """ "“右口底”黏膜上皮中-重度异常增生及瘤样增生,癌变为鳞状细胞癌,高-中分化,DOI:小于5mm。 送检切缘:“前、后、左、右、底”均阴性(-)。 南院免疫组化结果(I2021-3047):CKH(+),CK5/6(+),P16(-),Ki67(约30-40%+),CD31(-),S100(-),EGFR(+),P53(少量+)。" """ oral = Oral(Finding, Conclusion) oral.print_y_pred() print("-----------------") oral.print_y_pred_o() print("-----------------") oral.get_Info() # print(oral.get_json())