-
Notifications
You must be signed in to change notification settings - Fork 2
/
HW2-Group8.sh
238 lines (199 loc) · 6.24 KB
/
HW2-Group8.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#--------------------------------------------------------
## Web Search Engines - Homework 2 - Group 8
##
## @desc: This script builds the index, starts server
## and outputs their evaluations for all the
## queries in data/queries.tsv
## @author: Sanchit Mehta<[email protected]>
#--------------------------------------------------------
#!/bin/sh
red='\033[0;31m'
green='\033[1;32m'
yellow='\033[01;33m'
bold='\033[1m'
blue='\033[0;34m'
NC='\033[0m' # No Color
#Creates TestOutput dir if it doesn't exist
mkdir -p TestOutputs
rm -r TestOutputs/* &> /dev/null
compile_code () {
printf "\nCompiling Java Code\n"
{
javac -cp lib/* src/edu/nyu/cs/cs2580/*.java
} &> /dev/null
STATUS=$?
if [ $STATUS -eq 0 ]; then
printf "\n\n${green}Java Build Successful${NC}\n\n"
else
printf "\n\n${red}Java Build Failed${NC}\n\n"
exit 1
fi
}
run_indexer () {
date -u
printf "\nCreating search Index\n"
{
java -cp "src:lib/*" edu.nyu.cs.cs2580.SearchEngine --mode=index --options=conf/engine.conf
} &> /dev/null
STATUS=$?
if [ $STATUS -eq 0 ]; then
printf "\n\n${green}Search Index Created${NC}\n\n"
else
printf "\n\n${red}Index Creation Failed${NC}\n\n"
exit 1
fi
date -u
}
start_server () {
printf "\nStarting Java Search Engine Server\n"
{
ps aux | grep 25808 | awk '{print $2}' |xargs kill -9
java -cp src -Xmx512m edu.nyu.cs.cs2580.SearchEngine --mode=serve --port=25808 --options=conf/engine.conf &
#storing PID of the server process,to shut it down later
echo $! > java_pid
} &> /dev/null
STATUS=$?
if [ $STATUS -eq 0 ]; then
#waiting until the server has started
url=http://localhost:25808/
printf "Loading Index "
until curl --output /dev/null --silent "$url"; do
printf '.'
sleep 2
done
printf "\n\n${green}Server Started${NC}\n\n"
else
printf "\n\n${red}Initialising Server Encountered an error${NC}\n\n"
exit 1
fi
}
test () {
printf "\nStarting Test Case Execution\n"
run_query () {
q=$1
r=$2
q="${q// /+}"
if [[ ! -z $r ]]
then
curl "http://localhost:25808/search?query=$q&ranker=$r&format=text&num=10"
fi
}
evaluate () {
q=$1
r=$2
printf "$q\t"
q="${q// /+}"
n=10
for i in $(seq 0 6)
do
if [[ ! -z $r ]]
then
#1000 Results for Precision at Recall Points
if [[ $i == 3 ]]
then
n="all"
fi
curl "http://localhost:25808/search?query=$q&ranker=$r&format=text&num=$n" | java -cp src edu.nyu.cs.cs2580.Evaluator data/labels.tsv $i | awk -F "\t" '{print $2}' | tr '\n' '\t'
n=10
fi
done
printf "\n\n"
}
filename="data/queries.tsv"
while read -r line
do
query="$line"
printf "\n\nQuery : ${blue}$query${NC}"
printf "\nRunning QL Ranker"
{
run_query "$query" "ql"
} >> TestOutputs/hw1.1-ql.tsv 2>&0
printf "\nRunning Cosine Ranker"
{
run_query "$query" "cosine"
} >> TestOutputs/hw1.1-vsm.tsv 2>&0
printf "\nRunning Phrase Ranker"
{
run_query "$query" "phrase"
} >> TestOutputs/hw1.1-phrase.tsv 2>&0
printf "\nRunning Linear Ranker"
{
run_query "$query" "linear"
} >> TestOutputs/hw1.2-linear.tsv 2>&0
printf "\nRunning Numviews Ranker"
{
run_query "$query" "numviews"
} >> TestOutputs/hw1.1-numviews.tsv 2>&0
printf "\nEvaluating vsm ranker"
{
evaluate "$query" "cosine"
} >> TestOutputs/hw1.3-vsm.tsv 2>&0
printf "\nEvaluating ql ranker"
{
evaluate "$query" "ql"
} >> TestOutputs/hw1.3-ql.tsv 2>&0
printf "\nEvaluating numviews ranker"
{
evaluate "$query" "ql"
} >> TestOutputs/hw1.3-numviews.tsv 2>&0
printf "\nEvaluating phrase ranker"
{
evaluate "$query" "phrase"
} >> TestOutputs/hw1.3-phrase.tsv 2>&0
done < "$filename"
}
shut_server () {
printf "\n\nShuting down Java Server\n"
{
value=`cat java_pid`
kill $value
} &> /dev/null
STATUS=$?
if [ $STATUS -eq 0 ]; then
printf "\n\n${green}Server Stopped${NC}\n\n"
else
printf "\n\n${red}Error in shutting down the server${NC}\n\n"
exit 1
fi
rm java_pid
}
usage () {
printf "\n\nUsage: `basename $0` \n-- This is a utility script for server commands and test execution\n\nCommands: [-r] [-t] [-s] [--run] [--stop] [--test]\n\nwhere:\n-r\tcompiles code, sets up index and runs the java server\n-t\tcompiles code, starts server, indexes and generates the output cases\n-s\tstops the java server\n\n"
}
if [ "$1" == "" ]; then
usage
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
-r | --run ) shift
printf "\n\n${bold}${yellow}CSGA-2580 - Group 8 - Server Runner${NC}\n\n"
compile_code
run_indexer
start_server
;;
-s | --stop )
printf "\n\n${bold}${yellow}CSGA-2580 - Group 8 - Stop Processor${NC}\n\n"
shut_server
;;
-t | --test )
printf "\n\n${bold}${yellow}CSGA-2580 - Group 8 - Test Output Files Generator${NC}\n\n"
compile_code
run_indexer
start_server
test
shut_server
printf "\nTest case execution ${green}completed!${NC} Output files generated in ${bold}./TestOutputs${NC}\n"
;;
-h | --help )
usage
exit
;;
* )
usage
exit 1
;;
esac
shift
done
exit 0