-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (26 loc) · 830 Bytes
/
index.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
const path = require('path');
const esql = require('sql-extra');
const columns = require('@ifct2017/columns');
var corpus = null;
function load() {
if (corpus) return corpus;
columns.load();
corpus = require('./corpus');
return corpus;
}
function csv() {
return path.join(__dirname, 'index.csv');
}
function sql(tab='intakes', opt={}) {
return esql.setupTable(tab, {code: 'TEXT', whorda: 'REAL', usear: 'REAL', usrdam: 'REAL',
usrdaf: 'REAL', euprim: 'REAL', euprif: 'REAL', ulus: 'REAL', uleu: 'REAL', uljapan: 'REAL'},
load().values(), Object.assign({pk: 'code', index: true, tsvector: {code: 'A'}}, opt));
}
function intakes(txt) {
if (!corpus) load();
return columns(txt).map(r => corpus.get(r.code));
}
intakes.load = load;
intakes.csv = csv;
intakes.sql = sql;
module.exports = intakes;