-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-morph-tester.sh.in
executable file
·317 lines (300 loc) · 10.2 KB
/
run-morph-tester.sh.in
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
# @configure_input@
# This is a shell script that will take one test file
# and run it through the Apertium Quality morph-test.py tool, using Xerox
# or Hfst transducers to the extent found.
#
# It takes three arguments: the transducer type, the file to be tested
# and the text to precede each output line, e.g.
# test run number.
#
# The script is typically sourced by another shell script listed in the TESTS
# variable in the Makefile.am file. This other shell script identifies the fst
# and the test file to be used.
#
# This file must be processed by ./configure before being used.
echo "DEPRECATED run-morph-tester.sh MAYBE CALLED FROM $0"
# Wrong usage - short instruction:
if ! test $# -ge 5 ; then
echo
echo "Usage: $0 TRANSDUCERTYPE TESTFILE RELPATH HALFTEST LEADTEXT"
echo
echo "were:"
echo " TRANSDUCERTYPE is the type of transducer targeted for testing,"
echo " gt-norm, gt-desc, etc., and the optional"
echo " TESTFILE is either a LexC file or a Yaml test data file, both"
echo " containing test data."
echo " RELPATH gives the relative path between the calling"
echo " script and this script, and is used several places to"
echo " find the correct location of required files."
echo " HALFTEST is a string with one of the values 'ana', 'gen' or 'full',"
echo " indicating that only the analyser, only the generator,"
echo " or both are tested, respectively."
echo " FSTTEST specifies whether all or only some fst types should be"
echo " tested. Possible values are 'all' and 'specified'."
echo " LEADTEXT is typically the number of the test in a test set loop."
echo
echo "LEADTEXT can contain spaces, it is effectively everything after the"
echo "fourth argument."
echo
exit 77
fi
###### Variables: #######
transducer=$1
testfile=$2
relpath=$3
halftest=$4
fsttest=$5
shift 5
leadtext="$@"
testfileshort=$(echo "$(basename \
$(dirname $testfile))/$(basename $testfile)")
# Identify the relative subdirs where the fst's are built by:
# getting the root test dir in the source tree ($GTLANG/test/):
roottestdir="$(cd "$(dirname "$srcdir/$relpath")"/.. && pwd)/"
# getting the absolute path of the $srcdir of the test script:
abs_srcdir=$(cd $srcdir && pwd)
# subtracting the root test dir from the test script source dir - the
# remaining intervening dirs equals the path to the fst dir as long as the
# directory structure within $GTLANG/test/ mirrors the structure of the other
# directories - this mirroring thus becomes imperative for the yaml testing:
#fstdir=${abs_srcdir:${#roottestdir}:${#roottestdir}}/fst/
fstdir=${abs_srcdir%/test}
# The analyser files are built $relpath relative to the test dir, one further
# dir up, and then in the identified fst dir (see above):
analyserfile=$fstdir/analyser-$transducer
generatorfile=$fstdir/generator-$transducer
bare_fst_file=$fstdir/$transducer
pythonbin=@PYTHON@
runtests="$pythonbin @GTCORE@/scripts/morph-test.py"
testtotalsfile=testtotals.tmp.txt
# Use autotools mechanisms to only run the configured fst types in the tests:
fsttype=
@CAN_HFST_TRUE@fsttype="$fsttype hfst"
@CAN_XFST_TRUE@fsttype="$fsttype xfst"
@CAN_FOMA_TRUE@fsttype="$fsttype foma"
# Exit if all fst types have been shut off:
if [[ "x$fsttype" == "x" ]]; then
echo "All transducer types have been shut off at configure time."
echo "Nothing to test. SKIPPED."
exit 77
fi
# Construct the correct argument for running either analysis, generation or
# both tests
if test "$halftest" == "ana" \
-o "$halftest" == "speller"; then
halftestoption="--surface"
elif test "$halftest" == "gen"; then
halftestoption="--lexical"
else
halftestoption=""
fi
if test "x$fsttest" == "xspecified"; then
if test "$halftest" == "ana" \
-o "$halftest" == "gen"; then
filebasename=$(basename -s .yaml $testfile)
removed_halftestsuff=${filebasename%*.}
testfst=${removed_halftestsuff#*.}
else
filebasename=$(basename -s .yaml $testfile)
testfst=${filebasename#*.}
fi
fi
# Debugging only; the variable contains the string of the fst type to be the
# only one included (e.g. "hfst") or the one to be excluded (e.g. "~xfst"):
# echo "testfst 114: $testfst"
function run_tests() {
# --output final/terse/compact/normal - OR:
# --silent
outputformat="--output final"
if [ ! "$outputformat" == "--silent" ]; then
if [ ! "$outputformat" == "--output final" ]; then
echo
fi
fi
$runtests \
--colour \
$outputformat \
--ignore-extra-analyses \
--section $section \
--app "$lookuptool" \
$fstoptions \
$halftestoption \
$testfile | tee -a $testtotalsfile
exitv=$( echo ${PIPESTATUS[0]} )
# If the test failed, print instructions to rerun and get more details:
if [[ $exitv -gt 0 ]]; then
let "Fail += 1"
printf "\033[1;31mFAIL\033[m\n"
echo
printf "To rerun with more details, please triple-click, copy and paste"
echo " the following:"
echo
echo "pushd $(pwd); $runtests -c -i -v -p -S $section \
--app \"$lookuptool\" $fstoptions $halftestoption $testfile; popd"
echo
else
if [ "$outputformat" == "--silent" \
-o "$outputformat" == "--output final" ]; then
printf "\033[0;32mPASS\033[m\n"
fi
fi
}
###### Start testing: #######
transducer_found=0
# Loop over the transducer types first - we test both hfst, xfst and foma
# according to the configuration:
for f in $fsttype; do
# DEBUG: echo "Fst type 161: $f"
# Check whether to test only against certain fst types:
if test "$fsttest" == "specified"; then
# run yaml test if $f is identical to the requested type:
if test "$f" == "$testfst"; then
# DEBUG: echo "Match! $f = $testfst"
true
# or different from the negated type:
elif [[ "$testfst" == ~* ]]; then
# Remove the tilde:
bare_testfst=${testfst#\~}
# If we don't have a match, we can run the test:
if test "x$f" != "x$bare_testfst"; then
# DEBUG: echo "Negative match! $f != $bare_testfst"
true
# Otherwise, just continue:
else
# DEBUG: echo "Should we exit here? 178"
continue
fi
# else go to the next fst type:
else
# DEBUG: echo "Continue!"
continue
fi
fi # test "$fsttest" == "specified"
# DEBUG: echo "Fst loop 187: $f"
# Remember to empty the variables between each for loop:
analyser=""
generator=""
if test $f == "xfst"; then
lookuptool="@LOOKUP@ -flags mbTT"
section="xerox"
fstsuffix="xfst"
elif test $f == "foma"; then
lookuptool="@FLOOKUP@"
section="xfst"
fstsuffix="foma"
elif test $f == "hfst"; then
lookuptool="@HFST_LOOKUP@"
fastlookup="@HFST_OPTIMIZED_LOOKUP@"
section="hfst"
fstsuffix="hfstol hfst"
else
let "Fail += 1"
echo "FAIL: Unknown fst type! FST=$f"
continue
fi
# Check whether the actual fst's exist, run the tests if true, FAIL if not:
# First check for analysis tests only:
if test "$halftest" == "ana" ; then
for suff in $fstsuffix; do
echo debug trying $analyserfile.$suff
if test -f "$analyserfile.$suff"; then
analyser=$analyserfile.$suff
let "transducer_found += 1"
if test "$suff" == "hfstol" ; then
lookuptool=$fastlookup
fi
break
fi
done
# Only start a test run if an analyser was found:
if test "x$analyser" != "x" ; then
printf "$leadtext $(basename $analyser) + $testfileshort - "
fstoptions="--morph $analyser"
run_tests
fi
# Then check for generation tests only:
elif test "$halftest" == "gen" ; then
for suff in $fstsuffix; do
# Regular word form generation tests:
echo debug trying $generatorfile.$suff
echo maybe $bare_fst_file.lookup.$suff
if test -f "$generatorfile.$suff"; then
generator=$generatorfile.$suff
let "transducer_found += 1"
if test "$suff" == "hfstol" ; then
lookuptool=$fastlookup
fi
break
# Generation tests for rule fst's:
elif test -f "$bare_fst_file.lookup.$suff"; then
generator=$bare_fst_file.lookup.$suff
let "transducer_found += 1"
if test "$suff" == "hfstol" ; then
lookuptool=$fastlookup
fi
break
fi
done
# Only start a test run if a generator was found:
if test "x$generator" != "x" ; then
printf "$leadtext $(basename $generator) + $testfileshort - "
fstoptions="--gen $generator"
run_tests
fi
# Then check for speller acceptor tests:
elif test "$halftest" == "speller" ; then
for suff in $fstsuffix; do
echo debug trying $bare_fst_file.$suff
if test -f "$bare_fst_file.$suff"; then
analyser=$bare_fst_file.$suff
let "transducer_found += 1"
lookuptool=$fastlookup
break
fi
done
# Only start a test run if an analyser was found:
if test "x$analyser" != "x" ; then
printf "$leadtext $(basename $analyser) + $testfileshort - "
fstoptions="--morph $analyser"
run_tests
fi
# Finally check the full analysis + generation tests:
elif test "$halftest" == "full" ; then
for suff in $fstsuffix; do
echo debug trying $analyserfile.$suff and $generatorfile.$suff
if test -f "$analyserfile.$suff" \
-a -f "$generatorfile.$suff"; then
analyser=$analyserfile.$suff
generator=$generatorfile.$suff
let "transducer_found += 1"
if test "$suff" == "hfstol" ; then
lookuptool=$fastlookup
fi
break
fi
done
# Only start a test run if an analyser and a generator was found:
if test "x$analyser" != "x" -a "x$generator" != "x" ; then
printf "$leadtext $(basename $analyser) + $testfileshort - "
fstoptions="--morph $analyser --gen $generator"
run_tests
fi
# FAIL - no fst found:
else
let "Fail += 1"
if test "$halftest" == "ana" -o "$halftest" == "full"; then
echo "FAIL: Analyser file not found! $(basename $analyser)"
echo "FAIL: $analyser"
fi
if test "$halftest" == "gen" -o "$halftest" == "full"; then
echo "FAIL: Generator file not found! $(basename $generator)"
echo "FAIL: full path: $generator"
fi
echo "FAIL: referenced by: $testfileshort"
echo "FAIL: in $(pwd)"
echo "FAIL: testtype: $halftest"
continue
fi
done
echo "DEPRECATED run-morph-tester.sh MAYBE CALLED FROM $0"