2
# test average shannon entropy calculation for multiple documents
3
# we test with -w 2 switch (type -p only counts 2-grams for the shannon entropy)
4
# (verification is more accurate with identical mails)
9
prerequisite_command() {
10
type $2 2>&1 > /dev/null
12
echo "$1: $2 not found, test will be skipped"
17
prerequisite_command $0 formail
18
prerequisite_command $0 grep
19
prerequisite_command $0 awk
20
prerequisite_command $0 tr
22
DBACL_PATH="`pwd`/`basename $0 .sh`_`date +"%Y%m%dT%H%M%S"`"
27
(echo ; echo "From - -" ; cat sample.spam-1 ; \
28
echo ; echo "From - -" ; cat sample.spam-1 ; \
29
echo ; echo "From - -" ; cat sample.spam-1 ; \
30
echo ; echo "From - -" ; cat sample.spam-1 ; ) \
33
cat "$DBACL_PATH/mbox" \
34
| $DBACL -l dummy -T email -X -d -w 2 \
36
| awk '{print $3/log(2)}' \
40
cat "$DBACL_PATH/mbox" \
41
| formail -s $DBACL -c dummy -vX \
42
| awk '{d += $3; e += $5} END{print (d/4), (e/4)}' \
46
echo "`cat \"$DBACL_PATH/out1\"` `cat \"$DBACL_PATH/out2\"`" \
48
function abs(x) { return (x >= 0) ? x : -x }
50
# must invert exit value
51
exit !( abs($1 - $3) < (0.15/2.0) * ($1 + $3) )
b'\\ No newline at end of file'