|
|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package org.jeecg.modules.ocr.utils;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.xm.Similarity;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description 对比俩个字符串的相似度
|
|
|
|
|
@ -158,6 +161,9 @@ public class StrCharUtil {
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static double similarityRatio(String strA, String strB) {
|
|
|
|
|
double v = Similarity.charBasedSimilarity(strA, strB);
|
|
|
|
|
return new BigDecimal(v).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
|
/*System.out.println(word1 + " vs " + word2 + " 字面相似度值:" + charBasedSimilarityResult);
|
|
|
|
|
if (StringUtils.isBlank(strA)||StringUtils.isBlank(strB)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
@ -165,18 +171,18 @@ public class StrCharUtil {
|
|
|
|
|
if (v<=1.0) {
|
|
|
|
|
v = v*100;
|
|
|
|
|
}
|
|
|
|
|
return v;
|
|
|
|
|
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));
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|