salut, comment comparer la liste 1 à la liste 2 pour calculer la distance entre chaînes à l'aide de Jaro Winkler
Le fichier de sortie doit contenir les noms de la liste 1 et de la liste 2 et une troisième colonne contenant le score JW.
https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance
Liste1
JOHN SMITH
TIGER WOODS
TONY MOLLY
JAMES A
MICKEY LA SOURIS
DONALD DUCK
DUNKIN DONUTS
TOKYO
Liste2:
JOHNTHAN SMITH
TIGRE WOO
JOHN MOLLY
JAMES XXXX LLC
JAMES
TOKIO
Je vous remercie. Je vais essayer les options et revenir en arrière.
JMP fournit la fonction Shortest Edit Script () et l'exemple de l'index de script fournit un script permettant de rechercher la séquence la plus longue commune.
L'un des scripts écrits pour le livre JSL Companion, 2nd Edition définit la distance de Levenshtein et fournit des exemples. il est joint ci-dessous.
Le Web n'attacherait pas le fichier jsl, j'ai donc changé l'extension en .txt
Je ne vois pas de statistiques similaires, alors j'ai trouvé du code dans une autre langue et l'ai transféré vers JMP. Vous trouverez ci-dessous un exemple de script qui répond à vos attentes. Copiez-le dans une fenêtre de script et exécutez-le. Il génère les listes de mots à, dans des tableaux de données séparés ..... Je crois que c'est ce que vous voulez. Ensuite, il les combine dans une seule table de données et crée une nouvelle colonne avec la statistique Jaro-Winkler.
names default to here(1);
dt1 = New Table( "Table 1",
Add Rows( 8 ),
New Column( "List 1",
Character,
"Nominal",
Set Values(
{"JOHN SMITH", "TIGER WOODS", "TONY MOLLY", "JAMES A", "MICKEY MOUSE",
"DONALD DUCK", "DUNKIN DONUTS", "TOKYO"}
)
)
);
dt2 = New Table( "Table 2",
Add Rows( 6 ),
New Column( "List 2",
Character,
"Nominal",
Set Values(
{"JOHNTHAN SMITH", "TIGER WOO", "JOHN MOLLY", "JAMES XXXX LLC", "JAMES",
"TOKIO"}
)
)
);
// Join the tables
dtJoined = dt1 << Join(
With( dt2 ),
By Row Number,
Output Table( "Joined Table" )
);
// Create New column
dtJoined << New Column("Jaro-Winkler");
// Add the functions that create the Jaro-Winkler
jaromatch = Function( {string1, string2}, {i},
str1_len = Length( string1 );
str2_len = Length( string2 );
allowedDist = Floor( Max( str1_len, str2_len ) / 2 ) - 1;
//*** walk through string1 and match characters to string2 ***;//
matchChars = "";
For( i = 1, i <= str1_len, i++,
//*** get the part of string2 to search ***;
allowed_start = Max( 1, i - allowedDist );
//*** starting char position ***;
allowed_str2 = Substr( string2, allowed_start, i + allowedDist - allowed_start + 1 );
//*** find i char from string1 in string2 within the allowedDist ***;
position = Contains( allowed_str2, Substr( string1, i, 1 ) );
If( position > 0,
matchChars = Concat( matchChars, Substr( allowed_str2, position, 1 ) );
//*** Once a char is assigned, it can not be assigned again. So, chg char in string2. ***;
string2 = Substr( string2, 1, allowed_start + position - 2 ) || "~" ||
Substr( string2, allowed_start + position );
);
);
Trim( matchChars );
);
/* count the number of "half" transpositions */
jarotrans = Function( {string1, string2},{i},
ntrans = 0;
For( i = 1, i <= Min( Length( Trim( string1 ) ), Length( Trim( string2 ) ) ), i++,
If( Substr( string1, i, 1 ) != Substr( string2, i, 1 ),
ntrans
++)
);
ntrans / 2;
);
/* get the length of the matching characters at the beginning */
getPrefixlen = Function( {string1, string2, maxprelen},{i},
n = Min( maxprelen, Length( string1 ), Length( string2 ) );
If( n == 0,
n = 0,
For( i = 1, i <= n, i++,
If( Substr( string1, i, 1 ) != Substr( string2, i, 1 ),
n = (i - 1)
); //*** all maxprelen characters match ***;
)
);
n;
);
/* calc the jaro distance */
jarodist = Function( {string1, string2}, {i},
//*** get number of matched characters in string1 ***;
m1 = jaromatch( string1, string2 );
m1_len = Length( m1 );
If( m1_len == 0, j_dist = 0 );
//*** get number of matched characters in string2 ***;
m2 = jaromatch( string2, string1 );
m2_len = Length( m2 );
If( m2_len == 0, j_dist = 0 );
//*** get number of transposed characters ***;
ntrans = jarotrans( m1, m2 );
//*** calc jaro distance ***;
j_dist = (m1_len / Length( string1 ) + m2_len / Length( string2 ) + (m1_len - ntrans) / m1_len) / 3;
j_dist;
);
/* calc the jaro-winkler distance */
jarowink = Function( {string1, string2, prefixscale},{i},
string1 = Uppercase( Trim( string1 ) );
string2 = Uppercase( Trim( string2 ) );
//*** check for trivial case and calc JW if needed ***;
If( string1 == string2,
returned = 1.0,
jarodist1 = jarodist( string1, string2 );
prelen = getPrefixlen( string1, string2, 4 );
returned = jarodist1 + prelen * prefixscale * (1 - jarodist1);
);
returned;
);
// Loop through the data table and create the values for the new column
For(i=1,i<=n rows(dtJoined), i++,
dtJoined:Name("Jaro-Winkler")[i] = jarowink(dtJoined:List 1[i], dtJoined:List2[i], 0.1);
)Avons-nous une autre fonction intégrée à JMP comparable à Jaro-Winkler?
La lecture de 2 listes différentes à partir de deux fichiers différents est triviale, et la combinaison n'est pas non plus un problème. Le vrai travail serait de développer un script qui calcule les distances de Jaro-Winkler. Il n’existe pas de fonction intégrée pour calculer la distance de Jaro-Winkler. Si JMP pouvait s’acquitter de cette tâche, il faudrait déployer des efforts considérables pour la développer.
@vishalparekh ,
Je ne pense pas que JMP intègre une fonction permettant de calculer la distance que vous recherchez. Vous devrez définir des fonctions personnalisées définies par l'utilisateur pour obtenir ce que vous recherchez. Si j'en ai l'occasion, j'essaierai plus tard. vous voudrez peut-être lire sur function () et contains () dans l'index de script pour avoir quelques idées.