forked from multimeric/wordnet-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupOMW.js
33 lines (27 loc) · 902 Bytes
/
setupOMW.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
#!/usr/bin/env node
const _ = require('lodash');
const fs = require('fs');
const readline = require('readline');
const sqlite3 = require('sqlite3').verbose();
//Make the database and run it serially
var db = new sqlite3.Database('wordnet.dict');
db.serialize(function () {
db.run("BEGIN TRANSACTION");
//Prepare the insert statement
var stmt = db.prepare("UPDATE words SET fr = IFNULL(fr || ' ; ' || ?, ?) WHERE id = ?;");
//Read each line of the file
var rl = readline.createInterface({input: fs.createReadStream('omw/fra/wn-data-fra.tab')});
var rows = 0;
rl.on('line', function (line) {
var sections = line.split(/ /);
stmt.run(sections[1], sections[1], sections[0]);
rows++;
});
rl.on('close', function () {
stmt.finalize(()=>{
db.run("END");
db.exec("VACUUM");
db.close();
});
});
});