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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
#!/bin/sh
FORMAT_TOOL=
COMPARE_TOOL=
COMPOSE_TOOL=
REGEXP_TOOL=
CONCATENATE_TOOL=
MINIMIZE_TOOL=
CONJUNCT_TOOL=
SUBTRACT_TOOL=
DISJUNCT_TOOL=
STRINGS2FST_TOOL=
FST2TXT_TOOL=
if [ "$1" = "--python" ]; then
FORMAT_TOOL="python3 ./hfst-format.py"
COMPARE_TOOL="python3 ./hfst-compare.py"
COMPOSE_TOOL="python3 ./hfst-compose.py"
REGEXP_TOOL="python3 ./hfst-regexp2fst.py"
CONCATENATE_TOOL="python3 ./hfst-concatenate.py"
MINIMIZE_TOOL="python3 ./hfst-minimize.py"
CONJUNCT_TOOL="python3 ./hfst-conjunct.py"
SUBTRACT_TOOL="python3 ./hfst-subtract.py"
DISJUNCT_TOOL="python3 ./hfst-disjunct.py"
STRINGS2FST_TOOL="python3 ./hfst-strings2fst.py"
FST2TXT_TOOL="python3 ./hfst-fst2txt.py"
else
TOOLDIR=../../tools/src/
FORMAT_TOOL=$TOOLDIR/hfst-format
COMPARE_TOOL=$TOOLDIR/hfst-compare
COMPOSE_TOOL=$TOOLDIR/hfst-compose
REGEXP_TOOL=$TOOLDIR/hfst-regexp2fst
CONCATENATE_TOOL=$TOOLDIR/hfst-concatenate
MINIMIZE_TOOL=$TOOLDIR/hfst-minimize
CONJUNCT_TOOL=$TOOLDIR/hfst-conjunct
SUBTRACT_TOOL=$TOOLDIR/hfst-subtract
DISJUNCT_TOOL=$TOOLDIR/hfst-disjunct
STRINGS2FST_TOOL=$TOOLDIR/hfst-strings2fst
FST2TXT_TOOL=$TOOLDIR/hfst-fst2txt
fi
for ext in .sfst .ofst .foma; do
FFLAG=
case $ext in
.sfst)
FFLAG="-f sfst"
if ! ($FORMAT_TOOL --list-formats | grep "sfst" > /dev/null) ; then
continue;
fi;;
.ofst)
FFLAG="-f openfst-tropical"
if ! ($FORMAT_TOOL --list-formats | grep "openfst-tropical" > /dev/null) ; then
continue;
fi;;
.foma)
FFLAG="-f foma"
if ! ($FORMAT_TOOL --list-formats | grep "foma" > /dev/null) ; then
continue;
fi;;
*)
FFLAG=;;
esac
# composition
# harmonization: [a:b] .o. [ID:ID] == [a:b]
if ! ($COMPOSE_TOOL a2b$ext id$ext | $COMPARE_TOOL -s a2b$ext); then
echo "compose #1" ${FFLAG}
exit 1;
fi
# harmonization: [ID:ID] .o. [a:b] == [a:b]
if ! ($COMPOSE_TOOL id$ext a2b$ext | $COMPARE_TOOL -s a2b$ext); then
echo "compose #2" ${FFLAG}
exit 1;
fi
# harmonization: [a:b] .o. [UNK:UNK | ID:ID] == [[a:a] | [a:b] | [a:UNK]]
if ! ($COMPOSE_TOOL a2b$ext unk2unk_or_id$ext | $COMPARE_TOOL -s a2a_or_a2b_or_a2unk$ext); then
echo "compose #3" ${FFLAG}
exit 1;
fi
# harmonization: [UNK:UNK | ID:ID] .o. [a:b] == [[a:b] | [b:b] | [UNK:b]]
if ! ($COMPOSE_TOOL unk2unk_or_id$ext a2b$ext | $COMPARE_TOOL -s a2b_or_b2b_or_unk2b$ext); then
echo "compose #4" ${FFLAG}
exit 1;
fi
# no harmonization: [a:b] .o. [ID:ID] == empty
if ! ($COMPOSE_TOOL -H a2b$ext id$ext | $COMPARE_TOOL -s empty$ext); then
echo "compose #5" ${FFLAG}
exit 1;
fi
# no harmonization: [ID:ID] .o. [a:b] == empty
if ! ($COMPOSE_TOOL -H id$ext a2b$ext | $COMPARE_TOOL -s empty$ext); then
echo "compose #6" ${FFLAG}
exit 1;
fi
# no harmonization: [a:b] .o. [UNK:UNK | ID:ID] == empty
if ! ($COMPOSE_TOOL -H a2b$ext unk2unk_or_id$ext | $COMPARE_TOOL -s empty$ext); then
echo "compose #7" ${FFLAG}
exit 1;
fi
# no harmonization: [UNK:UNK | ID:ID] .o. [a:b] == empty
if ! ($COMPOSE_TOOL -H unk2unk_or_id$ext a2b$ext | $COMPARE_TOOL -s empty$ext); then
echo "compose #8" ${FFLAG}
exit 1;
fi
# concatenation
echo "[?]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[a:b]" | $REGEXP_TOOL ${FFLAG} > tmp2;
# harmonization
$CONCATENATE_TOOL tmp1 tmp2 | $MINIMIZE_TOOL > concatenation;
echo "[[?|a|b] a:b]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result; # error
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s concatenation result); then
echo "concatenate #1" ${FFLAG}
exit 1;
fi
# no harmonization
$CONCATENATE_TOOL -H tmp1 tmp2 | $MINIMIZE_TOOL > concatenation;
echo "[? a:b]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s concatenation result); then
echo "concatenate #2" ${FFLAG}
exit 1;
fi
rm -f concatenation
## conjunction
echo "[?:?]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[a:b]" | $REGEXP_TOOL ${FFLAG} > tmp2;
# harmonization
$CONJUNCT_TOOL tmp1 tmp2 | $MINIMIZE_TOOL > conjunction;
echo "[a:b]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s conjunction result); then
echo "concatenate #1" ${FFLAG}
exit 1;
fi
# no harmonization
$CONJUNCT_TOOL -H tmp1 tmp2 | $MINIMIZE_TOOL > conjunction;
echo "[] - []" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s conjunction result); then
echo "concatenate #2" ${FFLAG}
exit 1;
fi
rm -f conjunction
# disjunction
echo "[?]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[a:b]" | $REGEXP_TOOL ${FFLAG} > tmp2;
# harmonization
$DISJUNCT_TOOL tmp1 tmp2 | $MINIMIZE_TOOL > disjunction;
echo "[?|a|b|a:b]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s disjunction result); then
echo "concatenate #1" ${FFLAG}
exit 1;
fi
# no harmonization
$DISJUNCT_TOOL -H tmp1 tmp2 | $MINIMIZE_TOOL > disjunction;
echo "[?|a:b]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s disjunction result); then
echo "concatenate #2" ${FFLAG}
exit 1;
fi
rm -f disjunction
## subtraction
echo "[?:?]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[a:b]" | $REGEXP_TOOL ${FFLAG} > tmp2;
# harmonization FOMA FAILS
$SUBTRACT_TOOL tmp1 tmp2 | $MINIMIZE_TOOL > subtraction;
echo "[?:?|a:?|?:a|b:?|?:b|b:a|a|b]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s subtraction result); then
echo "subtract #1" ${FFLAG}
exit 1;
fi
# no harmonization
$SUBTRACT_TOOL -H tmp1 tmp2 | $MINIMIZE_TOOL > subtraction;
echo "[?:?]" | $REGEXP_TOOL -H ${FFLAG} | $MINIMIZE_TOOL > result;
# do not harmonize when comparing, the transducers must be exactly the same
if ! ($COMPARE_TOOL -H -s subtraction result); then
echo "subtract #2" ${FFLAG}
exit 1;
fi
rm -f subtraction
## substitution
echo "\`[[a:b ?] , c , d ]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[a:b ?]" | $REGEXP_TOOL ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "substitution test #1" ${FFLAG}
exit 1;
fi
echo "\`[[a:b ?] , b , B C D ]" | $REGEXP_TOOL -H ${FFLAG} > tmp1;
echo "[[a:B | a:C | a:D] [?]]" | $REGEXP_TOOL -H ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "substitution test #2" ${FFLAG}
exit 1;
fi
echo "\`[[?] , a , b ]" | $REGEXP_TOOL -H ${FFLAG} > tmp1;
echo "[?]" | $REGEXP_TOOL -H ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "substitution test #3" ${FFLAG}
exit 1;
fi
echo "\`[[a b a:b] , a , ]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[]-[]" | $REGEXP_TOOL ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "substitution test #4" ${FFLAG}
exit 1;
fi
echo "\`[[ [a|c] b [a:b|d:e]] , a , ]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[c b d:e]" | $REGEXP_TOOL ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "substitution test #5" ${FFLAG}
exit 1;
fi
## freely insert aka ignore
echo "[?] / a" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[a* [?|a] a*]" | $REGEXP_TOOL -H ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "freely insert (aka ignore) test #1" ${FFLAG}
exit 1;
fi
echo "[?|a] / a:0" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[[a:0]* [?|a] [a:0]*]" | $REGEXP_TOOL -H ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "freely insert (aka ignore) test #2" ${FFLAG}
exit 1;
fi
echo "[?|a] / [a b]" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "[[a b]* [?|a|b] [a b]*]" | $REGEXP_TOOL -H ${FFLAG} > tmp2;
if ! ($COMPARE_TOOL -H tmp1 tmp2 > /dev/null); then
echo "freely insert (aka ignore) test #3" ${FFLAG}
exit 1;
fi
## some cases
echo "a:?" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "a:?|a" | $REGEXP_TOOL ${FFLAG} > tmp3;
if ! ($COMPARE_TOOL -H tmp1 tmp3 > /dev/null); then
echo "[a:?] == [a:?|a] test" ${FFLAG}
exit 1;
fi
echo "?:b" | $REGEXP_TOOL ${FFLAG} > tmp1;
echo "?:b|b" | $REGEXP_TOOL ${FFLAG} > tmp3;
if ! ($COMPARE_TOOL -H tmp1 tmp3 > /dev/null); then
echo "[?:b] == [?:b|b] test" ${FFLAG}
exit 1;
fi
## test that special symbols @_.*_@ are never harmonized
echo "@_foo_@" | $STRINGS2FST_TOOL -S ${FFLAG} > tmp1;
echo "[?:?]" | $REGEXP_TOOL ${FFLAG} > tmp2;
# using command line binary tools
for tool in "$COMPOSE_TOOL" "$CONCATENATE_TOOL" "$CONJUNCT_TOOL" "$DISJUNCT_TOOL" "$SUBTRACT_TOOL"
do
$tool tmp1 tmp2 | $FST2TXT_TOOL | tr '\t' ' ' > result
if (grep "@_foo_@ @_UNKNOWN_SYMBOL_@" result > /dev/null); then
echo "special symbols" $tool ${FFLAG}
exit 1;
fi
if (grep "@_UNKNOWN_SYMBOL_@ @_foo_@" result > /dev/null); then
echo "special symbols" $tool ${FFLAG}
exit 1;
fi
done
# and using regex parser operators
for operator in ".o." " " "&" "|" "-"
do
echo '?:?' $operator '"@_foo_@"' | $REGEXP_TOOL ${FFLAG} | \
$FST2TXT_TOOL | tr '\t' ' ' > result
if (grep "@_foo_@ @_UNKNOWN_SYMBOL_@" result > /dev/null); then
echo "special symbols" $tool ${FFLAG}
exit 1;
fi
if (grep "@_UNKNOWN_SYMBOL_@ @_foo_@" result > /dev/null); then
echo "special symbols" $tool ${FFLAG}
exit 1;
fi
done
## test special symbols in replace rules
## test ".#." which is a special symbol in foma
if ! (echo '[".#." ".#."]' | $REGEXP_TOOL ${FFLAG} | $FST2TXT_TOOL > /dev/null); then
echo "special symbol '.#.'" ${FFLAG}
exit 1
fi
if ! (echo '["@#@" "@#@"]' | $REGEXP_TOOL ${FFLAG} | $FST2TXT_TOOL > /dev/null); then
echo "special symbol '@#@'" ${FFLAG}
exit 1
fi
if ! (echo '["@#@" ".#."]' | $REGEXP_TOOL ${FFLAG} | $FST2TXT_TOOL > /dev/null); then
echo "special symbols '.#.' and '#@£'" ${FFLAG}
exit 1
fi
done
rm -f tmp1 tmp2 tmp3 result
|