相似度的算法(编辑距离法)(Java实现代码)
来源:互联网 发布:mac优化 编辑:程序博客网 时间:2024/04/30 04:18
public class Suanfa {public static void main(String[] args) {String Str_1="abcdefghijklmuvwxyz";String Str_2="ijkabclmdefghpq";//lengthint Length1=Str_1.length();int Length2=Str_2.length();int Distance=0;if (Length1==0) {Distance=Length2;}if(Length2==0){Distance=Length1;}if(Length1!=0&&Length2!=0){int[][] Distance_Matrix=new int[Length1+1][Length2+1];//编号int Bianhao=0;for (int i = 0; i <= Length1; i++) {Distance_Matrix[i][0]=Bianhao;Bianhao++;}Bianhao=0;for (int i = 0; i <=Length2; i++) {Distance_Matrix[0][i]=Bianhao;Bianhao++;}char[] Str_1_CharArray=Str_1.toCharArray();char[] Str_2_CharArray=Str_2.toCharArray();for (int i = 1; i <= Length1; i++) {for(int j=1;j<=Length2;j++){if(Str_1_CharArray[i-1]==Str_2_CharArray[j-1]){Distance=0;}else{Distance=1;}int Temp1=Distance_Matrix[i-1][j]+1;int Temp2=Distance_Matrix[i][j-1]+1;int Temp3=Distance_Matrix[i-1][j-1]+Distance;Distance_Matrix[i][j]=Temp1>Temp2?Temp2:Temp1;Distance_Matrix[i][j]=Distance_Matrix[i][j]>Temp3?Temp3:Distance_Matrix[i][j];}}Distance=Distance_Matrix[Length1][Length2];}double Aerfa=1-1.0*Distance/(Length1>Length2?Length1:Length2);System.out.println(Aerfa);}}
0 0
- 相似度的算法(编辑距离法)(Java实现代码)
- java实现编辑距离算法,计算字符串相似度
- java文本相似度计算(Levenshtein Distance算法(中文翻译:编辑距离算法))----代码和详解
- java文本相似度计算(Levenshtein Distance算法(中文翻译:编辑距离算法))----代码和详解
- 文本相似度——编辑距离算法&java简单实现
- 相似度算法(一)------编辑距离
- 相似度算法(编辑距离原理)
- 文本相似度 -- 最小编辑距离算法
- 编辑距离算法的java实现
- 计算字符串的相似度---编辑距离
- 用C#实现字符串相似度算法(编辑距离算法 Levenshtein Distance)
- java两字符串相似度计算算法——Levenshtein distance编辑距离算法
- 字符串相似度算法 levenshtein distance 编辑距离算法
- 字符串相似度算法(编辑距离算法 Levenshtein Distance)
- 字符串相似度算法 levenshtein distance 编辑距离算法
- 字符串相似度算法 -- levenshtein distance 编辑距离算法
- 字符串相似度算法(编辑距离算法 Levenshtein Distance)
- 算法介绍(3) 编辑距离算法-字符串相似度
- 网点推广策划方案
- 【PAT】1018. Public Bike Management
- 【SpringBoot系列】SpringBoot注解详解
- Unity结合C++开发服务器实现多人游戏(三)
- BOL的使用例子
- 相似度的算法(编辑距离法)(Java实现代码)
- java InputStream 和 OutputStream
- 分享一个链接
- 十进制转换为任何进制
- jQuery选择器 层次选择器
- eclipse javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- AndroidL之后ROOM的zip包中关于system.new.dat无法挂载
- 在Spring整合 SpringMVC,SpringData和 JPA 时,如何解决 Lazy懒加载问题?
- CodeForces - 766D Mahmoud and a Dictionary (并查集)