Commit 9ba70876 authored by 陶书衡's avatar 陶书衡

v1.1.0 stable

parent 94ed2394
......@@ -3,7 +3,7 @@ import copy
import requests
import uuid
from flask import Flask, request, redirect, url_for, render_template, flash, jsonify, Blueprint
from give_color import get_color
from model import Oral
oral_api = Blueprint('oral', __name__)
......@@ -38,7 +38,15 @@ def recognize():
print('' if verbose == 0 else 'verbose out:')
oral = Oral(finding, conclusion, verbose = False if verbose == 0 else 1)
data = oral.get_json()
return jsonify({'success': True, 'description': {'data': data}}), 200
finding_list, conclusion_list, findind_replaced_word, conclusion_replaced_word, ImmunohistochemistryContent, MolecularResultsContent = oral.get_entity()
color_finding = get_color(finding, finding_list, findind_replaced_word, ImmunohistochemistryContent,
MolecularResultsContent)
color_conclusion = get_color(conclusion, conclusion_list, conclusion_replaced_word,
ImmunohistochemistryContent, MolecularResultsContent)
return jsonify({'success': True,
'description': {'entity': data,
'color': {'finding': color_finding,
'conclusion': color_conclusion}}}), 200
except Exception as e:
print("/n******ERROR SRART******/n")
print(e)
......
##
from model import Oral
import re
##
Finding = """
左IV区淋巴结:1枚,直径2.5cm(1)
颏下:1枚,直径2cm(1)
左颊:部分上、下颌骨及颊部组织12*9*8cm,黏膜切面见一肿块6*3*2cm,灰白,界不清(1)
送检切缘:前内、前外、上内、上外、颊、翼内肌、翼外肌、腮腺、鼻底、鼻旁、鼻腔、软腭、舌根、颏突,均0.5cm
送检切缘:腮腺2,0.5cm
左颈大块:9*6*4cm,为肌肉、脂肪、血管,灰黄。
右颈大块:10*8*4cm,一侧见一腺体4*3*2cm,灰黄分叶,余为脂肪血管。
左I区: 1只直径1cm。
左II区: 2只直径0.5-1cm。
左III区: 4只直径0.8-1.3cm。
左IV区: 3只直径1.2-1.8cm。
左V区: 1只直径1cm。
右I区: 3只直径1-3.5cm。
右II区: 3只直径0.8-2cm。
右III区: 4只直径0.5-1cm。
右IV区: 4只直径0.5-1.2cm。
右V区: 2只直径0.5-0.8cm。
"""
Conclusion = """
“左颊”黏膜鳞状细胞癌,高-中分化,DOI>10mm
送检切缘:“腮腺”阳性(+)、“前内、前外、上内、上外、颊、翼内肌、翼外肌、鼻底、鼻旁、鼻腔、软腭、舌根、颏突、腮腺2”均阴性(-)
冰冻送检:“颏下淋巴结”1只内见鳞状细胞癌转移(+),侵犯至包膜外,“左IV区淋巴结”1只为软组织,伴出血
“左颈大块”为软组织、“右颌下腺”轻度慢性炎
送检淋巴结:“右I”1/3只有肿瘤转移(+),余及“左”“I”1只,“II”2只,“III”4只,“IV”3只,“V”1只,“右”“II”3只,“III”4只,“IV”4只,“V”2只均阴性(-)
免疫组化结果NI21-695
AE1/AE3+ CKH+ CK5/6+ EGFR部分+ Ki67部分+ CD31- S-100- P16-
北院分子结果(NM2021-0316):EGFR扩增探针 FISH(未见明显扩增(-))
"""
oral = Oral(Finding, Conclusion, verbose = False)
##
def get_color(text, entity_list, replaced_word, ImmunohistochemistryContent, MolecularResultsContent):
# print('replaced_word:', replaced_word)
# print(ImmunohistochemistryContent)
# print(MolecularResultsContent)
synonyms = []
for item in entity_list:
if item['tag'] == 'ANATOMY':
words_anatomy = item['words']
if item['words'] == 'I' or item['words'] == 'II' or item['words'] == 'III' or item['words'] == 'IV' or item[
'words'] == 'VI' or item['words'] == 'V' or item['words'] == '右' or item['words'] == '左':
words_anatomy = "“" + item['words'] + "”"
for i in re.finditer(
words_anatomy.replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
synonyms.append(i.span())
if item['tag'] == 'OTHER':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
synonyms.append(i.span())
negative = []
for i in re.finditer('无', text):
negative.append(i.span())
for i in re.finditer('未见', text):
negative.append(i.span())
for i in re.finditer('未发生', text):
negative.append(i.span())
numeracal = []
for item in entity_list:
if item['tag'] == 'NUMBER':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
numeracal.append(i.span())
if item['tag'] == 'SIZE':
# if item['words']=='12*9*8cm':
# print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
# print(text)
# for i in re.finditer(item['words'], text):
# print(i)
# print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
numeracal.append(i.span())
if item['tag'] == 'DOI':
if replaced_word == '':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'),
text):
numeracal.append(i.span())
else:
if item['words'] not in text:
if replaced_word == '大于':
doi_words = item['words'].replace(">", "大于")
elif replaced_word == '小于':
doi_words = item['words'].replace("<", "小于")
elif replaced_word == '大于等于':
doi_words = item['words'].replace("≥", "大于等于")
elif replaced_word == '小于等于':
doi_words = item['words'].replace("≤", "小于等于")
elif replaced_word == '>':
doi_words = item['words'].replace(">", ">")
elif replaced_word == '小于':
doi_words = item['words'].replace("<", "<")
for i in re.finditer(
doi_words.replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'),
text):
numeracal.append(i.span())
summary = []
for item in entity_list:
if item['tag'] == 'ENE':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
summary.append(i.span())
if item['tag'] == 'PN':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
summary.append(i.span())
classification = []
for item in entity_list:
if item['tag'] == 'LEVEL':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
classification.append(i.span())
other = []
for item in entity_list:
if item['tag'] == 'SQUAMOUS':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
other.append(i.span())
if item['tag'] == 'INVASION':
for i in re.finditer(
item['words'].replace('*', '\*').replace('(', '\(').replace(')', '\)').replace('+', '\+'), text):
other.append(i.span())
if ImmunohistochemistryContent != '':
for i in re.split('。| |\n', ImmunohistochemistryContent):
# print(i)
if i == "" or i == "\n":
continue
for j in re.finditer(i, text):
# print(j)
other.append(j.span())
if MolecularResultsContent != '':
for i in re.split('。| |\n', MolecularResultsContent):
# print(i)
if i == "" or i == "\n":
continue
for j in re.finditer(i, text):
# print(j)
other.append(j.span())
synonyms = list(set(synonyms))
negative = list(set(negative))
numeracal = list(set(numeracal))
summary = list(set(summary))
classification = list(set(classification))
other = list(set(other))
return {
'医学术语解析': other,
'同义词判断': synonyms,
'识别否定修饰词及其修饰对象': negative,
'数值解析': numeracal,
'对可归纳总结的信息进行解析后归纳判断': summary,
'对定义明确的分类变量进行赋值': classification
}
##
if __name__ == '__main__':
finding_list, conclusion_list, findind_replaced_word, conclusion_replaced_word, ImmunohistochemistryContent, MolecularResultsContent = oral.get_entity()
for i in finding_list:
print(i)
r1 = get_color(Finding, finding_list, findind_replaced_word, ImmunohistochemistryContent, MolecularResultsContent)
print("\n医学术语解析:")
for i in r1['医学术语解析']:
print(Finding[i[0]: i[1]], i[0], i[1])
print("\n同义词判断:")
for i in r1['同义词判断']:
print(Finding[i[0]: i[1]], i[0], i[1])
print("\n识别否定修饰词及其修饰对象:")
for i in r1['识别否定修饰词及其修饰对象']:
print(Finding[i[0]: i[1]], i[0], i[1])
print("\n数值解析:")
for i in r1['数值解析']:
print(Finding[i[0]: i[1]], i[0], i[1])
print("\n对可归纳总结的信息进行解析后归纳判断:")
for i in r1['对可归纳总结的信息进行解析后归纳判断']:
print(Finding[i[0]: i[1]], i[0], i[1])
print("\n对定义明确的分类变量进行赋值:")
for i in r1['对定义明确的分类变量进行赋值']:
print(Finding[i[0]: i[1]], i[0], i[1])
print("\n*****************************************\n")
for i in conclusion_list:
print(i)
r2 = get_color(Conclusion, conclusion_list, conclusion_replaced_word, ImmunohistochemistryContent,
MolecularResultsContent)
print("\n医学术语解析:")
for i in r2['医学术语解析']:
print(Conclusion[i[0]: i[1]], i[0], i[1])
print("\n同义词判断:")
for i in r2['同义词判断']:
print(Conclusion[i[0]: i[1]], i[0], i[1], )
print("\n识别否定修饰词及其修饰对象:")
for i in r2['识别否定修饰词及其修饰对象']:
print(Conclusion[i[0]: i[1]], i[0], i[1])
print("\n数值解析:")
for i in r2['数值解析']:
print(Conclusion[i[0]: i[1]], i[0], i[1])
print("\n对可归纳总结的信息进行解析后归纳判断:")
for i in r2['对可归纳总结的信息进行解析后归纳判断']:
print(Conclusion[i[0]: i[1]], i[0], i[1])
print("\n对定义明确的分类变量进行赋值:")
for i in r2['对定义明确的分类变量进行赋值']:
print(Conclusion[i[0]: i[1]], i[0], i[1])
# ##
# print(Conclusion[235:236])
# print(Conclusion[179:180])
# print(Conclusion[161:162])
......@@ -17,12 +17,39 @@ class Oral:
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(
......@@ -694,6 +721,21 @@ class Oral:
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)
......@@ -735,21 +777,15 @@ class Oral:
##
if __name__ == '__main__':
Finding = """
" 左颈大块:6*5*4cm,一侧见一腺体3*3*2cm,灰黄分叶,余为脂肪血管。
左I区: 3只直径0.2-1.2cm。
左II区: 3只直径0.5-1.2cm。
左III区: 3只直径0.5-1cm。
左IV区: 3只直径0.5-0.8cm。
右I区:3只直径1-2cm。
右II区: 3只直径1cm。
右III区: 3只直径0.5-0.8cm。
右IV区: 3只直径0.5-0.6cm。
右颈淋巴:7*7*6cm,內见一腺体3*3*2cm,灰黄分叶,余为脂肪血管。"
"1、一带黏膜组织,1.8*0.8*0.5cm。灰黄。(2全)。
2、送检切缘:“前、后、左、右、底”均0.5cm。"
"""
Conclusion = """
"“左颌下腺”慢性涎腺炎
“右颌下腺”慢性涎腺炎
送检淋巴结:“左”“I区”1/3只、“II区”1/3只、“III区”1/3只(肿瘤位于软组织内)及“右”“I区”2/3只(其中1只肿瘤侵犯至包膜外)、“II区”2/3只(肿瘤侵犯至包膜外)有肿瘤转移(+),余及“左IV区”3只、“右”“III区”3只、“IV区”3只均阴性(-)"
"“右口底”黏膜上皮中-重度异常增生及瘤样增生,癌变为鳞状细胞癌,高-中分化,DOI:小于5mm。
送检切缘:“前、后、左、右、底”均阴性(-)。
南院免疫组化结果(I2021-3047):CKH(+),CK5/6(+),P16(-),Ki67(约30-40%+),CD31(-),S100(-),EGFR(+),P53(少量+)。"
"""
oral = Oral(Finding, Conclusion)
......@@ -758,4 +794,4 @@ if __name__ == '__main__':
oral.print_y_pred_o()
print("-----------------")
oral.get_Info()
print(oral.get_json())
# print(oral.get_json())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment