Java字串相似度匹配

2021-09-01 00:23:56 字數 1020 閱讀 5762

原文:

package com.xfl.boot.common.utils;

/** * created by xfl

* time on 2018/11/16 0:10

* description:

*/public class similarityutils

/***

* @param str1

* @param str2

*/public static void levenshtein(string str1,string str2)

for (int a = 0; a <= len2; a++)

//計算兩個字元是否一樣,計算左上的值

int temp;

for (int i = 1; i <= len1; i++) else

//取三個值中最小的

dif[i][j] = min(dif[i - 1][j - 1] + temp, dif[i][j - 1] + 1,

dif[i - 1][j] + 1);}}

system.out.println("字串\""+str1+"\"與\""+str2+"\"的比較");

//取陣列右下角的值,同樣不同位置代表不同字串的比較

system.out.println("差異步驟:"+dif[len1][len2]);

//計算相似度

float similarity =1 - (float) dif[len1][len2] / math.max(str1.length(), str2.length());

system.out.println("相似度:"+similarity);

}//得到最小值

java字串相似度演算法

按順序匹配的,如下 判斷兩個字串相似度,可設定level param strsource 原字串 param strcompared 比較字串 param level 評分閥值 param morecount 比較字串比原字串多多少個限制 return public staticboolean is...

字串相似度

這個演算法 於網上,但忘記了出處,對其使使用了 issame封裝,然後用在了自己的網頁資料抓取 中。求解兩個字串的相似度int calculatestringdistance const string stra,const string strb intret c lena 1 lenb 1 for...

字串相似度

最近要對字串進行聚類,這些字串都是 的輸出,嘗試了幾種字串相似度度量的方法 levenshtein距離 字串核函式 lcs max len str1,str2 其中相似度用公式distance 1.0 similarity 1轉換為距離.使用層次聚類方法.下面是要聚類的字串 points aabbc...