///|
fn example_linkage_config() -> @phonetic.LinkageConfig {
{
match_config: {
normalization: @phonetic.name_normalization_config(),
encoders: [],
metric: @phonetic.Levenshtein,
string_weight: 1.0,
threshold: 0.6,
token_policy: @phonetic.WholeInput,
unmatched_token_penalty: 0.5,
},
blocking_algorithms: [@phonetic.Soundex],
max_candidates_per_left: 10,
minimum_score: 0.6,
retain_rejected: true,
}
}
///|
fn print_ids(label : String, ids : Array[String]) -> Unit {
let mut value = ""
for index = 0; index < ids.length(); index = index + 1 {
if index > 0 {
value = value + ","
}
value = value + ids[index]
}
println(label + "=" + value)
}
///|
fn main {
let left : Array[@phonetic.LinkRecord] = [
{ id: "old-1", name: "Robert" },
{ id: "old-2", name: "Alice" },
{ id: "old-3", name: "Smith" },
]
let right : Array[@phonetic.LinkRecord] = [
{ id: "new-1", name: "Rupert" },
{ id: "new-2", name: "Alyce" },
{ id: "new-3", name: "Jones" },
]
match @phonetic.link_name_datasets(left, right, example_linkage_config()) {
Err(_) => println("linkage failed")
Ok(report) => {
for link in report.links {
println(
"link=\{link.left_id}->\{link.right_id} score=\{link.evidence.score}",
)
}
print_ids("unmatched_left", report.unmatched_left_ids)
print_ids("unmatched_right", report.unmatched_right_ids)
println("blocked=\{report.stats.blocked_candidate_count}")
println("evaluated=\{report.stats.evaluated_pair_count}")
println("accepted=\{report.stats.accepted_link_count}")
}
}
}