-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
51 lines (44 loc) · 1.59 KB
/
app.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
const express = require('express');
const path = require('path');
const app = express();
var bodyParser = require('body-parser');
const embeddings = require('./embeddings');
const cosine_similarity = require('./cosine_similarity');
const word_analogies = require('./word_analogies');
const visualization = require('./visualization');
const port = process.env.PORT || 3000;
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res) {
res.sendFile(__dirname+'/index.html')
});
app.post('/extraction', function(req, res){
let glove_embeddings = embeddings()
let word = req.body.word1;
extracted_vect = glove_embeddings[word]
res.send({name: extracted_vect});
})
app.post('/similarity', function(req, res){
let glove_embeddings = embeddings()
let word1 = req.body.word1;
let word2 = req.body.word2;
let extracted_vect1 = glove_embeddings[word1];
let extracted_vect2 = glove_embeddings[word2];
let similarity = cosine_similarity(extracted_vect1, extracted_vect2);
res.send({name: similarity});
})
app.post('/word_analogy', function(req, res){
let word1 = req.body.word1;
let word2 = req.body.word2;
let word3 = req.body.word3;
let word_analogy = word_analogies(word1, word2, word3);
res.send({name: word_analogy});
})
app.post('/visualization', function(req, res){
let word1 = req.body.word1;
let vis = visualization(word1);
res.send({dr_data: vis.data, words: vis.words});
})
app.listen(port, function() {
console.log(`App listening on port ${port}!`);
})