-
Notifications
You must be signed in to change notification settings - Fork 0
/
obtainTermList.py
82 lines (71 loc) · 1.6 KB
/
obtainTermList.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import sys
import numpy as np
#Getting command line input
inputFile1 = sys.argv[1]
inputFile2 = sys.argv[2]
stopWordFile = sys.argv[3]
outputFile = sys.argv[4]
#Reading stop words for processing queries
stopWords = {}
f = open(stopWordFile)
for line in f:
stopWords[line.strip()] = ''
f.close()
#Reading input file 1 and preparing term list
iterCount = 0
termList = {}
print ('Reading Input file 1')
f = open(inputFile1)
for line in f:
iterCount += 1
if(iterCount % 10000 == 0):
print '.',
lineParts = line.split('||')
tq = lineParts[0].strip()
hq = lineParts[1].strip()
#Processing stopWords and collecting termlist
for word in tq.split():
if(word in stopWords):
continue
else:
if(word not in termList):
termList[word] = ''
for word in hq.split():
if(word in stopWords):
continue
else:
if(word not in termList):
termList[word] = ''
f.close()
#Reading input file 2 and adding to the term list
iterCount = 0
print ('')
print ('Reading Input file 2')
f = open(inputFile2)
for line in f:
iterCount += 1
if(iterCount % 10000 == 0):
print '.',
lineParts = line.split('||')
tq = lineParts[0].strip()
hq = lineParts[1].strip()
#Processing stopWords and collecting termlist
for word in tq.split():
if(word in stopWords):
continue
else:
if(word not in termList):
termList[word] = ''
for word in hq.split():
if(word in stopWords):
continue
else:
if(word not in termList):
termList[word] = ''
f.close()
#Print the termList to get vectors from the main file
f = open(outputFile, 'w')
for term in termList:
f.write(term.strip() + '\n')
f.close()