-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.sh
174 lines (137 loc) · 2.59 KB
/
pipeline.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
#!/bin/bash
usage="
$(basename $0) -l -t [-o] [-p] [-i] [-s] [-r] [-m] [-c]
script to run full pipeline: main_iterative.py, extractor.py, refiner.py.
arguments:
-l
path to excel file containing links
-t
path to csv file containing search terms
options:
-h
show this help message and exit
-o
output directory
default=./data
-p
number of pools for multiprocessing
default=0 (no multiprocessing)
-i
scraper iteration depth
default=2
-s
scraper HTML size cutoff
default=1000
-r
scraper retry cutoff
default=10
-m
extractor sentences plus minus
default=5
-c
use google webcaching when direct scrape fails past cutoff (toggle true)
"
#
#
# Parse arguments using getopts
#
#
links=''
search_terms=''
outdir='./data'
pools=0
iterations=2
size_cutoff=1000
retry_cutoff=10
plusminus=5
webcache=false
while getopts "hl:t:o:p:i:s:r:m:c" flag; do
case $flag in
h) printf "$usage"; exit;;
l) links=$OPTARG;;
t) search_terms=$OPTARG;;
o) outdir=$OPTARG;;
p) pools=$OPTARG;;
i) iterations=$OPTARG;;
s) size_cutoff=$OPTARG;;
r) retry_cutoff=$OPTARG;;
m) plusminus=$OPTARG;;
c) webcache=true;;
esac
done
#
#
# Validate arguments
#
#
if [ -z "$links" ]; then
printf "error: missing required argument -- l " >&2
exit 1
fi
if ! test -f $links; then
printf "error: file '$links' does not exist " >&2
exit 1
fi
if [ -z "$search_terms" ]; then
printf "error: missing required argument -- t " >&2
exit 1
fi
if ! test -f $search_terms; then
printf "error: file '$search_terms' does not exist " >&2
exit 1
fi
#
#
# Echo pipeline arguments
#
#
printf "
Links: $links
Search terms: $search_terms
Output directory: $outdir
Pools: $pools
Iterations: $iterations
HTML size cutoff: $size_cutoff
Retry cutoff: $retry_cutoff
Sentences plus minus: $plusminus
Use webcache: $webcache
Running pipeline..."
#
#
# Main Iterative
#
#
printf "
==========Main Iterative==========
"
if [ $webcache = true ]; then
python3 main_iterative.py $links $search_terms -d $outdir -p $pools -i $iterations -s $size_cutoff -r $retry_cutoff -c
else
python3 main_iterative.py $links $search_terms -d $outdir -p $pools -i $iterations -s $size_cutoff -r $retry_cutoff
fi
#
#
# Extractor
#
#
printf "
==========Extractor==========
"
python3 extractor.py $outdir -p $pools
#
#
# Refiner
#
#
printf "
==========Refiner==========
"
python3 refiner.py $outdir $search_terms -p $pools -s $plusminus
#
#
# Done
#
#
printf "
Pipeline done.
"