You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R中从以[report_complete]分隔的医疗文本提取结肠癌病例信息

提取含特定诊断的医疗病历片段的R脚本实现

需求说明

从以[report_complete]为分隔符的大型医疗病历文本中,提取包含结肠癌(已行活检)(对应原英文Colon cancer (biopsy done))诊断的完整患者病历片段(即两个[report_complete]之间的内容)。

示例数据

raw_text <- '[report_complete]
Name:
age:
sex:
Institution:
Date of Operation: 8/2/2015
Date of Accession: 8/2/2015
Reported: 8/5/2015 16:10
Results
FINAL DIAGNOSIS:
*RIGHT FOOT TRANSMETATARSAL AMPUTATION:
[report_complete]
Name:
age:
sex:
ANATOMIC PATHOLOGY
Date of Operation: 7/11/2015
Date of Accession: 7/11/2015
Reported: 7/14/2015
FINAL PATHOLOGIC DIAGNOSIS:
Colon cancer (biopsy done)
[report_complete]'

正确R实现脚本

# 加载stringr包
library(stringr)

# 将原始文本按分隔符分割为单个病历片段
reports <- str_split(raw_text, fixed("[report_complete]"), simplify = TRUE) %>%
  # 过滤掉空字符串和空白片段
  str_trim() %>%
  .[. != ""]

# 筛选包含目标诊断的病历片段
target_reports <- reports[str_detect(reports, fixed("Colon cancer (biopsy done)"))]

# 输出结果
print(target_reports)

脚本说明

  • 使用fixed()包裹分隔符和诊断文本,避免正则表达式转义问题,提升匹配准确性和效率
  • 分割后通过str_trim()和过滤空字符串,清理无效的空白片段
  • 用str_detect()精准匹配目标诊断内容,筛选出符合要求的病历

内容的提问来源于stack exchange,提问作者Vishal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 08:01:02