summaryrefslogtreecommitdiff
path: root/src/filer.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/filer.js')
-rw-r--r--src/filer.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/filer.js b/src/filer.js
new file mode 100644
index 0000000..a93f0b4
--- /dev/null
+++ b/src/filer.js
@@ -0,0 +1,42 @@
+const fs = require('fs');
+const api = require('./api');
+
+function pad(n, z) {
+ z = z || 2;
+ return ('0000000000' + n).slice(-z);
+}
+
+function msToTime(s) {
+ var ms = s % 1000;
+ s = (s - ms) / 1000;
+ var secs = s % 60;
+ s = (s - secs) / 60;
+ var mins = s % 60;
+ var hrs = (s - mins) / 60;
+
+ return pad(hrs) + ':' + pad(mins) + ':' + pad(secs)
+}
+
+module.exports = (lang) => {
+ console.log("Reading files at /train/" + lang + "/...");
+ files = fs.readdirSync("./train/" + lang);
+
+ files.forEach((file, index) => {
+ console.log("Processing file /train/" + lang + "/" + file);
+ content = fs.readFileSync("./train/" + lang + "/" + file).toString();
+ sentences = content.match(/([^\.!\?]+[\.!\?]+)|([^\.!\?]+$)/g);
+ total = sentences.length;
+ done = 0;
+ sentences.forEach((e) => {
+ ccold = new Date();
+ api(e, lang, true);
+ ccrec = new Date();
+ ccdiff = ccrec - ccold;
+ if ((done / 50) == Math.round(done / 50)) {
+ cceta = ccdiff * (total - done);
+ }
+ console.log(lang + " - " + pad(done, total.toString().length) + "/" + total + " (" + pad(Math.round((done/total)*100), 3) + "%, " + pad(total - done, total.toString().length) + ") - " + pad(index + 1, files.length.toString().length) + "/" + files.length + " - " + msToTime(cceta) + " - " + msToTime((cceta) * (__train_totallangs - __train_donelangs)));
+ done++;
+ })
+ })
+} \ No newline at end of file