안녕하세요, Jaro Winkler를 사용하여 문자열 거리를 계산하기 위해 List 1을 List 2와 어떻게 비교할 수 있습니까?
출력 파일에는 목록 1과 목록 2의 이름과 JW 점수가있는 세 번째 열이 있어야합니다.
https://en.wikipedia.org/wiki/Jaro%E2%8080%93Winkler_distance
목록 1
존 스미스
타이거 우즈
토니 몰리
제임스 A
미키 마우스
도날드 덕
던킨 도넛
도쿄
List2 :
욘 스미스
타이거 우
존 몰리
제임스 XXXX LLC
제임스
도쿄
고맙습니다. 나는 옵션을 시도하고 다시 원을 칠 것이다.
JMP는 Shortest Edit Script () 함수를 제공하며, Scripting Index의 예제는 가장 긴 공통 시퀀스를 찾는 스크립트를 제공합니다.
책 JSL Companion, 2nd Edition을 위해 작성된 스크립트 중 하나는 Levenshtein 거리를 정의하고 예제를 제공합니다. 아래에 첨부되어 있습니다.
웹은 jsl 파일을 첨부하지 않으므로 확장자를 .txt로 변경했습니다.
비슷한 통계가 보이지 않아 다른 언어로 된 코드를 찾아서 JMP로 포팅했습니다. 다음은 내가 원하는 것이라고 생각하는 예제 스크립트입니다. 그것을 스크립트 창에 복사하고 실행하십시오. 그것은 단어 목록을 별도의 데이터 표로 생성합니다 ..... 나는 그것이 당신이 원하는 것이라고 믿습니다. 그런 다음 이들을 하나의 데이터 테이블로 결합하고 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);
)JMP에 내장 된 다른 함수가 있습니다. 자로 - 윙클러?
두 개의 서로 다른 파일에서 두 개의 서로 다른 목록을 읽는 일은 쉽지 않으며 결합 작업도별로 중요하지 않습니다. 실제 작업은 Jaro-Winkler 거리를 계산하는 스크립트를 개발하는 것입니다. Jaro-Winkler Distance를 계산하는 내장 함수는 없습니다. JMP가 작업을 처리 할 수는 있지만 개발하는 데는 많은 노력이 필요합니다.
@vishalparekh ,
나는 JMP에 당신이있는 거리를 계산할 내장 함수가 있다고 생각하지 않는다. 사용자 정의 함수를 정의하여 사용자가 원하는 것을 성취해야합니다. 기회가 생기면 나중에 그 기회를 줄 것입니다. 몇 가지 아이디어를 얻으려면 Scripting Index에서 function () 및 contains ()를 읽으십시오.