-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
96 lines (82 loc) · 3.33 KB
/
Copy pathexample.js
File metadata and controls
96 lines (82 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Example usage of the Enhanced Name Matcher library
*/
const {
EnhancedNaturalMatcher,
match,
isMatch,
matchGroup,
NameNormalizer
} = require('./index');
console.log('Enhanced Name Matcher - Example Usage\n');
// Basic similarity scoring
console.log('Basic similarity scoring:');
const testPairs = [
['John Smith', 'Smith, John'],
['William Jones', 'Bill Jones'],
['Robert Johnson', 'Bob Johnson'],
['Aaron Charles Donovan', 'Aaron Donovan'],
['Michael Jackson', 'Michael Jackson Jr'],
['James Chaney', 'Jim Chaney'],
['Jessica Elizondo', 'Jessica William Elizondo'],
['Ander Herrera', 'Herrera Ander'],
['Chelsea M Solomon', 'Chelsea Mary-Elizabeth Solomon'],
['John Smith', 'James Smith'], // Should not match
['Robert Johnson', 'Robert Williams'] // Should not match
];
testPairs.forEach(([name1, name2]) => {
const score = match(name1, name2);
const matched = isMatch(name1, name2);
console.log(`"${name1}" vs "${name2}": Score = ${score.toFixed(3)}, Match = ${matched ? 'YES' : 'NO'}`);
});
// Custom matcher with different threshold
console.log('\nCustom matcher with different threshold:');
const strictMatcher = new EnhancedNaturalMatcher({ threshold: 0.85 });
const lenientMatcher = new EnhancedNaturalMatcher({ threshold: 0.6 });
const borderlinePair = ['Michael Johnson', 'Mike Johnson'];
console.log(`"${borderlinePair[0]}" vs "${borderlinePair[1]}"`);
console.log(` Standard (0.75): ${isMatch(borderlinePair[0], borderlinePair[1]) ? 'MATCH' : 'NO MATCH'}`);
console.log(` Strict (0.85): ${strictMatcher.isMatch(borderlinePair[0], borderlinePair[1]) ? 'MATCH' : 'NO MATCH'}`);
console.log(` Lenient (0.6): ${lenientMatcher.isMatch(borderlinePair[0], borderlinePair[1]) ? 'MATCH' : 'NO MATCH'}`);
// Group matching
console.log('\nGroup matching:');
const nameGroups = [
['Aaron Charles Donovan', 'Aaron Donovan', 'Donovan Aaron Charles'],
['Emily Farris', 'Emily Tigist Ferede Farris', 'Farris Emily Tigist Ferede'],
['Tiffany Nash', 'Nash Tiffany M']
];
nameGroups.forEach((group, index) => {
const result = matchGroup(group);
console.log(`Group ${index + 1}: ${result.isMatch ? 'MATCH' : 'NO MATCH'} (Score: ${result.score.toFixed(3)})`);
console.log(` Names: ${group.join(' | ')}`);
});
// Name normalization
console.log('\nName normalization:');
const nameExamples = [
'Smith, John William Jr.',
'Dr. Robert J. Johnson III',
'Michael Patrick Davis',
'Mary-Elizabeth Smith (Parker)',
'O\'Connor, James Richard'
];
nameExamples.forEach(name => {
const parsed = NameNormalizer.parseName(name);
console.log(`\nOriginal: "${name}"`);
console.log(` Normalized: "${parsed.normalized}"`);
console.log(` First: "${parsed.firstName}", Middle: "${parsed.middleNames.join(' ')}", Last: "${parsed.lastName}"`);
if (parsed.prefixes.length > 0) {
console.log(` Prefixes: ${parsed.prefixes.join(', ')}`);
}
if (parsed.suffixes.length > 0) {
console.log(` Suffixes: ${parsed.suffixes.join(', ')}`);
}
console.log(` Initials: ${parsed.initials.first}${parsed.initials.middle}${parsed.initials.last}`);
// Get variations for the first name
if (parsed.firstName) {
const variations = NameNormalizer.getNameVariations(parsed.firstName);
if (variations.length > 1) {
console.log(` First name variations: ${variations.join(', ')}`);
}
}
});
console.log('\nDone!');