或者,并且修改

devhuozheluoji
郭向斌 2 years ago
parent 1ed303f7c6
commit 569ba606d6

@ -17,8 +17,13 @@ public class OcrConstant {
*/ */
public static String ruleCheckSplitChar="&"; public static String ruleCheckSplitChar="&";
public static String ruleCheckOrChar="||"; public static String ruleHz="||";
public static String ruleZkh="\\(";
public static String ruleYkh="\\)";
public static String ruleDyh=">";
public static String ruleXyh="<";
public static String ruleTh="!";
public static String ruleBq="&&";
public static String ruleCheckValueRightChar="="; public static String ruleCheckValueRightChar="=";
/** /**

@ -237,13 +237,13 @@ public class RestUtil {
//回调接口 //回调接口
if (url.contains("callback")) { if (url.contains("callback")) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(30000); requestFactory.setConnectTimeout(300000);
requestFactory.setReadTimeout(30000); requestFactory.setReadTimeout(300000);
RT = new RestTemplate(requestFactory); RT = new RestTemplate(requestFactory);
}else{ }else{
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(300 *1000); requestFactory.setConnectTimeout(300 *10000);
requestFactory.setReadTimeout(300* 1000); requestFactory.setReadTimeout(300* 10000);
RT = new RestTemplate(requestFactory); RT = new RestTemplate(requestFactory);
} }
// 解决乱码问题 // 解决乱码问题

@ -9,8 +9,8 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>jeecg-system-biz</artifactId> <artifactId>jeecg-system-biz</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jeecgframework.boot</groupId> <groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-system-local-api</artifactId> <artifactId>jeecg-system-local-api</artifactId>
@ -45,7 +45,11 @@
<artifactId>thumbnailator</artifactId> <artifactId>thumbnailator</artifactId>
<version>0.4.8</version> <version>0.4.8</version>
</dependency> </dependency>
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>4.7.0-0</version>
</dependency>
<!--词义匹配导入本地maven--> <!--词义匹配导入本地maven-->
<!--https://github.com/shibing624/similarity--> <!--https://github.com/shibing624/similarity-->
<dependency> <dependency>
@ -53,6 +57,7 @@
<artifactId>similarity</artifactId> <artifactId>similarity</artifactId>
<version>1.1.6</version> <version>1.1.6</version>
</dependency> </dependency>
<!-- 积木报表 mongo redis 支持包 <!-- 积木报表 mongo redis 支持包
<dependency> <dependency>
<groupId>org.jeecgframework.jimureport</groupId> <groupId>org.jeecgframework.jimureport</groupId>

@ -24,6 +24,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -60,6 +61,7 @@ public class OcrSimulatorController{
List<String> imageList = images.toJavaList(String.class); List<String> imageList = images.toJavaList(String.class);
OcrIdentify ocrIdentify=new OcrIdentify(); OcrIdentify ocrIdentify=new OcrIdentify();
ocrIdentify.setTaskSource("模拟实验");//模拟实验-场景识别 ocrIdentify.setTaskSource("模拟实验");//模拟实验-场景识别
ocrIdentify.setTaskType(requestBody.getString("taskType"));
ocrIdentifyService.save(ocrIdentify); ocrIdentifyService.save(ocrIdentify);
List<OcrIdentifyDetail> ocrIdentifyDetailList=new ArrayList<>(); List<OcrIdentifyDetail> ocrIdentifyDetailList=new ArrayList<>();
double nluTimeSum=0d; double nluTimeSum=0d;
@ -77,6 +79,15 @@ public class OcrSimulatorController{
ocrIdentifyDetail.setImageUrl(uploadFilePath + "/" + image);//图片地址 ocrIdentifyDetail.setImageUrl(uploadFilePath + "/" + image);//图片地址
semanticRequestBody.put("img_path", uploadFilePath + "/" + image); semanticRequestBody.put("img_path", uploadFilePath + "/" + image);
} }
if(requestBody.getString("taskType")!=null&&requestBody.getString("taskType").equals("1699246961812586497")){
semanticRequestBody.put("scenes",1);
List<String> schema=new ArrayList<>();
schema.add("姓名");schema.add("年龄");schema.add("主要症状");schema.add("体征");schema.add("入院时主要症状和体征");
semanticRequestBody.put("schema",schema);
}else{
semanticRequestBody.put("scenes",0);
}
log.info("ocr识别模型请求参数{}",semanticRequestBody.toJSONString());
JSONObject semanticResponseJson = RestUtil.post(OcrConstant.api_test2_identify_url, semanticRequestBody); JSONObject semanticResponseJson = RestUtil.post(OcrConstant.api_test2_identify_url, semanticRequestBody);
//执行时间 调整小数点 //执行时间 调整小数点
Double nluTime = semanticResponseJson.getDouble("nlu_time"); Double nluTime = semanticResponseJson.getDouble("nlu_time");

@ -23,9 +23,9 @@ public class OcrRuleCheckDTO extends OcrRuleCheck {
@Excel(name = "元数据配置名称", width = 15) @Excel(name = "元数据配置名称", width = 15)
private String metadataConfigName; private String metadataConfigName;
private String configRuleAdapter; private String configRuleAdapter;
private Map<String,String> configRuleMap=new LinkedHashMap<>(); private Map<String,Object> configRuleMap=new LinkedHashMap<>();
private Map<String,String> fieldMap=new LinkedHashMap<>(); private Map<String,String> fieldMap=new LinkedHashMap<>();
Map<String,Map<String,String>> configRuleTypeMap=new LinkedHashMap<>(); Map<String,Map<String,Object>> configRuleTypeMap=new LinkedHashMap<>();
} }

@ -64,4 +64,7 @@ public class OcrRuleCheck implements Serializable {
@ApiModelProperty(value = "元数据配置id") @ApiModelProperty(value = "元数据配置id")
/*@Excel(name = "元数据配置id", width = 15)*/ /*@Excel(name = "元数据配置id", width = 15)*/
private String metadataConfigId; private String metadataConfigId;
@ApiModelProperty(value = "是否并且或者表达式1不是2是")
private Integer type;
} }

