LevenshteinDist - 脚本和图表函数
LevenshteinDist() 返回两个字符串之间的 Levenshtein 距离。它定义为将一个字符串更改为另一个字符串所需的最小单字符编辑次数(插入、删除或替换)。
该函数用于模糊字符串比较。
语法:
LevenshteinDist(text1, text2)
返回数据类型: 整数
LevenshteinDist('Kitten','Sitting') | Returns '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;
结果
1 | Silver | Sliver | 2 |
2 | Silver | SSiver | 2 |
3 | Silver | SSiveer | 3 |
4 | Gold | Bold | 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 |