|
|
|
|
@ -24,6 +24,7 @@ import org.jeecg.modules.ocr.utils.ImageUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.StrCharUtil;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.SimulateChecksVO;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -60,6 +61,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OcrIdentifyVo findById(String id) {
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = baseMapper.findById(id);
|
|
|
|
|
@ -156,6 +158,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
//==========================
|
|
|
|
|
//==========================
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
@ -175,7 +178,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
ocrArrayFor:
|
|
|
|
|
for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = null;
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
@ -186,16 +190,16 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没识别值
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@ -203,37 +207,37 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,null);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
|
//准确度 可靠
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -241,11 +245,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -372,8 +376,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
public void updateTaskResultInfo(String id) {
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId());
|
|
|
|
|
|
|
|
|
|
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
/*for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult());
|
|
|
|
|
String imgPath = identifyDetail.getImageUrl();
|
|
|
|
|
// 进行数据化 结构
|
|
|
|
|
@ -389,7 +392,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
//==========================
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
checkSemanticFor:
|
|
|
|
|
for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
@ -408,7 +412,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
ocrArrayFor:
|
|
|
|
|
for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = null;
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
@ -500,12 +505,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
identifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
|
ocrIdentifyDetailService.updateById(identifyDetail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
//=======规则检查配置
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
|
|
|
|
|
|
//===================
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
/*LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
@ -680,7 +683,21 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ocrResultAdd(List<OcrResult> ocrResultList,String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation,Double d) {
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param ocrResultList
|
|
|
|
|
* @param fieldName
|
|
|
|
|
* @param field
|
|
|
|
|
* @param inputText
|
|
|
|
|
* @param ocrText
|
|
|
|
|
* @param ocrPrecisionRate
|
|
|
|
|
* @param imgPath
|
|
|
|
|
* @param failureReason
|
|
|
|
|
* @param ruleValidation
|
|
|
|
|
* @param d
|
|
|
|
|
* @param ruleValidationValue 检查要求
|
|
|
|
|
*/
|
|
|
|
|
public static void ocrResultAdd(List<OcrResult> ocrResultList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d,String ruleValidationValue) {
|
|
|
|
|
OcrResult ocrResult = new OcrResult();
|
|
|
|
|
ocrResult.setTag(field);
|
|
|
|
|
ocrResult.setTagName(fieldName);
|
|
|
|
|
@ -707,6 +724,18 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrResultList = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
ocrResult.setRuleValidation(ruleValidation);
|
|
|
|
|
if ("0".equals(ruleValidationValue)) {
|
|
|
|
|
ocrResult.setRuleValidationText("有名称就算过");
|
|
|
|
|
}else if(Double.valueOf(ruleValidationValue)>0 &&Double.valueOf(ruleValidationValue)<=99){
|
|
|
|
|
ocrResult.setRuleValidationText("匹配度>="+ruleValidationValue);
|
|
|
|
|
}else if("100".equals(ruleValidation)){
|
|
|
|
|
ocrResult.setRuleValidationText("名称必须与参数完全一致");
|
|
|
|
|
}else if("101".equals(ruleValidationValue)){
|
|
|
|
|
ocrResult.setRuleValidationText("有值必须匹配无值算过");
|
|
|
|
|
}else if("isrule=1".equals(ruleValidationValue)){
|
|
|
|
|
ocrResult.setRuleValidationText("依据输入参数必须一致判断");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ocrResultList.add(ocrResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -721,11 +750,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
* @param imgPath
|
|
|
|
|
* @param failureReason
|
|
|
|
|
*/
|
|
|
|
|
public static void ocrResultAdd(List<OcrResult> ocrResultList,String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation) {
|
|
|
|
|
public static void ocrResultAdd(List<OcrResult> ocrResultList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation,String ruleValidationValue) {
|
|
|
|
|
if (ruleValidation) {
|
|
|
|
|
ocrResultAdd(ocrResultList,fieldName,field,inputText,ocrText,ocrPrecisionRate,imgPath,failureReason,ruleValidation,100d);
|
|
|
|
|
ocrResultAdd(ocrResultList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 100d,ruleValidationValue);
|
|
|
|
|
} else {
|
|
|
|
|
ocrResultAdd(ocrResultList,fieldName,field,inputText,ocrText,ocrPrecisionRate,imgPath,failureReason,ruleValidation,0d);
|
|
|
|
|
ocrResultAdd(ocrResultList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 0d,ruleValidationValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -882,6 +911,148 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void simulateChecks(SimulateChecksVO simulateChecksVO) {
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIds(simulateChecksVO.getIdentifyDetailIdList());
|
|
|
|
|
//遍历任务,做匹配
|
|
|
|
|
int i1=1;
|
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
|
if (i1==1) {
|
|
|
|
|
ocrIdentifyDetail.setSemanticResult("{\"ocr_res\":[[[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],[\"北京市朝阳区三里屯社区卫生服务中心\",0.9670220613479614]],[[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],[\"儿科专家门诊\",0.984556257724762]],[[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],[\"Pediatric srecialistclinic\",0.8756008148193359]]],\"其他\":[{\"area\":[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],\"end\":26,\"ocrText\":\"Pediatric srecialistclinic\",\"probability\":0.9925054592526585,\"start\":0,\"text\":\"Pediatric srecialistclinic\"}],\"医院名称\":[{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区三里屯社区卫生服务中心\",\"probability\":0.9681764264135495,\"start\":0,\"text\":\"北京市朝阳区三里屯社区卫生服务中心\"},{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区农光里医院\",\"probability\":0.95,\"start\":0,\"text\":\"北京市朝阳区农光里医院\"}],\"姓名\":[],\"时间\":[],\"科室\":[{\"area\":[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],\"end\":6,\"ocrText\":\"儿科专家门诊\",\"probability\":0.9836859327676066,\"start\":0,\"text\":\"儿科专家门诊\"}]}");
|
|
|
|
|
}
|
|
|
|
|
i1++;
|
|
|
|
|
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
|
|
|
|
|
String imgPath = ocrIdentifyDetail.getImageUrl();
|
|
|
|
|
if (StringUtils.isBlank(semanticResultJson)) continue;
|
|
|
|
|
String doctorName = simulateChecksVO.getDoctorName();
|
|
|
|
|
String hospitalName = simulateChecksVO.getHospitalName();
|
|
|
|
|
String departmentName = simulateChecksVO.getDepartmentName();
|
|
|
|
|
String time = simulateChecksVO.getTime();
|
|
|
|
|
List<JSONObject> sourceJson = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isNotBlank(doctorName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"doctorName\", \"inputText\":\"%s\"}", doctorName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(hospitalName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"hospitalName\", \"inputText\":\"%s\"}", hospitalName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(departmentName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"departmentName\", \"inputText\":\"%s\"}", departmentName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(time)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"time\", \"inputText\":\"%s\"}", time)));
|
|
|
|
|
}
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(semanticResultJson);
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson);
|
|
|
|
|
String text = null;//ocr 识别的文本
|
|
|
|
|
Double probability = 0d;
|
|
|
|
|
//用于数据结构化的对象
|
|
|
|
|
List<OcrResult> ocrResultList = new ArrayList<>();
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
//==========================
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
String inputText = value.getInputText();//校验文本 ,ocr识别的文本如果不包含该内容,则算作失败
|
|
|
|
|
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
|
|
|
|
|
text = null;
|
|
|
|
|
boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList()));
|
|
|
|
|
//查看ocr识别返回的字段名称中是否有当前这个字段名称
|
|
|
|
|
if (b) {
|
|
|
|
|
//TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
|
|
|
|
|
List<JSONObject> ocrArray = new ArrayList<>();
|
|
|
|
|
for (String s : fieldNameList) {
|
|
|
|
|
JSONArray jsonArray = semanticResult.getJSONArray(s);
|
|
|
|
|
if (jsonArray != null && jsonArray.size() > 0) {
|
|
|
|
|
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
ocrArrayFor:
|
|
|
|
|
for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = null;
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
log.info("ocrItem:");
|
|
|
|
|
log.info(ocrItem.toJSONString());
|
|
|
|
|
if ("101".equals(ruleInfo)) {
|
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没识别值
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,null);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
|
//准确度 可靠
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("----------------------");
|
|
|
|
|
for (OcrResult result : ocrResultList) {
|
|
|
|
|
System.out.println(result.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void executeTask() {
|
|
|
|
|
//获取任务
|
|
|
|
|
|