导入simhash工程
这个项目不能直接使用,因为jar包的问题,需要进行改造。
测试simhash
按照测试用例的要求,准备两个文件,就是需要进行对比的文章
执行测试用例,结果如下
案例整合
需要先把simhash安装到本地仓库
在案例的pom.xml中加入以下依赖
com.lou
simhasher
0.0.1-SNAPSHOT
修改代码@Component
public class TaskTest {
@Scheduled(cron = "0/5 * * * * *")
public void test() {
System.out.println(LocalDateTime.now()+"任务执行了");
String str1 = readAllFile("D:/test/testin.txt");
SimHasher hash1 = new SimHasher(str1);
//打印simhash签名
System.out.println(hash1.getSignature());
System.out.println("============================");
String str2 = readAllFile("D:/test/testin2.txt");
//打印simhash签名
SimHasher hash2 = new SimHasher(str2);
System.out.println(hash2.getSignature());
System.out.println("============================");
//打印海明距离 System.out.println(hash1.getHammingDistance(hash2.getSignature()));
}
public static String readAllFile(String filename) {
String everything = "";
try {
FileInputStream inputStream = new FileInputStream(filename);
everything = IOUtils.toString(inputStream);
inputStream.close();
} catch (IOException e) {
}
return everything;
}
}
启动项目控制台显示: