-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess
209 lines (142 loc) · 4.19 KB
/
preprocess
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
#!/bin/bash
#===============================================================================
# USAGE: ./preprocess <judgeclass> <verbose> <topic> <query>
#
# DESCRIPTION: Creates and loads start up files, creates seed trainsets.
#===============================================================================
source "${UTIL_PATH}/handle_errors"
source "${UTIL_PATH}/colors"
JUDGECLASS=$1; shift
VERBOSE=false; [[ $1 == "true" ]] && VERBOSE=true; shift
TOPIC=$1; shift
QUERY=$1; shift
#----------------------------------------------------------------------
# if data is already prepared, skips data extraction
#----------------------------------------------------------------------
if [ ! -f "${JUDGECLASS}.svm.fil" ]; then
pushd Corpus
e_primary "Preparing dataset (executing dofast)..."
./dofast "$JUDGECLASS" $VERBOSE
e_success "Done."
cp "$JUDGECLASS".df ../"$JUDGECLASS".df > /dev/null
cp "$JUDGECLASS".svm.fil ../"$JUDGECLASS".svm.fil
e_primary "Running feature compression SVD..."
../svd/./script_create_svd.sh ../$JUDGECLASS.svm.fil 10
e_success "Done."
popd
fi
RESULT_DIR="result/${JUDGECLASS}"
$VERBOSE && e_primary "Creating directories to store results..."
try
(
rm -rf "${RESULT_DIR}/${TOPIC}/"
mkdir -p "${RESULT_DIR}/${TOPIC}/"
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
$VERBOSE && e_primary "Creating topic directory..."
try
(
rm -rf $TOPIC
mkdir $TOPIC
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
$VERBOSE && e_primary "Creating goldendb..."
try
(
cat judgement/qrels.$JUDGECLASS.list \
| grep "$TOPIC" \
| cut -d' ' -f3 \
| sort > $TOPIC/goldendb
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
$VERBOSE && e_primary "Creating file with total number of docs..."
try
(
echo `wc -l < "$JUDGECLASS".svm.fil` > N
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
pushd $TOPIC
echo "$QUERY" > "$TOPIC".seed.doc
ln -n ../$JUDGECLASS.svm.fil $JUDGECLASS.svm.fil
$VERBOSE && echo "Preparing 'docfils' file with all documents..."
try
(
cut -d' ' -f1 ../$JUDGECLASS.svm.fil \
| sed -e 's/.*/& &/' > docfil
cut -d' ' -f1 docfil \
| cat -n > docfils
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
$VERBOSE && echo "Preparing auxiliary and result files..."
try
(
touch rel.$TOPIC.fil
touch prel.$TOPIC
rm -rf prevalence.rate
touch prevalence.rate
rm -rf rel.rate
touch rel.rate
rm -f new[0-9][0-9].$TOPIC tail[0-9][0-9].$TOPIC self*.$TOPIC gold*.$TOPIC
touch new00.$TOPIC
touch seed
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
cp $TOPIC.seed.doc ../$TOPIC.seed.doc
popd
$VERBOSE && e_primary "Executing ./dofeaturesseed..."
./dofeaturesseed $TOPIC.seed.doc $TOPIC $JUDGECLASS $VERBOSE
$VERBOSE && e_success "Finished ./dofeaturesseed."
pushd $TOPIC
# TODO: Adds error detection here.
$VERBOSE && e_primary "Preparing ../$JUDGECLASS.svm.fil (runs ../dosplit)..."
sed -e 's/[^ ]*/0/' ../$JUDGECLASS.svm.fil \
| ../dosplit
$VERBOSE && e_success "Done."
$VERBOSE && e_primary "Preparing $TOPIC.synthetic.seed..."
try
(
sed -e 's/[^ ]*/1/' svm.$TOPIC.seed.doc.fil > $TOPIC.synthetic.seed
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
#-------------------------------------------------------------------------
# set kissdb parameters and execute it if database doesn't exists
#-------------------------------------------------------------------------
KEYSIZE=$(awk 'BEGIN{a=0}{len = length($1); a=a<len?len:a}END{print a}' \
$JUDGECLASS.svm.fil)
VALSIZE=$(awk 'BEGIN{a=0}{len = length($0); a=a<len?len:a}END{print a}' \
$JUDGECLASS.svm.fil)
export KEYSIZE=$((KEYSIZE+2))
export VALSIZE=$((VALSIZE+2))
if [ ! -f "../$JUDGECLASS.db" ]; then
$VERBOSE && e_primary "Indexing $JUDGECLASS, keysize = $KEYSIZE, valsize = $VALSIZE"
try
(
../indexer $JUDGECLASS.svm.fil "$JUDGECLASS".db $KEYSIZE $VALSIZE
) 2> $STD_ERROR_OUT
catch || {
exit_on_error
}
$VERBOSE && e_success "Done."
fi
popd