-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordCount.py
More file actions
79 lines (64 loc) · 2.05 KB
/
Copy pathwordCount.py
File metadata and controls
79 lines (64 loc) · 2.05 KB
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
from twitter import *
import re
#trends = trendsByLocation("United States")
#query = trends[1]# '"' + '" OR "'.join(trends) + '"'
#print trends[1]
#tweetss = tweets(query, count=1000)
#for tweet in tweetss:
# print tweet
# MapReduce word count
def isSignificant(word):
return word.lower() not in [u'there',u'this',u'that',u'also',u'with',u'then',u'your',u'during',u'than']
def wordCount(tweetsList):
words = []
for tweet in tweetsList:
words.extend(re.findall(r'(?:(?:https?://t\.co/)|[@#]?)\w+', tweet[0]))
d = {}
for word in words:
if word.lower() not in d and len(word) > 3 and not word.startswith('http') and isSignificant(word):
ct = words.count(word)
d[word.lower()] = ct
return d
def locCount(locationList):
locations = []
print "LOCATION LIST:"
print locationList
for location in locationList:
locations.append(location[1])
print locations
e = []
for location in locations:
if location not in e:
if location != "":
e.append((locations.count(location), location.lower()))
return e
def dictListRev(dictionary):
swag = []
# print len(dictionary)
for k, v in dictionary.iteritems():
swag.append((v, k))
swag = sorted(swag,reverse=True)
return swag
#wordCount = wordCount(tweetss)
#print(json.dumps(wordCount, sort_keys=True, \
# indent=4, separators=(',', ': ')) )
#listResults = dictListRev(wordCount)[0:10]
#print listResults
#x = [v for k, v in listResults[1:]]
#y = [k for k, v in listResults[1:]]
def maxIndex(L):
max = 0
maxdex = -1
for i in xrange(len(L)):
if L[i] > max:
max = L[i]
maxdex = i
return maxdex
def closeMatch(comWords, tweetsList):
scoreboard = [0 for tweet in tweetsList]
for (count, word) in comWords[1:]:
for (i, tweet) in enumerate(tweetsList):
if word in tweet:
scoreboard[i] += count
return tweetsList[maxIndex(scoreboard)]
#repTweet = closeMatch(listResults, tweetss)