-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoding.js
More file actions
59 lines (53 loc) · 1.38 KB
/
encoding.js
File metadata and controls
59 lines (53 loc) · 1.38 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
const trie = require("./trie.js");
function CreateDenseSearchTermFromString(input) {
let words = [input];
let buf = input.split("");
for (let i = 1; i < buf.length; i++) {
let tmp = []
for (let j = i; j < buf.length; j++) {
tmp.push(buf[j]);
}
words.push(tmp.join(""));
}
return words;
}
function CreateSearchObject(inputFile) {
return new Promise((resolve, reject) => {
let searchObject = {"trie": new trie.Trie(), "coverage": {}, "locations": {}};
let fragments = inputFile["message_data"].split(inputFile["fragmenter"]["l1"]);
console.log(fragments);
let loc = 0;
fragments.forEach(item => {
console.log(item);
if (!searchObject["locations"][item]) {
searchObject["locations"][item] = [];
}
searchObject["locations"][item].push(loc);
if (!searchObject["coverage"][item]) {
searchObject["coverage"][item] = 0;
}
let dense = CreateDenseSearchTermFromString(item);
console.log(dense);
dense.forEach(d => {
trie.AddToTrie(searchObject["trie"], d);
});
});
resolve(searchObject);
});
}
function Encode(inputFile) {
return new Promise((resolve, reject) => {
CreateSearchObject(inputFile).then((so) => {
resolve(so)
}).catch(err => {
console.log("Error creating search file!")
console.log(err.message)
console.log(err.stack)
});
});
}
module.exports = {
Encode,
CreateSearchObject,
CreateDenseSearchTermFromString,
}