LevenshteinDist - 指令碼與圖表函數
LevenshteinDist() 傳回兩個字串之間的 Levenshtein 距離。這定義為將一個字串變更為另一個字串所需的最小單一字元編輯數量 (插入、刪除或替代)。 該函數對於模糊字串比較很實用。
語法:
LevenshteinDist(text1, text2)
傳回的資料類型: 整數
範例 | 結果 |
---|---|
LevenshteinDist('Kitten','Sitting') | 傳回「3」 |
載入指令碼
T1: Load *, recno() as ID; Load 'Silver' as String_1,* inline [ String_2 Sliver SSiver SSiveer ]; T1: Load *, recno()+3 as ID; Load 'Gold' as String_1,* inline [ String_2 Bold Bool Bond ]; T1: Load *, recno()+6 as ID; Load 'Ove' as String_1,* inline [ String_2 Ove Uve Üve ]; T1: Load *, recno()+9 as ID; Load 'ABC' as String_1,* inline [ String_2 DEFG abc ビビビ ]; set nullinterpret = '<NULL>'; T1: Load *, recno()+12 as ID; Load 'X' as String_1,* inline [ String_2 '' <NULL> 1 ]; R1: Load ID, String_1, String_2, LevenshteinDist(String_1, String_2) as LevenshteinDistance resident T1; Drop table T1;
結果
ID | String_1 | String_2 | LevenshteinDistance |
---|---|---|---|
1 | Silver | Sliver | 2 |
2 | Silver | SSiver | 2 |
3 | Silver | SSiveer | 3 |
4 | Gold | 粗體 | 1 |
5 | Gold | Bool | 3 |
6 | Gold | Bond | 2 |
7 | Ove | Ove | 0 |
8 | Ove | Uve | 1 |
9 | Ove | Üve | 1 |
10 | ABC | DEFG | 4 |
11 | ABC | abc | 3 |
12 | ABC | ビビビ | 3 |
13 | X | 1 | |
14 | X | - | 1 |
15 | X | 1 | 1 |