|
@@ -1257,35 +1257,52 @@ def extract_interpretation(full_text, indicator_name, pattern_type='nutrition'):
|
|
|
def extract_overall_assessment(full_text):
|
|
def extract_overall_assessment(full_text):
|
|
|
"""提取整体评估描述(P0)
|
|
"""提取整体评估描述(P0)
|
|
|
|
|
|
|
|
- 包括:肠道年龄评估、健康总分解读、菌群健康状况评估
|
|
|
|
|
|
|
+ 包括:健康总分解读、肠道年龄评估
|
|
|
"""
|
|
"""
|
|
|
assessments = {}
|
|
assessments = {}
|
|
|
|
|
|
|
|
- # 肠道年龄评估 - 找"肠道菌群与众多的健康问题息息相关"附近的内容
|
|
|
|
|
- for keyword in ['肠道菌群与众多的健康问题息息相关', '肠道菌群与健康问题']:
|
|
|
|
|
|
|
+ # 健康总分解读 - 找"健康总分\n总分说明"(page 11 详细解读,非首页概览)
|
|
|
|
|
+ for keyword in ['健康总分\n总分说明', '健康总分 总分说明', '总分说明']:
|
|
|
idx = full_text.find(keyword)
|
|
idx = full_text.find(keyword)
|
|
|
if idx != -1:
|
|
if idx != -1:
|
|
|
- end_markers = ['健康总分', '疾病风险评估', '主要消化道致病菌', '指标范围']
|
|
|
|
|
- end_pos = len(full_text)
|
|
|
|
|
- for m in end_markers:
|
|
|
|
|
- ei = full_text.find(m, idx)
|
|
|
|
|
- if ei != -1 and ei < end_pos:
|
|
|
|
|
- end_pos = ei
|
|
|
|
|
|
|
+ # 从"健康总分"开始(回退到"健康总分"的位置)
|
|
|
|
|
+ total_idx = full_text.rfind('健康总分', 0, idx + 50)
|
|
|
|
|
+ if total_idx != -1:
|
|
|
|
|
+ idx = total_idx
|
|
|
|
|
+ # 结束于"肠道年龄"(下一个大段)
|
|
|
|
|
+ end_pos = full_text.find('\n肠道年龄', idx)
|
|
|
|
|
+ if end_pos == -1:
|
|
|
|
|
+ end_pos = full_text.find('健康总分', idx + 50) # 避免找到同一处
|
|
|
|
|
+ if end_pos != -1:
|
|
|
|
|
+ pass # 使用这个 end_pos
|
|
|
|
|
+ else:
|
|
|
|
|
+ end_pos = idx + 2000
|
|
|
text = full_text[idx:end_pos].strip()
|
|
text = full_text[idx:end_pos].strip()
|
|
|
- text = re.sub(r'\d+/\d+', '', text).strip()[:500]
|
|
|
|
|
|
|
+ # 页码标记去除,保留内容
|
|
|
|
|
+ text = re.sub(r'\d+/\d+', '', text).strip()
|
|
|
if len(text) > 50:
|
|
if len(text) > 50:
|
|
|
- assessments['肠道年龄评估'] = text
|
|
|
|
|
|
|
+ assessments['健康总分解读'] = text
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
- # 健康总分解读
|
|
|
|
|
- idx = full_text.find('健康总分')
|
|
|
|
|
- if idx != -1:
|
|
|
|
|
- # 找"健康总分"后到"肠道菌群"之间的文本
|
|
|
|
|
- end_pos = idx + 800
|
|
|
|
|
- text = full_text[idx:end_pos].strip()
|
|
|
|
|
- text = re.sub(r'\d+/\d+', '', text).strip()[:300]
|
|
|
|
|
- if len(text) > 30:
|
|
|
|
|
- assessments['健康总分解读'] = text
|
|
|
|
|
|
|
+ # 肠道年龄评估:包含"肠道年龄"(page 12)+ "菌群评估"(pages 13-14)
|
|
|
|
|
+ # 起始:"肠道年龄\n真实年龄" 或 "肠道菌群与众多的健康问题息息相关"
|
|
|
|
|
+ start = full_text.find('肠道年龄\n真实年龄')
|
|
|
|
|
+ if start == -1:
|
|
|
|
|
+ start = full_text.find('肠道年龄\n真实年龄:')
|
|
|
|
|
+ if start == -1:
|
|
|
|
|
+ start = full_text.find('肠道菌群与众多的健康问题息息相关')
|
|
|
|
|
+ if start != -1:
|
|
|
|
|
+ # 结束于下一个大段 "菌群构成层级" 或 "菌群详细构成"
|
|
|
|
|
+ end_markers = ['\n菌群构成层级', '\n菌群详细构成', '\n菌群检出详细列表']
|
|
|
|
|
+ end_pos = len(full_text)
|
|
|
|
|
+ for m in end_markers:
|
|
|
|
|
+ ei = full_text.find(m, start)
|
|
|
|
|
+ if ei != -1 and ei < end_pos:
|
|
|
|
|
+ end_pos = ei
|
|
|
|
|
+ text = full_text[start:end_pos].strip()
|
|
|
|
|
+ text = re.sub(r'\d+/\d+', '', text).strip()
|
|
|
|
|
+ if len(text) > 50:
|
|
|
|
|
+ assessments['肠道年龄评估'] = text
|
|
|
|
|
|
|
|
return assessments
|
|
return assessments
|
|
|
|
|
|