master
周文涛 2 years ago
parent 37f53be1b9
commit 69ce1ef405

@ -210,9 +210,9 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
public Result<String> edit(@RequestBody OcrIdentify ocrIdentify) {
AssertUtils.notEmpty(ocrIdentify.getId(), "[id]不可为空");
OcrIdentify identify = ocrIdentifyService.getById(ocrIdentify.getId());
if (Arrays.asList("0","1","2").contains(identify.getStatus())) {
/*if (Arrays.asList("0","1","2").contains(identify.getStatus())) {
throw new JeecgBootException("当前状态不可编辑");
}
}*/
ocrIdentifyService.updateById(ocrIdentify);
return Result.OK("编辑成功!");
}
@ -343,6 +343,18 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
return super.importExcel(request, response, OcrIdentify.class);
}
@ApiOperation(value = "重新执行")
@PostMapping(value = "/restartTask")
public Result<?> restartTask(@RequestBody OcrIdentify ocrIdentify){
AssertUtils.notEmpty(ocrIdentify.getId(), "[id]不可为空");
OcrIdentify identify = ocrIdentifyService.getById(ocrIdentify.getId());
if (!Arrays.asList("1","9").contains(identify.getStatus())) {
return Result.error("当前任务不可重新执行");
}
//TODO 重新执行操作
return Result.OK("已执行");
}
@ApiOperation(value = "上报通知给无量云")
@PostMapping(value = "/pushNotice")
public Result<?> pushNotice(@RequestBody OcrIdentify ocrIdentify){

@ -26,4 +26,7 @@ public class OcrResult {
private String failureReason;
@ApiModelProperty(value = "规则验证结果")
private Boolean ruleValidation=false;
@ApiModelProperty(value = "文本匹配度")
private Double textRate;
}

@ -18,6 +18,7 @@ import org.jeecg.modules.ocr.mapper.OcrIdentifyMapper;
import org.jeecg.modules.ocr.model.*;
import org.jeecg.modules.ocr.service.*;
import org.jeecg.modules.ocr.utils.ArrayOUtils;
import org.jeecg.modules.ocr.utils.StrCharUtil;
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
import org.springframework.scheduling.annotation.Async;
@ -154,13 +155,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
} else if ("0".equals(ruleInfo)) {
//必定验证参数,必须有值且匹配
double v = StrCharUtil.similarityRatio(inputText, text);
if (StringUtils.isBlank(inputText) || text.contains(inputText) || inputText.contains(text)) {
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
} else {
rMessage.append(value.getFieldName() + "不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false,v);
}
}
}
@ -364,13 +366,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
} else if ("0".equals(ruleInfo)) {
//必定验证参数,必须有值且匹配
double v = StrCharUtil.similarityRatio(inputText, text);
if (StringUtils.isBlank(inputText) || text.contains(inputText) || inputText.contains(text)) {
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
} else {
rMessage.append(value.getFieldName() + "_参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "_参数不匹配", false);
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "_参数不匹配", false,v);
}
}
}
@ -477,6 +480,27 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
super.update(updateWrapper);
}
public static void main(String[] args) {
int stringPercent = getStringPercent("张三", "张三脏");
System.out.println(stringPercent);
}
private static int getStringPercent(String text, String inputText) {
String[] inputTextSplit = inputText.split(".");
String[] textSplit = text.split(".");
int trueNum=0;
for (int i = 0; i < inputTextSplit.length; i++) {
if (textSplit.length>=i){
for (int p = 0; p < textSplit.length; p++) {
trueNum++;
}
}else{
break;
}
}
return 0;
}
@Override
public void callbackWly(String ocrIdentifyId){
OcrIdentifyCallbackLog ocrIdentifyCallbackLog=new OcrIdentifyCallbackLog();
@ -576,25 +600,18 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
}
}
/**
* OcrResult, ocrResultList
*
* @param ocrResultList
* @param field
* @param inputText
* @param ocrText
* @param ocrPrecisionRate
* @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,Double d) {
OcrResult ocrResult = new OcrResult();
ocrResult.setTag(field);
ocrResult.setTagName(fieldName);
ocrResult.setOcrText(ocrText);
ocrResult.setInputText(inputText);
ocrResult.setOcrPrecisionRate(ocrPrecisionRate == null ? 0d : ocrPrecisionRate);
if (d==null) {
ocrResult.setTextRate(0d);
}else{
ocrResult.setTextRate(new BigDecimal(d).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
}
System.out.println("-----------------");
System.out.println(failureReason);
System.out.println("-----------------");
@ -613,6 +630,25 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrResultList.add(ocrResult);
}
/**
* OcrResult, ocrResultList
*
* @param ocrResultList
* @param field
* @param inputText
* @param ocrText
* @param ocrPrecisionRate
* @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) {
if (ruleValidation) {
ocrResultAdd(ocrResultList,fieldName,field,inputText,ocrText,ocrPrecisionRate,imgPath,failureReason,ruleValidation,100d);
}else{
ocrResultAdd(ocrResultList,fieldName,field,inputText,ocrText,ocrPrecisionRate,imgPath,failureReason,ruleValidation,0d);
}
}
/**
* checkSemanticModelMap
*

@ -0,0 +1,182 @@
package org.jeecg.modules.ocr.utils;
import org.apache.commons.lang.StringUtils;
/**
* @Description
* @Author ZhouWenTao
* @Date 2023/8/11 13:50
*/
public class StrCharUtil {
/**
* ()
*
* @param strA
* @param strB
* @return
*/
public static String longestCommonSubstringNoOrder(String strA, String strB) {
if (strA.length() >= strB.length()) {
return longestCommonSubstring(strA, strB);
} else {
return longestCommonSubstring(strB, strA);
}
}
/**
*
*
* @param strLong
* @param strShort
* @return <p>summary</p>:
*/
private static String longestCommonSubstring(String strLong, String strShort) {
char[] chars_strA = strLong.toCharArray();
char[] chars_strB = strShort.toCharArray();
int m = chars_strA.length;
int n = chars_strB.length;
int[][] matrix = new int[m + 1][n + 1];
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (chars_strA[i - 1] == chars_strB[j - 1]) {
matrix[i][j] = matrix[i - 1][j - 1] + 1;
} else {
matrix[i][j] = Math.max(matrix[i][j - 1], matrix[i - 1][j]);
}
}
}
char[] result = new char[matrix[m][n]];
int currentIndex = result.length - 1;
while (matrix[m][n] != 0) {
if (matrix[n] == matrix[n - 1]) {
n--;
} else if (matrix[m][n] == matrix[m - 1][n]) {
m--;
} else {
result[currentIndex] = chars_strA[m - 1];
currentIndex--;
n--;
m--;
}
}
return new String(result);
}
private static boolean charReg(char charValue) {
return (charValue >= 0x4E00 && charValue <= 0X9FA5) || (charValue >= 'a' && charValue <= 'z') || (charValue >= 'A' && charValue <= 'Z') || (charValue >= '0' && charValue <= '9');
}
private static String removeSign(String str) {
StringBuffer sb = new StringBuffer();
for (char item : str.toCharArray()) {
if (charReg(item)) {
sb.append(item);
}
}
return sb.toString();
}
/**
*
* 1
* 2
*
* @param strA
* @param strB
* @return
*/
public static double SimilarDegree(String strA, String strB) {
String newStrA = removeSign(strA);
String newStrB = removeSign(strB);
int temp = Math.max(newStrA.length(), newStrB.length());
int temp2 = longestCommonSubstringNoOrder(newStrA, newStrB).length();
return temp2 * 1.0 / temp;
}
/**
* ()
*
* @param str
* @param target
* @return
*/
private static int compare(String str, String target) {
int d[][]; // 矩阵
int n = str.length();
int m = target.length();
int i; // 遍历str的
int j; // 遍历target的
char ch1; // str的
char ch2; // target的
int temp; // 记录相同字符,在某个矩阵位置值的增量,不是0就是1
if (n == 0) {
return m;
}
if (m == 0) {
return n;
}
d = new int[n + 1][m + 1];
// 初始化第一列
for (i = 0; i <= n; i++) {
d[i][0] = i;
}
// 初始化第一行
for (j = 0; j <= m; j++) {
d[0][j] = j;
}
// 遍历str
for (i = 1; i <= n; i++) {
ch1 = str.charAt(i - 1);
// 去匹配target
for (j = 1; j <= m; j++) {
ch2 = target.charAt(j - 1);
if (ch1 == ch2) {
temp = 0;
} else {
temp = 1;
}
// 左边+1,上边+1, 左上角+temp取最小
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + temp);
}
}
return d[n][m];
}
private static int min(int one, int two, int three) {
return (one = one < two ? one : two) < three ? one : three;
}
/**
*
* 1
* 2
*
* @param strA
* @param strB
* @return
*/
public static double similarityRatio(String strA, String strB) {
if (StringUtils.isBlank(strA)||StringUtils.isBlank(strB)) {
return 0;
}
double v = 1 - (double) compare(strA, strB) / Math.max(strA.length(), strB.length());
if (v<=1.0) {
v = v*100;
}
return v;
}
public static void main(String[] args) {
String strA = "河北唐山市协和医院";
String 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));
}
}
Loading…
Cancel
Save