-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomqueryfromfile.py
34 lines (34 loc) · 978 Bytes
/
randomqueryfromfile.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
import random
from random_words import RandomWords
rw = RandomWords()
count = 0
writeword = ""
file = open("sampled.txt", "r")
queries = open("queryfromfile.txt", "a")
for line in file:
data = ""
cont = 0
if "review/text" in line:
tokens = line.split()
for i in range(random.randint(3, 10)):
myword = random.choice(tokens)
writeword = myword
if i == 0:
if myword.isalpha():
queries.write(myword)
else:
queries.write(str(rw.random_words()[0]))
else:
if myword.isalpha():
queries.write(" ")
queries.write(myword)
else:
queries.write(" ")
queries.write(str(rw.random_words()[0]))
if count == 50000:
break
count = count + 1
queries.write("\n")
print(count)
file.close()
queries.close()