-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (37 loc) · 1.19 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
const { ExtractorEnum } = require('@nlpjs/ner');
const XLSX = require('xlsx');
const express = require('express');
var parseUrl = require('body-parser');
const app = express();
const loadXlsx = (path, columnIndex) => {
const workbook = XLSX.readFile(path);
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
const columnA = [];
for (let z in worksheet) {
if(z.toString()[0] === columnIndex){
columnA.push(worksheet[z].v);
}
}
return columnA;
}
const fetchMatchedCnt = (data, keyword) => {
const similar = new ExtractorEnum();
return data.reduce((sum, cur) => {
const nlpMatched = similar.getBestSubstringList(cur, keyword);
const matchedCnt = nlpMatched.filter(o => o.levenshtein === 0).length;
sum += matchedCnt;
return sum;
}, sum = 0);
}
let encodeUrl = parseUrl.urlencoded({ extended: false });
app.get('/', (req, res) => {
res.sendFile(__dirname + '/form.html');
});
app.post('/', encodeUrl, (req, res) => {
console.log('Form request:', req.body);
const { keyword } = req.body;
const xlsxData = loadXlsx("./test.xls", "A");
const totalCnt = fetchMatchedCnt(xlsxData, keyword);
res.json({ keyword, totalCnt });
});
app.listen(4000);