LevenshteinDist - función de script y de gráfico
LevenshteinDist() devuelve la distancia Levenshtein entre dos cadenas. Se define como el número mínimo de ediciones de un solo carácter (inserciones, eliminaciones o sustituciones) necesarias para cambiar una cadena por otra. La función es útil para comparaciones de cadenas difusas.
Sintaxis:
LevenshteinDist(text1, text2)
Tipo de datos que devuelve: entero
Ejemplo | Resultado |
---|---|
LevenshteinDist('Kitten','Sitting') | Devuelve "3" |
Script de carga
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;
Resultado
ID | Cadenatexto_1 | Cadenatexto_2 | LevenshteinDistance |
---|---|---|---|
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 |