fix(文档对比): 相同纯img标签对比不一致问题
This commit is contained in:
+15
-1
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -161,7 +162,20 @@ public class SarFileCompareInfoServiceImpl extends ServiceImpl<SarFileCompareInf
|
||||
}
|
||||
String rightTxt = rightItemList.get(j).getItemsText();
|
||||
if (null != rightTxt && !rightTxt.isEmpty()) {
|
||||
double similarity = CompHanLPUtils.findSimilarity(leftTxt.trim(), rightTxt.trim());
|
||||
double similarity = 0;
|
||||
// 使用正则表达式判断是否是纯<img>标签,不以</p>结尾,也不以</table>结尾
|
||||
String leftTxtTrim = leftTxt.trim();
|
||||
String rightTxtTrim = rightTxt.trim();
|
||||
boolean leftTxtMatches = Pattern.matches("<img[^>]+>(?<!</p>)(?<!</table>)", leftTxtTrim);
|
||||
boolean rightTxtMatches = Pattern.matches("<img[^>]+>(?<!</p>)(?<!</table>)", rightTxtTrim);
|
||||
if (leftTxtMatches && rightTxtMatches){
|
||||
// 如果是纯img标签直接对比内容
|
||||
if (leftTxtTrim.equals(rightTxtTrim)){
|
||||
similarity = 1;
|
||||
}
|
||||
}else {
|
||||
similarity = CompHanLPUtils.findSimilarity(leftTxt.trim(), rightTxt.trim());
|
||||
}
|
||||
//如果相似度超过0.6 并且该相似度比之前的相似度还高,那么该条款目前相似度最高
|
||||
if (similarity >= 0.6 && compareSimilarity < similarity) {
|
||||
compareSimilarity = similarity;
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.wltea.analyzer.core.Lexeme;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user