-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathembedding_worker.js
More file actions
27 lines (23 loc) · 842 Bytes
/
Copy pathembedding_worker.js
File metadata and controls
27 lines (23 loc) · 842 Bytes
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
const maxLength = 400;
function embed_freq(freqMap, searchResultsData){
searchResultsData.forEach(results =>{
results.preprocessedResults.forEach(word =>{
results.vectors.push(freqMap.get(word));
})
results.vectors = padding(results.vectors);
})
return searchResultsData;
}
function padding(vectors){
const paddingLength = maxLength - vectors.length;
return vectors.concat(new Array(paddingLength).fill(0));
}
self.addEventListener('message', event => {
const searchResultsData = event.data[1];
const freqMap = event.data[0];
// Perform preprocessing and vectorization
const vectorizedData = embed_freq(freqMap, searchResultsData);
// Send the vectorized data back to the main script
// console.log(vectorizedData);
self.postMessage(vectorizedData);
});