-
Notifications
You must be signed in to change notification settings - Fork 0
/
waldo.js
96 lines (81 loc) · 2.88 KB
/
waldo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var fs = require("fs"),
geode = require("geode"),
q = require("q"),
_ = require("underscore"),
document = require("./models/document"),
utils = require("./util/utils");
//var prepositions = fs.readFileSync("grammar-prepositions.txt").toString().split("\n");
var docs = [];
module.exports = {
addDocument: function(doc, success) {
var self = this;
docs.push(new document(doc));
utils.fire(success, docs);
return this;
},
clearDocuments: function(success) {
docs = [];
utils.fire(success, docs);
return this;
},
getDocuments: function(callback) {
utils.fire(callback, docs);
return this;
},
extractLocations: function(username, success) {
var self = this;
var defs = [];
var all_tokens = [];
defs.push(q.fcall(function() {
self.getTokens(false, function(tokens) {
console.log(tokens);
all_tokens = tokens;
});
}));
var cap_nouns = [];
/*
defs.push(q.fcall(self.getNouns(function(nouns) {
self.getCapitalizedTokens(nouns, function(cappedNouns) {
cap_nouns = cappedNouns;
});
})));*/
q.all(defs).then(function() {
//console.log(all_tokens);
//console.log(cap_nouns);
utils.fire(success, null);
});
//console.log(prepositions);
/*
var upperCaseTokens = _.filter(tokens, function(token) {
return (token[0] === token[0].toUpperCase());
});
console.log(upperCaseTokens);
*/
/*
var geo = new geode(username);
geo.search({ q: "london", maxRows: 10 }, function(err, results) {
utils.fire(success, results);
});
*/
//return this;
var items = [];
_.each(docs, function(doc) {
doc.words(function(words) {
items.push(_.chain(words).uniq(function(item) {
return item.text;
}).filter(function(item) {
return (
(utils.isProperNoun(item) || (utils.isNoun(item) && item.related().length > 0))
&& item.occurrence() <= 2 && item.confidence() >= 8);
}).value());
});
});
_.chain(items).flatten().each(function(word) {
console.log(word.text + " - " + word.tag);
_.each(word.related(), function(related) {
console.log("--> " + related.text + " - " + related.weight);
});
console.log("--> weight= " + word.weight() + ", occ= " + word.occurrence() + ", conf= " + word.confidence());
});
}
};