스크립트를 사용하여 순서에 관계없이 데이터 테이블의 내용과 두 번째 테이블의 내용과 일치하는 문자 수를 얻고 가장 일치하는 데이터가 있는 두 번째 테이블의 행 번호를 반환하는 방법.
간단한 루프 비교만 작성하겠습니다.
비교할 문자열의 수가 많으면 어떻게 더 빠를 수 있습니까?
감사해요!
예를 들어,
첫 번째 테이블의 문자열
"KDBAC"
"FLGHEK"
"ONLCQR"
"WVTZXR"
두 번째 테이블의 문자열
"ROMNLQ"
"DFBACE"
"LKGHJK"
"WVTZYX"
중복이 허용되지 않으면 연관 배열과 해당 집합 연산을 사용해 볼 수 있습니다.
Names Default To Here(1);
dt = New Table("demo",
Add Rows(4),
New Column("A", Character, "Nominal", Set Values({"KDBAC", "FLGHEK", "ONLCQR", "WVTZXR"})),
New Column("B", Character, "Nominal", Set Values({"ROMNLQ", "DFBACE", "LKGHJK", "WVTZYX"}))
);
// Create lookup associative array, with row number as key and value as associative array with
// keys as characters in row. This will be used in union operations
aa_lookup = Associative Array();
For Each({val, idx}, dt:B << get values,
aa_lookup[idx] = Associative Array(Eval List(Words(val, "")));
);
// Create collection column
dt << New Column("C", Numeric, Continuous);
For Each Row(dt,
best_match = 0;
max_row = .;
For Each({{key, val}}, aa_lookup,
cur_aa = Associative Array(Eval List(Words(:A, "")));
cur_aa << Intersect(val);
cur_match = N Items(cur_aa);
If(cur_match > best_match,
best_match = cur_match;
max_row = key;
);
);
:C = max_row;
);
