-
Notifications
You must be signed in to change notification settings - Fork 0
/
twelpCheckName.js
49 lines (37 loc) · 1.37 KB
/
twelpCheckName.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
// **************************
// ****** DEPENDENCIES ******
// **************************
var _ = require('lodash');
var fs = require('fs');
var database = require('./api/database');
var proc = require('./util/process');
// **************************
// ******** PROGRAM ********
// **************************
var fromFile = './private/yelp/yelp_businesses-20140323T163547057Z.json';
var bizNames = JSON.parse(fs.readFileSync(fromFile));
bizNames = _.pluck(bizNames, 'name');
bizNames = _.uniq(_.map(bizNames, function(name) { return name.toLowerCase().trim(); }));
database.runWithConn(function() {
database.findTweets({}, function(err, tweets) {
if (err) {
proc.bail('Failed to find tweets', err);
}
tweets = _.map(tweets, function(tweet) {
tweet.words = tweet.text.toLowerCase().split(' ');
return tweet;
});
_.each(bizNames, function(name) {
var nameParts = name.split(' ');
var otherNameParts = name.replace("'", '').replace('-', '').split(' ');
var matchingTweets = _.filter(tweets, function(tweet) {
return _.difference(nameParts, tweet.words).length == 0 ||
_.difference(otherNameParts, tweet.words).length == 0;
});
if (matchingTweets.length > 0) {
var lengthStr = matchingTweets.length < 10 ? matchingTweets.length + ' ' : matchingTweets.length;
console.log(lengthStr + ' => ' + name);
}
});
});
});