提取数据(实验室检查)

news/发布时间2024/7/27 11:17:58

/**
* 实验室检查
*/
public class BeginPathology {
public static void main(String[] args) throws Exception {
try {

String folderPath = "C:\\Users\\kfeng5\\OneDrive - DXC Production\\Desktop\\年假工作";
File folder = new File(folderPath);
File[] files = folder.listFiles();

if (files != null) {
for (File file : files) {
if (file.getName().endsWith(".pdf")) {
PDDocument document = PDDocument.load(file);
PDFTextStripper stripper = new PDFTextStripper(); // 初始化文本剥离器
String text = stripper.getText(document);
String[] lines = text.split("\n");

boolean nameFlag = false;
boolean infoFlag = false;
boolean underFlag = false;
boolean numberFlag = false;
String name = null;
String type = null;
String[] split = null;
StringBuilder sb = new StringBuilder();
Map<String, String> hashMap = new HashMap<>();
for (String line : lines) {

Pattern compile0 = Pattern.compile("^\\d+(.*)");
Matcher matcher0 = compile0.matcher(line.trim());
if (matcher0.find()) {
if (StringUtils.isBlank(matcher0.group(1))) {
continue;//跳出此line
}
}

if (line.startsWith("附件")) {
nameFlag = true;
continue;
}

if (nameFlag) {
Pattern pattern = Pattern.compile("(.*)诊疗方案");
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
name = matcher.group(1);
nameFlag = false;
continue;
}
}

Pattern compile1 = Pattern.compile("(.*)、实验室检查");
Matcher matcher1 = compile1.matcher(line.trim());
if (matcher1.find()) {
infoFlag = true;
continue;//跳出此line
}
if(infoFlag){
if(line.length()>1){
if(line.charAt(1)=='、'){
System.out.println(name+"!"+type+"!"+sb.toString().replaceAll("\r",""));
infoFlag = false;
break;
}
}else {
System.out.println(name + "!" + "此行没有第二个字符,不能检测是否有顿号");
}

//TODO 当有以此开头的非目标内容时,会被按目标内容格式输出,所以数据异常,需调整
if (line.startsWith("(")) {
sb = getNewBuilder(sb, name, type);
//切割统一3位。得到(一)xxx检查 的xxx
type = line.substring(3).replaceAll("\r","");
underFlag = true;
continue;//跳出此line
}
if (underFlag) {
Pattern compile2 = Pattern.compile("^\\d\\.(.*)");
Matcher matcher2 = compile2.matcher(line.trim());
if(matcher2.find()){
sb = getNewBuilder(sb, name, type);
line = matcher2.group(1);
//split = matcher2.group(1).split(":", 2);
}
sb.append(line);
continue;
}
}
}
document.close();
}
}
}
}catch(Exception e){
throw new Exception(e);
}
}

//检测到标志,如果sb不为空,输出sb的内容
private static StringBuilder getNewBuilder(StringBuilder sb, String name, String type) {
if (sb.toString().length() != 0 && sb != null) {
System.out.println(name + "!" + type + "!" + sb.toString().replaceAll("\r", ""));
sb = new StringBuilder();
}
return sb;
}
}

取String类型的字符。对象.charAt(位)。
String对象类型内容的比较,用对象1.equals(对象2)方法。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.jwkm.cn/p/54165752.html

如若内容造成侵权/违法违规/事实不符,请联系宁远站长网进行投诉反馈email:xxxxxxxx@qq.com,一经查实,立即删除!

相关文章

mysql5.7安装教程

下载MySQL 或者使用刚才下载的 Mysql文件都行打开下载链接:https://dev.mysql.com/downloads/windows/installer/5.7.html 点击Download进行下载 弹出页面 点击No thanks进行下载下载下来的文件名是 mysql-installer-community-5.7.24.0.msi双击文件名称进行安装 如果提示如…

1对贝叶斯公式的思考

1:P(A)可以看成先验概率,不考虑B的影响,前面圈中的看成B事件对A的影响,A发生时B发生的概率与B的先验概率的比值,相同时比值为1,说明不影响 2:图书馆员和农民的例子,B是特征,A是农民,虽然特征符合较少,但总体基数大,即P(A)大 3:P(B)是分母,可以理解所有符合特质的…

力扣递归 深度优先搜索 之 104. 二叉树的最大深度

给定一个二叉树 root ,返回其最大深度。 二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。示例 1: 输入:root = [3,9,20,null,null,15,7] 输出:3示例 2: 输入:root = [1,null,2] 输出:2/*** Definition for a binary tree node.* public class Tre…

将他们分好队

这道题目非常好,是一道二分图染色的典型题目,记住 见这篇题解 然后说一种错误做法:求原图的SCC然后缩点讨论比如上图,其实是不能作为一个组的,因为第二个点其实并不认识第一个点(题目没有说有传递性)

记一次 Wireshark 无法抓包

问题描述 安装完 Wireshark 后提示没有权限,ChmodBPF 也安装了解决方案 终端运行以下代码 sudo launchctl enable system/org.wireshark.ChmodBPF sudo launchctl load /Library/LaunchDaemons/org.wireshark.ChmodBPF.plist

爬虫_052_爬虫相关概念介绍

目录爬虫的定义爬虫就是一个程序,程序运行完成之后,就能够拿到你想要获取的数据。爬虫的奥义就是程序模拟浏览器。爬虫的核心爬虫的难点在于:解析数据。爬虫的用途社交类:陌陌一开始爬微博数据当假的用户。电商类:电商网站互相监控,互相降价。出行类:智行、飞猪高频次访…