@ -355,7 +355,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
@Override @Override
@Async @Async
public void updateOcrIdentifyStatus(String id, String status) { public void updateOcrIdentifyStatus(String id, String status) {
log.info("id:{}",id);
//4.更新主任务状态 //4.更新主任务状态
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(OcrIdentify::getId, id); updateWrapper.eq(OcrIdentify::getId, id);
@ -412,7 +411,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id); OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
//=======规则检查配置 //=======规则检查配置
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo(); OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo();
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap(); Map<String, Map<String, Object>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
//=================== //===================
} }
@ -551,27 +550,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
* @param configRuleMap 1/0 map * @param configRuleMap 1/0 map
* @param fieldMap map * @param fieldMap map
*/ */
public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, String> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) { public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, Object> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) {
if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) { if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) {
//将 configRuleMap的 key 创建一个Set //缩写转全称
Set<String> keySet = new HashSet<>(configRuleMap.keySet()); OcrJudgmentTools.abbreviationToFullName(configRuleMap);
//循环keySet判断字段是否是缩写如果是缩写就把缩写的全称put一下
for (String s : keySet) {
String value = configRuleMap.get(s);
if ("hn".equals(s)) {
configRuleMap.put("hospitalName",value);
}else if("dn".equals(s)) {
configRuleMap.put("doctorName", value);
}else if("dmn".equals(s)) {
configRuleMap.put("departmentName", value);
}else if("tm".equals(s) || ("time".equals(s))) {
configRuleMap.put("time", value);
}else{
configRuleMap.put(s,value);
}
} }
}
Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>(); Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>();
//校验正确的值 //校验正确的值
Map<String, String> inputMap = new LinkedHashMap<>(); Map<String, String> inputMap = new LinkedHashMap<>();
@ -611,7 +594,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
copyEntity.setField(field); copyEntity.setField(field);
//1/0 //1/0
if (configRuleMap != null && configRuleMap.containsKey(field)) { if (configRuleMap != null && configRuleMap.containsKey(field)) {
configRule = configRuleMap.get(field); configRule =String.valueOf(configRuleMap.get(field));
copyEntity.setRuleInfo(configRule); copyEntity.setRuleInfo(configRule);
//端字段含义 //端字段含义
fieldName = fieldMap.get(field); fieldName = fieldMap.get(field);
@ -736,6 +719,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>(); List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
Date startDataCheckTime = new Date(); Date startDataCheckTime = new Date();
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
i1++; i1++;
String semanticResultJson = ocrIdentifyDetail.getSemanticResult(); String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
@ -785,11 +769,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath); ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
}*/ }*/
//============================绘制虚线 //============================绘制虚线
// JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
// String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
// //判断新目录是否存在,不存在则新建
// FileOUtils.folderCreate(fileUrl);
// String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result"); JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i); // String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
String fileUrl = imgPath.substring(0, i);
//判断新目录是否存在,不存在则新建 //判断新目录是否存在,不存在则新建
FileOUtils.folderCreate(fileUrl); FileOUtils.folderCreate(fileUrl);
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length()); String outputImagePath = fileUrl + "\\"+imgPath.substring(i + 1, imgPath.length());
if (semanticResult2!=null) { if (semanticResult2!=null) {
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2); List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
boolean hasPoints=true; boolean hasPoints=true;
@ -807,8 +797,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
//============================ //============================
} }
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson); Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson);
String text = null;//ocr 识别的文本 String text = null;//ocr 识别的文本
Double probability = 0d; Double probability = 0d;
@ -911,6 +899,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
} }
if (ocrArray.size() > 0) { if (ocrArray.size() > 0) {
if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){
for (JSONObject ocrItem : ocrArray) { for (JSONObject ocrItem : ocrArray) {
text = null; text = null;
text = ocrItem.getString("text");//ocr 识别的文本 text = ocrItem.getString("text");//ocr 识别的文本
@ -971,6 +960,62 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
} }
} }
} else if (ocrRuleCheckVo.getType()!= null&&ocrRuleCheckVo.getType()==2) {
for (JSONObject ocrItem : ocrArray) {
text = null;
text = ocrItem.getString("text");//ocr 识别的文本
probability = ocrItem.getDouble("probability");//置信度
if ("101".equals(ruleInfo)) {
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
//没识别值
mapPutIfTrue(fieldRightMap, field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true, ruleInfo);
} else {
double v = StrCharUtil.similarityRatio(inputText, text);
if (text.equals(inputText)) {
mapPutIfTrue(fieldRightMap, field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101");
} else {
rMessage.append(value.getFieldName()).append("参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo);
}
}
} else {
if (StringUtils.isBlank(text)) {
//ocr识别参数为空不通过
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
} else if (StringUtils.isBlank(inputText)) {
//没有输入值.
fieldRightMap.put(field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
} else if ("0".equals(ruleInfo)) {
//不必校验,有识别到就行,通过
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo);
} else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) {
//在1~99之间根据精准度匹配
double v = StrCharUtil.similarityRatio(inputText, text);
//准确度 可靠
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo);
} else if ("100".equals(ruleInfo)) {
//必定验证参数,必须有值且匹配
double v = StrCharUtil.similarityRatio(inputText, text);
if (text.equals(inputText)) {
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo);
} else {
rMessage.append(value.getFieldName()).append("参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo);
}
}
}
}
}
} else { } else {
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>"); rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
@ -1006,9 +1051,20 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
//没有匹配结果 //没有匹配结果
responseBody.put("taskResult",1); responseBody.put("taskResult",1);
}else{ }else{
if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){
long count = fieldRightMap.values().stream().filter(o->!o).count(); long count = fieldRightMap.values().stream().filter(o->!o).count();
//long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count(); //long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count();
responseBody.put("taskResult",count>0?0:1);//匹配成功或失败 responseBody.put("taskResult",count>0?0:1);//匹配成功或失败
}else if(ocrRuleCheckVo.getType()!=null&&ocrRuleCheckVo.getType()==2){
log.info(ocrResultDTOList.toString());
String configRule = ocrRuleCheckVo.getConfigRule();
Map<String,Object> params=new HashMap<>();
for(OcrResultDTO ocrResultDTO:ocrResultDTOList){
params.put(ocrResultDTO.getTag(),ocrResultDTO.getTextRate());
}
Boolean rest=OcrJudgmentTools.judment(configRule,params);
responseBody.put("taskResult",rest?0:1);
}
Set<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet()); Set<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet());
List<OcrResultDTO> newResultDTOList=new ArrayList<>(); List<OcrResultDTO> newResultDTOList=new ArrayList<>();
//过滤掉0的值 //过滤掉0的值
@ -1136,10 +1192,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
}*/ }*/
//============================绘制虚线 //============================绘制虚线
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result"); JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i); // String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
String fileUrl = imgPath.substring(0, i);
//判断新目录是否存在,不存在则新建 //判断新目录是否存在,不存在则新建
FileOUtils.folderCreate(fileUrl); FileOUtils.folderCreate(fileUrl);
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length()); String outputImagePath = fileUrl + "\\"+imgPath.substring(i + 1, imgPath.length());
if (semanticResult2!=null) { if (semanticResult2!=null) {
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2); List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
boolean hasPoints=true; boolean hasPoints=true;

@ -18,6 +18,8 @@ import org.jeecg.modules.ocr.mapper.OcrMetadataConfigMapper;
import org.jeecg.modules.ocr.mapper.OcrRuleCheckMapper; import org.jeecg.modules.ocr.mapper.OcrRuleCheckMapper;
import org.jeecg.modules.ocr.service.IOcrRuleCheckDetailService; import org.jeecg.modules.ocr.service.IOcrRuleCheckDetailService;
import org.jeecg.modules.ocr.service.IOcrRuleCheckService; import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
import org.jeecg.modules.ocr.utils.OcrJudgmentTools;
import org.jeecg.modules.ocr.utils.StrCharUtil;
import org.jeecg.modules.ocr.vo.SaveOcrRuleCheckVO; import org.jeecg.modules.ocr.vo.SaveOcrRuleCheckVO;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -39,10 +41,6 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, OcrRuleCheck> implements IOcrRuleCheckService { public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, OcrRuleCheck> implements IOcrRuleCheckService {
@Resource
IOcrRuleCheckDetailService ocrRuleCheckDetailService;
@Resource
OcrMetadataConfigMapper ocrMetadataConfigMapper;
@Resource @Resource
OcrMetadataConfigDetailMapper ocrMetadataConfigDetailMapper; OcrMetadataConfigDetailMapper ocrMetadataConfigDetailMapper;
@Override @Override
@ -62,14 +60,31 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
public void saveModelBatch(List<SaveOcrRuleCheckVO> saveOcrRuleCheckVOS) { public void saveModelBatch(List<SaveOcrRuleCheckVO> saveOcrRuleCheckVOS) {
for (SaveOcrRuleCheckVO saveOcrRuleCheckVO : saveOcrRuleCheckVOS) { for (SaveOcrRuleCheckVO saveOcrRuleCheckVO : saveOcrRuleCheckVOS) {
OcrRuleCheck ocrRuleCheck=new OcrRuleCheck(); OcrRuleCheck ocrRuleCheck=new OcrRuleCheck();
if(saveOcrRuleCheckVO.getType()==null||saveOcrRuleCheckVO.getType()==1){
if (StringUtils.isNotBlank(saveOcrRuleCheckVO.getConfigRule())) { if (StringUtils.isNotBlank(saveOcrRuleCheckVO.getConfigRule())) {
if (saveOcrRuleCheckVO.getConfigRule().contains("isrule=1") && saveOcrRuleCheckVO.getConfigRule().replace("isrule=1","").length()>0) { if (saveOcrRuleCheckVO.getConfigRule().contains("isrule=1") && saveOcrRuleCheckVO.getConfigRule().replace("isrule=1","").length()>0) {
throw new JeecgBootException("isrule=1规则只可单独使用"); throw new JeecgBootException("isrule=1规则只可单独使用");
} }
} }
saveOcrRuleCheckVO.setType(1);
}else if(saveOcrRuleCheckVO.getType()==2){
String configRule = saveOcrRuleCheckVO.getConfigRule();
String metadataConfigId = saveOcrRuleCheckVO.getMetadataConfigId();
//获取规则配置元字段
List<OcrMetadataConfigDetail> ocrMetadataConfigDetails = ocrMetadataConfigDetailMapper.selectList(new LambdaQueryWrapper<OcrMetadataConfigDetail>().eq(OcrMetadataConfigDetail::getMetadataConfigId, metadataConfigId));
Map<String,Object> params=new HashMap<>();
for(OcrMetadataConfigDetail configDetail:ocrMetadataConfigDetails){
String fieldName = configDetail.getFieldName();
params.put(fieldName,1);
}
OcrJudgmentTools.fullNameToAbbreviation(params);
//做下表达式校验,看表达式是否正确,如果不正确这个方法里面会抛出异常如果正确就继续入库
OcrJudgmentTools.judment(configRule, params);
}
ocrRuleCheck.setConfigRule(saveOcrRuleCheckVO.getConfigRule()); ocrRuleCheck.setConfigRule(saveOcrRuleCheckVO.getConfigRule());
ocrRuleCheck.setMetadataConfigId(saveOcrRuleCheckVO.getMetadataConfigId()); ocrRuleCheck.setMetadataConfigId(saveOcrRuleCheckVO.getMetadataConfigId());
ocrRuleCheck.setConfigName(saveOcrRuleCheckVO.getConfigName()); ocrRuleCheck.setConfigName(saveOcrRuleCheckVO.getConfigName());
ocrRuleCheck.setType(saveOcrRuleCheckVO.getType());
this.save(ocrRuleCheck); this.save(ocrRuleCheck);
} }
} }
@ -333,13 +348,14 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
OcrRuleCheckDTO ocrRuleCheckVo = baseMapper.findById(id); OcrRuleCheckDTO ocrRuleCheckVo = baseMapper.findById(id);
AssertUtils.notNull(ocrRuleCheckVo,id+"-规则检查配置不存在"); AssertUtils.notNull(ocrRuleCheckVo,id+"-规则检查配置不存在");
if (StringUtils.isNotBlank(ocrRuleCheckVo.getConfigRule())) { if (StringUtils.isNotBlank(ocrRuleCheckVo.getConfigRule())) {
if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){
String configRule = ocrRuleCheckVo.getConfigRule(); String configRule = ocrRuleCheckVo.getConfigRule();
//TODO {key(&,||):{key(字段):value(1/0)}} //TODO {key(&,||):{key(字段):value(1/0)}}
Map<String,Map<String,String>> configRuleTypeMap=new LinkedHashMap<>(); Map<String,Map<String,Object>> configRuleTypeMap=new LinkedHashMap<>();
if (configRule.contains(OcrConstant.ruleCheckOrChar)) { if (configRule.contains(OcrConstant.ruleHz)) {
// || // ||
String[] orSplit = configRule.split(OcrConstant.ruleCheckOrChar); String[] orSplit = configRule.split(OcrConstant.ruleHz);
Map<String,String> configRuleMap=new LinkedHashMap<>(); Map<String,Object> configRuleMap=new LinkedHashMap<>();
String field=null;String fieldValue=null; String field=null;String fieldValue=null;
for (String s : orSplit) { for (String s : orSplit) {
configRuleMap=new LinkedHashMap<>(); configRuleMap=new LinkedHashMap<>();
@ -349,12 +365,12 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
} }
configRuleMap.put(split1[0],split1[1]); configRuleMap.put(split1[0],split1[1]);
} }
configRuleTypeMap.put(OcrConstant.ruleCheckOrChar,configRuleMap); configRuleTypeMap.put(OcrConstant.ruleHz,configRuleMap);
}else { }else {
//& //&
String[] split = configRule.split(OcrConstant.ruleCheckSplitChar); String[] split = configRule.split(OcrConstant.ruleCheckSplitChar);
//将 `配置规则` 转成 map //将 `配置规则` 转成 map
Map<String,String> configRuleMap=new LinkedHashMap<>(); Map<String,Object> configRuleMap=new LinkedHashMap<>();
for (String s : split) { for (String s : split) {
String[] split1 = s.split(OcrConstant.ruleCheckValueRightChar); String[] split1 = s.split(OcrConstant.ruleCheckValueRightChar);
if (split1.length<=1) { if (split1.length<=1) {
@ -366,6 +382,11 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
configRuleTypeMap.put(OcrConstant.ruleCheckSplitChar,configRuleMap); configRuleTypeMap.put(OcrConstant.ruleCheckSplitChar,configRuleMap);
} }
ocrRuleCheckVo.setConfigRuleTypeMap(configRuleTypeMap); ocrRuleCheckVo.setConfigRuleTypeMap(configRuleTypeMap);
}else if(ocrRuleCheckVo.getType()!=null||ocrRuleCheckVo.getType()==2){
String configRule = ocrRuleCheckVo.getConfigRule();
Map<String,Object> restMap= StrCharUtil.strSplits(configRule);
ocrRuleCheckVo.setConfigRuleMap(restMap);
}
} }
if (StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) { if (StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
String metadataConfigId = ocrRuleCheckVo.getMetadataConfigId(); String metadataConfigId = ocrRuleCheckVo.getMetadataConfigId();
@ -379,4 +400,5 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl<OcrRuleCheckMapper, Ocr
return ocrRuleCheckVo; return ocrRuleCheckVo;
} }
} }

@ -27,26 +27,45 @@ public class ImageUtils {
Java使ImageIOThumbnailsJava Advanced Imaging APIJAI使ImageIO Java使ImageIOThumbnailsJava Advanced Imaging APIJAI使ImageIO
*/ */
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
String sourceImagePath = "C:\\Users\\Denim\\Desktop\\aabebdf71887c6c2707c65211cac2d3a.jpeg"; // String sourceImagePath = "C:\\Users\\Denim\\Desktop\\aabebdf71887c6c2707c65211cac2d3a.jpeg";
String outputImagePath = "C:\\Users\\Denim\\Desktop\\ds-aabebdf71887c6c2707c65211cac2d3a.jpeg"; // String outputImagePath = "C:\\Users\\Denim\\Desktop\\ds-aabebdf71887c6c2707c65211cac2d3a.jpeg";
//compressImage(sourceImagePath,outputImagePath,0.25f,0.25f); // //compressImage(sourceImagePath,outputImagePath,0.25f,0.25f);
List<Point> points = new ArrayList<>(); // List<Point> points = new ArrayList<>();
points.add(new Point(9, 2924)); // points.add(new Point(9, 2924));
points.add(new Point(107, 2924)); // points.add(new Point(107, 2924));
points.add(new Point(107, 2959)); // points.add(new Point(107, 2959));
points.add(new Point(9, 2959)); // points.add(new Point(9, 2959));
List<Point> points2 = new ArrayList<>(); // List<Point> points2 = new ArrayList<>();
points2.add(new Point(1282, 1576)); // points2.add(new Point(1282, 1576));
points2.add(new Point(2764, 1594)); // points2.add(new Point(2764, 1594));
points2.add(new Point(2763, 1671)); // points2.add(new Point(2763, 1671));
points2.add(new Point(1281, 1653)); // points2.add(new Point(1281, 1653));
List<List<Point>> pointList = new ArrayList<>(); // List<List<Point>> pointList = new ArrayList<>();
pointList.add(points); // pointList.add(points);
pointList.add(points2); // pointList.add(points2);
//drawDashedRectangleOnImages("http://47.103.213.109:8072/files/nfs/ocr/shared_directory/fdd50089f33e4b4391b8c88b6299735b/a86aff69fc3ff5397d038b4dbcde6165.jpeg", pointList, "C:\\Users\\Denim\\Desktop\\output_image.png","red"); // //drawDashedRectangleOnImages("http://47.103.213.109:8072/files/nfs/ocr/shared_directory/fdd50089f33e4b4391b8c88b6299735b/a86aff69fc3ff5397d038b4dbcde6165.jpeg", pointList, "C:\\Users\\Denim\\Desktop\\output_image.png","red");
drawDashedRectangleOnImages(sourceImagePath, pointList, "C:\\Users\\Denim\\Desktop\\output_image.png","green"); // drawDashedRectangleOnImages(sourceImagePath, pointList, "C:\\Users\\Denim\\Desktop\\output_image.png","green");
String sourceImagePath = "D:\\workspace\\ocr\\data\\upFiles\\医院名称识别不到_1697812202041.png";
try {
BufferedImage originalImage = ImageIO.read(new File(sourceImagePath));
// 设置放大后的图片尺寸
int newWidth = originalImage.getWidth() * 3;
int newHeight = originalImage.getHeight() * 3;
BufferedImage bufferedImage = zoomImage(originalImage, newWidth, newHeight);
ImageIO.write(bufferedImage, "png", new File("D:\\workspace\\ocr\\data\\医院名称识别不到_1697812202041.png"));
System.out.println("图片放大成功!");
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
public static BufferedImage zoomImage(BufferedImage originalImage, int newWidth, int newHeight) {
BufferedImage zoomedImage = new BufferedImage(newWidth, newHeight, originalImage.getType());
Graphics2D g = zoomedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
return zoomedImage;
}
/** /**
* *
* *

@ -0,0 +1,93 @@
package org.jeecg.modules.ocr.utils;
import org.jeecg.common.exception.JeecgBootException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @Title:
* @Description:
* @Author
* @Date 2023-10-13 17:47
* @Version V1.0
*/
public class OcrJudgmentTools {
public static void main(String[] args) {
Map<String,Object> engine =new HashMap<>();
String str="value>5&&st==\"test\"&&(state==\"正常\"||state==\"不正常\")";
engine.put("value",6);
engine.put("state","正常");
engine.put("st","test");
Boolean judment = judment(str, engine);
System.out.println(judment);
}
public static ScriptEngine getEngine(){
ScriptEngineManager manager=new ScriptEngineManager();
return manager.getEngineByName("nashorn");
}
public static Boolean judment(String expression, Map<String,Object> params){
Boolean eval=false;
ScriptEngine engine = getEngine();
for(String key:params.keySet()){
engine.put(key,params.get(key));
}
try {
eval =(Boolean) engine.eval(expression);
} catch (ScriptException e) {
throw new JeecgBootException("条件表达式配置错误请检查");
}
return eval;
}
/***
*
* @return
*/
public static void abbreviationToFullName(Map<String, Object> configRuleMap){
Set<String> keySet = new HashSet<>(configRuleMap.keySet());
//循环keySet判断字段是否是缩写如果是缩写就把缩写的全称put一下
for (String s : keySet) {
Object value = configRuleMap.get(s);
if ("hn".equals(s)) {
configRuleMap.put("hospitalName",value);
}else if("dn".equals(s)) {
configRuleMap.put("doctorName", value);
}else if("dmn".equals(s)) {
configRuleMap.put("departmentName", value);
}else if("tm".equals(s) || ("time".equals(s))) {
configRuleMap.put("time", value);
}else{
configRuleMap.put(s,value);
}
}
}
/***
*
* @return
*/
public static void fullNameToAbbreviation(Map<String, Object> configRuleMap){
Set<String> keySet = new HashSet<>(configRuleMap.keySet());
//循环keySet判断字段是否是缩写如果是缩写就把缩写的全称put一下
for (String s : keySet) {
Object value = configRuleMap.get(s);
if ("hospitalName".equals(s)) {
configRuleMap.put("hn",value);
}else if("doctorName".equals(s)) {
configRuleMap.put("dn", value);
}else if("departmentName".equals(s)) {
configRuleMap.put("dmn", value);
}else if("tm".equals(s) || ("time".equals(s))) {
configRuleMap.put("time", value);
}else{
configRuleMap.put(s,value);
}
}
}
}

@ -1,8 +1,13 @@
package org.jeecg.modules.ocr.utils; package org.jeecg.modules.ocr.utils;
import org.jeecg.common.constant.OcrConstant;
import org.xm.Similarity; import org.xm.Similarity;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Description * @Description
@ -10,6 +15,67 @@ import java.math.BigDecimal;
* @Date 2023/8/11 13:50 * @Date 2023/8/11 13:50
*/ */
public class StrCharUtil { public class StrCharUtil {
public static void main(String[] args) {
String configRule="hospitalName>=40&&(departmentName==0||doctorName==0)";
Map<String, Object> stringObjectMap = strSplits(configRule);
}
/**
*
*/
public static Map<String,Object> strSplits(String configRule){
//去除不需要的字符如 括号,叹号
configRule=configRule.replaceAll(" ","").replaceAll(OcrConstant.ruleZkh,"").replaceAll(OcrConstant.ruleYkh,"");
if(configRule.contains(OcrConstant.ruleTh+OcrConstant.ruleCheckValueRightChar)){
configRule=configRule.replaceAll(OcrConstant.ruleTh+OcrConstant.ruleCheckValueRightChar,"~"+OcrConstant.ruleCheckValueRightChar);//如果有!=那就替换为b=
}else{
configRule=configRule.replaceAll(OcrConstant.ruleTh,"");
}
if(configRule.contains(OcrConstant.ruleDyh+OcrConstant.ruleCheckValueRightChar)){
configRule=configRule.replaceAll(OcrConstant.ruleDyh+OcrConstant.ruleCheckValueRightChar,"dydy");
}
if(configRule.contains(OcrConstant.ruleDyh+OcrConstant.ruleCheckValueRightChar)){
configRule=configRule.replaceAll(OcrConstant.ruleXyh+OcrConstant.ruleCheckValueRightChar,"xydy");
}
//切割符组装 放入list中
List<String> splits=new ArrayList<>();
splits.add(OcrConstant.ruleDyh);
splits.add(OcrConstant.ruleXyh);
splits.add("xydy");
splits.add("dydy");
splits.add(OcrConstant.ruleCheckValueRightChar+OcrConstant.ruleCheckValueRightChar);
splits.add("~"+OcrConstant.ruleCheckValueRightChar);
if(configRule.contains(OcrConstant.ruleHz)){
configRule=configRule.replaceAll("\\|\\|",OcrConstant.ruleBq);
}
String[] strs = configRule.split(OcrConstant.ruleBq);
Map<String,Object> map=new HashMap<>();
for(String strss:strs){
strSplits(strss,splits,map);
}
return map;
}
public static void strSplits(String strs, List<String> splits,Map<String,Object> rest){
for(String split:splits){
if(strs.contains(split)){
String[] split1 = strs.split(split);
boolean sdf=false;
for(String s:split1){
for(String sf:splits){
if(!s.contains(sf)){
sdf=true;
}
}
}
if(sdf){
rest.put(split1[0],split1[1]);
}else{
for(String str22:split1){
strSplits(str22,splits,rest);
}
}
}
}
}
/** /**
* () * ()
@ -176,15 +242,4 @@ public class StrCharUtil {
return v;*/ return v;*/
} }
public static void main(String[] args) {
String strA = "河北唐山市协和医院";
String strB = "河北省唐山协和医院";
System.out.println(similarityRatio(strA,strB));
//System.out.println(longestCommonSubstringNoOrder(strA, strB));
//System.out.println(SimilarDegree(strA, strB));
//System.out.println(compare(strA, strB));
//System.out.println(similarityRatio(strA, strB));
}
} }

@ -37,6 +37,9 @@ public class SaveOcrRuleCheckVO implements Serializable {
@ApiModelProperty(value = "元数据配置名称") @ApiModelProperty(value = "元数据配置名称")
@Excel(name = "元数据配置名称", width = 15) @Excel(name = "元数据配置名称", width = 15)
private String metadataConfigName; private String metadataConfigName;
@ApiModelProperty(value = "并且或者组合规则,1不是2是")
@Excel(name = "是否为并且或者组合规则", width = 15)
private Integer type;
/**选择的元数据明细id*/ /**选择的元数据明细id*/
//@ApiModelProperty(value = "选择的元数据明细id") //@ApiModelProperty(value = "选择的元数据明细id")
//public List<String> metadataConfigDetailIdList=new ArrayList<>(); //public List<String> metadataConfigDetailIdList=new ArrayList<>();

@ -131,13 +131,13 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource: datasource:
master: master:
url: jdbc:mysql://47.103.213.109:3306/ocr?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai # url: jdbc:mysql://47.103.213.109:3306/ocr?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: Wang5322570..
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: root # username: root
# password: root # password: Wang5322570..
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/ocr?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: root
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
# 多数据源配置 # 多数据源配置
#multi-datasource1: #multi-datasource1:
@ -148,9 +148,13 @@ spring:
#redis 配置 #redis 配置
redis: redis:
database: 3 database: 3
host: 47.103.213.109 host: 127.0.0.1
port: 6379 port: 6379
password: '' password: ''
#tess4j
tess4j:
data-path: D:\workspace\ocr\data\tess4jdata
language: chi_sim
#mybatis plus 设置 #mybatis plus 设置
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml
@ -185,9 +189,9 @@ jeecg:
app: http://localhost:8051 app: http://localhost:8051
path: path:
#文件上传根目录 设置 #文件上传根目录 设置
upload: /data/ocr/upFiles upload: D:\workspace\ocr\data\upFiles
#webapp文件路径 #webapp文件路径
webapp: /opt/webapp webapp: D://opt/webapp
shiro: shiro:
excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/** excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**
#阿里云oss存储和大鱼短信秘钥配置 #阿里云oss存储和大鱼短信秘钥配置
@ -299,5 +303,6 @@ third-app:
system: system:
project: project:
env: customer_test env: customer_test
enableHandleTask: false enableHandleTask: true
fileReviewUrlPrefix: http://47.103.213.109:8072/files fileReviewUrlPrefix: http://localhost:8071/files
wlyCallback: https://hyycsozs.prevailcloud.com/api/task/image/ocr/callback

@ -3,4 +3,4 @@ spring:
name: jeecg-system name: jeecg-system
profiles: profiles:
# active: '@profile.name@' # active: '@profile.name@'
active: prod active: dev
Loading…
Cancel
Save