-
Notifications
You must be signed in to change notification settings - Fork 0
/
stanfordNER.js
62 lines (49 loc) · 1.52 KB
/
stanfordNER.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
52
53
54
55
56
57
58
59
60
61
62
var fs = require('fs'),
path = require('path'),
db = require('diskdb'),
_ = require('lodash'),
async = require('async'),
mkdirp = require('mkdirp'),
publicEye = require('public-eye')(),
storage = db.connect(__dirname + '/contents', ['records']);
// console.log()
var total = db.records.count();
var q = async.queue(function(filepath, nextFile) {
console.log('remaining: ', q.length(),'/', total);
async.waterfall([
function getContents(next) {
console.log('-- reading file: ', filepath)
fs.readFile(filepath, {encoding: 'utf8'}, next);
},
function(contents, next) {
console.log('-- parsing with stanfordNER file: ', filepath);
publicEye.stanfordNER({
text: contents
}, next);
},
function(response, next) {
var outdir = path.join(path.dirname(filepath), 'NER'),
outpath = path.join(outdir, path.basename(filepath) + '.NER.json');
console.log('-- storing stanfordNER responses in: ', outpath);
mkdirp(outdir, function (err) {
if (err)
next(err);
else
fs.writeFile(outpath, JSON.stringify({
annotated: response.raw,
entities:response.entities
}, null, 2), next);
});
}
], function(err) {
if(err) {
q.kill();
console.error(err)
}
nextFile();
});
}, 3);
q.push(_.map(db.records.find(), 'src'))
q.drain = function() {
console.log('oh, yeh');
}