-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-twitter.py
executable file
·64 lines (44 loc) · 1.38 KB
/
gen-twitter.py
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
#!/usr/bin/python
import os
import random
import re
import sys
if len(sys.argv) != 2:
print "Usage: python gen-twitter.py <numrecords>"
sys.exit(1)
def loadfile(filename):
handle = open(filename, 'r')
retval = []
for line in handle.readlines():
retval.append(line.strip())
return retval
def randomSentence(words, numwords):
tojoin = []
for i in range(0, numwords):
tojoin.append(words[random.randint(0, len(words)-1)])
return " ".join(tojoin)
if __name__ == "__main__":
names = []
words = []
if os.path.exists("/usr/share/dict/propernames"):
names = loadfile("/usr/share/dict/propernames")
else:
names = loadfile("/usr/share/dict/words")
words = loadfile("/usr/share/dict/words")
fmrinput = open("mapreduce-input.txt", 'w')
ftest = open("users-for-testing.txt", 'w')
ftrain = open("users-for-training.txt", 'w')
allusers = set()
for i in range(0, int(sys.argv[1])):
name = re.sub(" ", "", randomSentence(names, 2))
sentence = randomSentence(words, random.randint(10,20))
allusers.add(name)
fmrinput.write("%s\t%s\n" % (name, sentence))
for user in allusers:
ftest.write("%s\n" % (user))
if random.random() < .01:
ftrain.write("%s\n" % (user))
fmrinput.close()
ftest.close()
ftrain.close()
sys.exit(0)