-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic-usage.js
More file actions
70 lines (58 loc) · 2.06 KB
/
Copy pathbasic-usage.js
File metadata and controls
70 lines (58 loc) · 2.06 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
/**
* Basic usage example for @mixpeek/iab-mapper
*/
const { Mapper } = require('@mixpeek/iab-mapper');
// Create a mapper instance with default configuration
const mapper = new Mapper({
fuzzyMethod: 'rapidfuzz',
fuzzyCut: 0.92,
maxTopics: 3,
cattax: '2'
});
// Example 1: Map a single label
console.log('Example 1: Basic label mapping');
console.log('================================\n');
const result1 = mapper.mapRecord({
label: 'Sports'
});
console.log('Input:', result1.in_label);
console.log('Output IDs:', result1.out_ids);
console.log('Output Labels:', result1.out_labels);
console.log('OpenRTB format:', JSON.stringify(result1.openrtb, null, 2));
console.log('VAST format:', result1.vast_contentcat);
console.log('\n');
// Example 2: Map with code and vectors
console.log('Example 2: Mapping with code and vector attributes');
console.log('===================================================\n');
const result2 = mapper.mapRecord({
code: '2-12',
label: 'Food & Drink',
channel: 'editorial',
type: 'article',
format: 'video',
language: 'en',
source: 'professional',
environment: 'ctv'
});
console.log('Input:', result2.in_label, '(code:', result2.in_code + ')');
console.log('Topic IDs:', result2.topic_ids);
console.log('Topic Confidence:', result2.topic_confidence);
console.log('Topic Sources:', result2.topic_sources);
console.log('Vector Attributes:', result2.vectors);
console.log('All Output IDs:', result2.out_ids);
console.log('OpenRTB format:', JSON.stringify(result2.openrtb, null, 2));
console.log('\n');
// Example 3: Batch processing
console.log('Example 3: Batch processing multiple records');
console.log('=============================================\n');
const records = [
{ label: 'Sports' },
{ label: 'Automotive' },
{ label: 'Cooking how-to', channel: 'editorial' }
];
const results = mapper.mapRecords(records);
results.forEach((result, idx) => {
console.log(`Record ${idx + 1}: "${result.in_label}"`);
console.log(` → Mapped to: ${result.out_labels.join(', ')}`);
console.log(` → IDs: ${result.out_ids.join(', ')}`);
});