-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-basic.js
More file actions
83 lines (70 loc) · 2.98 KB
/
example-basic.js
File metadata and controls
83 lines (70 loc) · 2.98 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
/**
* ExisEcho API - Basic Example
*
* This example demonstrates basic duplicate detection using the ExisEcho API.
*
* Get your FREE test API key by emailing: exisllc@gmail.com
* Documentation: https://www.fuzzy-logic.com/Api
*/
import { ExisEchoClient } from './exisecho.js';
// Replace with your API key
const API_KEY = "your-api-key-here";
async function main() {
// Initialize the client
const client = new ExisEchoClient(API_KEY);
// Sample data with potential duplicates
const records = [
{ id: "1", fields: { name: "John Smith", email: "john.smith@example.com" } },
{ id: "2", fields: { name: "Jon Smyth", email: "jon.smyth@example.com" } },
{ id: "3", fields: { name: "Jane Doe", email: "jane.doe@example.com" } },
{ id: "4", fields: { name: "John A. Smith", email: "johnsmith@example.com" } },
{ id: "5", fields: { name: "Robert Johnson", email: "bob.johnson@example.com" } },
{ id: "6", fields: { name: "Bob Johnson", email: "robert.j@example.com" } },
];
console.log("ExisEcho API - Basic Example");
console.log("=".repeat(50));
console.log();
console.log(`Checking ${records.length} records for duplicates...`);
console.log();
try {
// Find duplicates with phonetic matching enabled
const result = await client.findDuplicates(records, {
threshold: 0.7,
columnOptions: {
name: {
usePhoneticMatching: true,
equateSynonyms: true,
ignoreWordOrder: true
}
}
});
if (result.success) {
const { summary, matches, usage } = result;
console.log("Results:");
console.log(` - Records analyzed: ${summary.totalRecordsAnalyzed}`);
console.log(` - Duplicates found: ${summary.totalMatches}`);
console.log(` - Processing time: ${summary.processingTimeMs}ms`);
console.log();
if (matches.length > 0) {
console.log("Potential Duplicates:");
console.log("-".repeat(50));
for (const match of matches) {
const rec1 = records.find(r => r.id === match.record1Id);
const rec2 = records.find(r => r.id === match.record2Id);
console.log(` Match Score: ${(match.score * 100).toFixed(0)}% (${match.quality})`);
console.log(` Record ${match.record1Id}: ${rec1.fields.name}`);
console.log(` Record ${match.record2Id}: ${rec2.fields.name}`);
console.log();
}
}
console.log("API Usage:");
console.log(` - Units consumed: ${usage.unitsConsumed}`);
console.log(` - Units remaining: ${usage.unitsRemaining}`);
} else {
console.error(`Error: ${result.error}`);
}
} catch (error) {
console.error(`Error: ${error.message}`);
}
}
main();