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
|
#!/bin/bash
#
# Copyright (C) 2002 Laird Breyer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Laird Breyer <laird@lbreyer.com>
#
# These functions are included by the test scripts. They could be
# just sourced, but then where to put the common functions in the filesystem?
# begin mailtest.functions
prerequisite_command() {
if [ -z "`type -p $1`" ]; then
echo "Error: $1 not found. Please install $2 to proceed."
exit 1
fi
}
clean_working_tree() {
if [ -e $MXDIR ]; then
rm -rf $MXDIR
else
echo "Nothing to clean"
fi
}
make_dummy_mbox() {
cat > $MXDIR/mbox/dummy.mailbox <<EOF
From MAILER-DAEMON Thu Dec 4 13:50:55 2003
Date: 04 Dec 2003 13:50:55 +1000
From: Mail System Internal Data <MAILER-DAEMON@scooby>
Subject: DON\'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
Message-ID: <1070509855@scooby>
X-IMAP: 1023007291 0000010227
Status: RO
This text is part of the internal format of your mail folder, and is not
a real message. It is created automatically by the mail system software.
If deleted, important folder data will be lost, and it will be re-created
with the data reset to initial values.
EOF
}
prepare_working_tree() {
if [ -d $MXDIR ]; then
echo "Error: Directory $MXDIR already exists. Remove it or use it.";
usage;
elif [ -n "$1" ]; then
prerequisite_command "seq" "shellutils"
NUM=`expr $1 - 1`;
if [ $NUM -gt -1 ]; then
mkdir "$MXDIR" && \
mkdir "$MXDIR/tmp" && \
mkdir "$MXDIR/log" && \
mkdir "$MXDIR/plots" && \
mkdir "$MXDIR/mbox" && \
mkdir "$MXDIR/review" && \
mkdir "$MXDIR/filters" && \
for i in `seq 0 $NUM`; do mkdir "$MXDIR/$i"; done && \
echo "=== prepare_working_tree $*" >> $ALOG
else
echo "Error: Please specify a number greater than zero."
usage
fi
else
echo "Error: Please specify a number."
usage
fi
}
get_categories() {
CATS=`find $MXDIR -type f -name '*.mbox' -exec basename {} \; | sort -u`
[ -z "$CATS" ] && echo "No categories found"
}
get_filters() {
FILTS=`find $FILTERS -type f -perm /0111 -exec basename {} \; | sort -u`
[ -z "$FILTS" ] && echo "No filters found"
}
get_number_of_subsets() {
NUM=`ls $MXDIR | grep '^[0-9]' | wc -l`
if [ $(($NUM)) -le 0 ]; then
echo "error: you need to prepare first."
usage
fi
}
review_misclassified() {
SM=$1
shift
cat > "$SM" <<EOF
#!/bin/sh
cat > msg.tmp.\$POSITION.\$FILENO
M=\`head -1 msg.tmp.\$POSITION.\$FILENO | grep -e "\$EMAIL.*\$DATE"\`
if [ -n "\$M" ]; then
mv msg.tmp.\$POSITION.\$FILENO $MXDIR/review/\$1.\$2.\$POSITION.\$FILENO
else
rm msg.tmp.\$POSITION.\$FILENO
fi
EOF
if [ -d "$MXDIR/review" ]; then
rm -f "$MXDIR/review/*"
else
echo "Error: You need to prepare first."
usage
fi
if [ -s "$CLOG" ]; then
grep " $1 $2 " "$CLOG" | \
while read f; do
BOX=`echo $f | cut -d' ' -f2`
export POSITION=`echo $f | cut -d' ' -f1`
export EMAIL=`echo $f | cut -d' ' -f4`
export DATE=`echo $f | cut -d' ' -f5-`
echo "$f"
[ -e "$MXDIR/$POSITION/$BOX.mbox" ] || export POSITION=mbox
cat "$MXDIR/$POSITION/$BOX.mbox" | formail -s /bin/sh "$SM" "$1" "$2"
done
else
echo "Error: There are no logs - run the classifier(s) first"
fi
rm -f "$SM"
}
testsuite_list_wrappers() {
if [ -d $BOOTSTRAP ] ; then
echo -ne "The following classification wrappers are selectable:\n\n"
for f in `ls $BOOTSTRAP` ; do
[ -x "$BOOTSTRAP/$f" ] && echo "$f - `$BOOTSTRAP/$f describe`"
done
else
echo "Bootstrap directory $BOOTSTRAP does not exist."
fi
}
testsuite_deselect_wrappers() {
shift
if [ -z "$*" ] ; then
usage
else
for f in "$@" ; do
if [ -e $FILTERS/$f ] ; then
echo "deselecting $f"
rm -f $FILTERS/$f
else
echo "$f: no such filter."
fi
done
fi
}
testsuite_select_wrappers() {
shift
if [ -z "$*" ] ; then
usage
else
for f in $* ; do
if [ -x $BOOTSTRAP/$f ] ; then
$BOOTSTRAP/$f bootstrap $FILTERS
else
echo "The wrapper $f cannot be selected, skipping."
fi
done
fi
}
summarize_log() {
awk -v "num=$NUM" -v "cats=${CATS//.mbox/}" '
BEGIN{
split(cats,names)
}
/^[^#]/{
f[$2,$3]++
fn[$3]++
fp[$2]++
}
END{
printf("Where do misclassifications go?\n(numbers on diagonal represent \"recall\")\n\n")
printf(" true | but predicted as...\n")
printf(" * | ")
for(c in names) printf("%10s", names[c])
printf("\n")
for(c in names) {
printf("%-10s | ", names[c])
for(d in names) {
printf("%9.2f%%", 100 * f[names[c],names[d]]/fp[names[c]])
}
printf("\n")
}
printf("\n")
printf("What is really in each category after prediction?\n(numbers on diagonal represent \"precision\")\n\n")
printf("category | contains mixture of...\n")
printf(" * | ")
for(c in names) printf("%10s", names[c])
printf("\n")
for(c in names) {
printf("%-10s | ", names[c])
for(d in names) {
printf("%9.2f%%", 100 * f[names[d],names[c]]/fn[names[c]])
}
printf("\n")
}
printf("\n")
x = y = 0
for(c in names) {
x += f[names[c],names[c]]
for(d in names) {
y += f[names[c],names[d]]
}
}
printf("Total correct classifications: %9.2f%%\n\n", (100 * x)/y)
}
'
}
plot_errors() {
OUTFILE=$MXDIR/plots/`basename $1 .log`
CMDFILE=$OUTFILE.cmd
DATAFILE=$OUTFILE.plotdata
TITLE=$2
cat $1 \
| grep -v '^#' \
| cut -f1,2,3 -d ' ' \
| awk '{count[$1]++; ecount[$1] += ($2 != $3); print (count[$1] == 1) ? "\n" : "", count[$1], ecount[$1]}' \
> $DATAFILE
shift 2
OUTPUT="set terminal x11"
SCALE="unset logscale"
PAUSE="pause -1 \"Press any key...\""
OUTPRINT=""
for o in "$@"; do
if [ "$o" = "ps" ]; then
OUTPUT="set terminal postscript"
OUTPRINT="set output \"$OUTFILE.ps\""
PAUSE=""
echo "writing $OUTFILE.ps"
elif [ "$o" = "logscale" ]; then
SCALE="set logscale"
fi
done
cat > $CMDFILE <<EOF
$OUTPUT
$OUTPRINT
$SCALE
unset key
set title "$TITLE"
plot "$DATAFILE" with points
$PAUSE
EOF
gnuplot $CMDFILE
}
plot_biplot() {
OUTFILE=$MXDIR/plots/$1
CMDFILE=$OUTFILE.cmd
DATAFILE=$OUTFILE.plotdata
ERRORFILE=$OUTFILE.ploterrors
TITLE=$1
cat $2 \
| grep -v '^#' \
| awk '{print $5, $14}' \
> $DATAFILE
cat $2 \
| grep -v '^#' \
| awk '{if( (($2 == $3) && ($5 > $14)) || (($2 != $3) && ($5 < $14)) ) print }' \
| awk '{print $5, $14}' \
> $ERRORFILE
shift 2
OUTPUT="set terminal x11"
SCALE="unset logscale"
PAUSE="pause -1 \"Press any key...\""
OUTPRINT=""
for o in "$@"; do
if [ "$o" = "ps" ]; then
OUTPUT="set terminal postscript"
OUTPRINT="set output \"$OUTFILE.ps\""
PAUSE=""
echo "writing $OUTFILE.ps"
elif [ "$o" = "logscale" ]; then
SCALE="set logscale"
fi
done
cat > $CMDFILE <<EOF
$OUTPUT
$OUTPRINT
$SCALE
unset key
set title "$TITLE"
plot "$DATAFILE" using 1:2 pt 1, "$ERRORFILE" using 1:2 pt 5, x
$PAUSE
EOF
gnuplot $CMDFILE
}
# end mailtest.functions
|