-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlda.js
50 lines (28 loc) · 1.05 KB
/
lda.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
var lda = require('lda');
// Example document.
async function ldaGenerator(text, topics , terms ){
// console.log('lda gen called');
// //var text = 'Cats are small. Dogs are big. Cats like to chase mice. Dogs like to eat bones.';
// // Extract sentences.
// var documents = text.match( /[^\.!\?]+[\.!\?]+/g );
// // Run LDA to get terms for 2 topics (5 terms each).
// resolvelda(documents, topics , terms).then(function(value) {
// console.log(value);
// // expected output: Array [1, 2, 3]
// });
// return result;
}
function resolvelda(text, topics , terms) {
// Extract sentences.
var documents = text.match( /[^\.!\?]+[\.!\?]+/g );
return new Promise(resolve => {
resolve(getfdata(documents, topics , terms));
});
};
var getfdata = (documents, topics , terms) => {
var fs = require('fs');
var json = JSON.stringify(lda(documents, topics , terms));
fs.writeFile('lda.json', json, 'utf8', () => console.log('writing complete'));
return true;
}
module.exports = resolvelda;