-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf2.js
86 lines (63 loc) · 1.8 KB
/
tf2.js
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
var txt = [];
var keys = [];
var tot = 10; // assign the num of files
const keyword_extractor = require("keyword-extractor");
var fs = require("fs");
// var files = [];
// for (var i = 0; i < tot; i++) {
// files.push("./problems/prob" + (i + 1) + ".txt");
// }
var words = [];
//var ind = {};
//var ind_num = 0;
var unique_words = [];
// create the file
var arr = new Array(2000); // create an empty array of length 2000
for (var i = 0; i < 2000; i++) {
arr[i] = new Array(10000); // make each element an array
}
var iidd = fs.readFileSync("./keywords.txt", "utf8");
iidd = iidd.toString();
iidd = iidd.split("\n");
for (var i = 0; i < tot; i++) {
var text = fs.readFileSync(files[i], "utf8");
text = text.toString();
var tt = keyword_extractor.extract(text, {
language: "english",
remove_digits: false,
return_changed_case: true,
remove_duplicates: false,
});
var newString = tt;
var count = new Map();
var cnt = 0;
for (var j = 0; j < newString.length; j++) {
if (count.has(newString[j]) == false) {
count.set(newString[j], 1); // = 1;
} else {
count.set(newString[j], count.get(newString[j]) + 1); // = ;
}
}
newString = keyword_extractor.extract(text, {
language: "english",
remove_digits: false,
return_changed_case: true,
remove_duplicates: true,
});
var sr = 0;
for (var j = 0; j < newString.length; j++) {
var x = count.get(newString[j]);
var cal = x / newString.length;
console.log("Running");
sr = sr + x * x;
fs.appendFile("./ptf/tf" + (i + 1) + ".txt", `${cal}\n`, (err) => {
if (err) throw err;
});
}
sr = Math.sqrt(sr);
fs.appendFile("mod.txt", `${sr}\n`, (err) => {
if (err) throw err;
});
}
//unique_words.sort();
// All the Unique words are written to the file keywords.txt