mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-07 22:27:59 +08:00
fix bug
This commit is contained in:
parent
21881a1609
commit
db20737abb
@ -20,7 +20,8 @@
|
|||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复NumberUtil.mul中null的结果错误问题(issue#I17Y4J@Gitee)
|
* 【core 】 修复NumberUtil.mul中null的结果错误问题(issue#I17Y4J@Gitee)
|
||||||
* 【core 】 修复当金额大于等于1亿时,转换会多出一个万字的bug(pr#715@Github)
|
* 【core 】 修复当金额大于等于1亿时,转换会多出一个万字的bug(pr#715@Github)
|
||||||
* 【core 】 修复FileUtil.listFileNames位于jar内导致的文件找不到问题(issue#listFileNames@Gitee)
|
* 【core 】 修复FileUtil.listFileNames位于jar内导致的文件找不到问题
|
||||||
|
* 【core 】 修复TextSimilarity.similar去除字符导致的问题(issue#I17K2A@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ public class TextSimilarity {
|
|||||||
newStrA = removeSign(strA);
|
newStrA = removeSign(strA);
|
||||||
newStrB = removeSign(strB);
|
newStrB = removeSign(strB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用较大的字符串长度作为分母,相似子串作为分子计算出字串相似度
|
// 用较大的字符串长度作为分母,相似子串作为分子计算出字串相似度
|
||||||
int temp = Math.max(newStrA.length(), newStrB.length());
|
int temp = Math.max(newStrA.length(), newStrB.length());
|
||||||
if(0 == temp) {
|
if(0 == temp) {
|
||||||
@ -65,7 +66,7 @@ public class TextSimilarity {
|
|||||||
char c;
|
char c;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
c = str.charAt(i);
|
c = str.charAt(i);
|
||||||
if(false == isInvalidChar(c)) {
|
if(isValidChar(c)) {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,8 +80,8 @@ public class TextSimilarity {
|
|||||||
* @param charValue 字符
|
* @param charValue 字符
|
||||||
* @return true表示为非汉字,数字和字母,false反之
|
* @return true表示为非汉字,数字和字母,false反之
|
||||||
*/
|
*/
|
||||||
private static boolean isInvalidChar(char charValue) {
|
private static boolean isValidChar(char charValue) {
|
||||||
return (charValue >= 0x4E00 && charValue <= 0XFFF) || //
|
return (charValue >= 0x4E00 && charValue <= 0X9FFF) || //
|
||||||
(charValue >= 'a' && charValue <= 'z') || //
|
(charValue >= 'a' && charValue <= 'z') || //
|
||||||
(charValue >= 'A' && charValue <= 'Z') || //
|
(charValue >= 'A' && charValue <= 'Z') || //
|
||||||
(charValue >= '0' && charValue <= '9');
|
(charValue >= '0' && charValue <= '9');
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package cn.hutool.core.lang;
|
package cn.hutool.core.text;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cn.hutool.core.text.TextSimilarity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文本相似度计算工具类单元测试
|
* 文本相似度计算工具类单元测试
|
||||||
* @author looly
|
* @author looly
|
||||||
@ -21,6 +19,12 @@ public class TextSimilarityTest {
|
|||||||
Assert.assertEquals(0.8571428571428571D, degree, 16);
|
Assert.assertEquals(0.8571428571428571D, degree, 16);
|
||||||
|
|
||||||
String similarPercent = TextSimilarity.similar(a, b, 2);
|
String similarPercent = TextSimilarity.similar(a, b, 2);
|
||||||
Assert.assertEquals("85.71%", similarPercent);
|
Assert.assertEquals("84.62%", similarPercent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void similarTest(){
|
||||||
|
final double abd = TextSimilarity.similar("abd", "1111");
|
||||||
|
Assert.assertEquals(0, abd, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,12 @@
|
|||||||
package cn.hutool.core.util;
|
package cn.hutool.core.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import java.util.ArrayList;
|
||||||
import cn.hutool.core.lang.func.Func1;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ReUtilTest {
|
public class ReUtilTest {
|
||||||
final String content = "ZZZaaabbbccc中文1234";
|
final String content = "ZZZaaabbbccc中文1234";
|
||||||
@ -52,7 +49,7 @@ public class ReUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
public void findAllTest() {
|
public void findAllTest() {
|
||||||
// 查找所有匹配文本
|
// 查找所有匹配文本
|
||||||
List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<String>());
|
List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>());
|
||||||
ArrayList<String> expected = CollectionUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
ArrayList<String> expected = CollectionUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||||
Assert.assertEquals(expected, resultFindAll);
|
Assert.assertEquals(expected, resultFindAll);
|
||||||
}
|
}
|
||||||
@ -82,13 +79,7 @@ public class ReUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
public void replaceAllTest2() {
|
public void replaceAllTest2() {
|
||||||
//此处把1234替换为 ->1234<-
|
//此处把1234替换为 ->1234<-
|
||||||
String replaceAll = ReUtil.replaceAll(this.content, "(\\d+)", new Func1<Matcher, String>() {
|
String replaceAll = ReUtil.replaceAll(this.content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-");
|
||||||
|
|
||||||
@Override
|
|
||||||
public String call(Matcher parameters) {
|
|
||||||
return "->" + parameters.group(1) + "<-";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll);
|
Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user