#! /bin/bash
# Last edited on 2024-03-30 18:08:31 by stolfi

# Usage: $0 <inprefix> <dictionary>
# Compares the files <inprefix>.checked-{bad,dunno,good} against the
#   given <dictionary> file, giving for each file the 
#   number of "old" (present) and "new" (absent) words.

if [[ $# -ne 2 ]]; then
  echo "** usage: $0 <inprefix> <dictionary>" 1>&2
  exit 1
fi

inprefix="$1"
dictionary="$2"

echo 'validas presentes (deixar):' 1>&2
bool 1.2 ${inprefix}.checked-good ${dictionary} | wc -l | tr '\012' ' ' 1>&2
echo ' ' 1>&2

echo 'invalidas ausentes (ignorar):' 1>&2
bool 1-2 ${inprefix}.checked-bad ${dictionary} | wc -l | tr '\012' ' ' 1>&2
echo ' ' 1>&2

echo 'invalidas presentes (remover):' 1>&2
bool 1.2 ${inprefix}.checked-bad ${dictionary} > ${inprefix}.checked-remove
cat ${inprefix}.checked-remove | wc -l | tr '\012' ' ' 1>&2
echo ' ' 1>&2

echo 'validas ausentes (acrescentar):' 1>&2
bool 1-2 ${inprefix}.checked-good ${dictionary} > ${inprefix}.checked-add
cat ${inprefix}.checked-add | wc -l | tr '\012' ' ' 1>&2
echo ' ' 1>&2

echo 'duvidosas presentes (talvez remover):' 1>&2
bool 1.2 ${inprefix}.checked-dunno ${dictionary} > ${inprefix}.checked-remove-maybe
cat ${inprefix}.checked-remove-maybe | wc -l | tr '\012' ' ' 1>&2
echo ' ' 1>&2

echo 'duvidosas ausentes (talvez acrescentar)' 1>&2
bool 1-2 ${inprefix}.checked-dunno ${dictionary} > ${inprefix}.checked-add-maybe
cat ${inprefix}.checked-add-maybe | wc -l | tr '\012' ' ' 1>&2
echo ' ' 1>&2

ntot=`cat ${inprefix}.checked-{bad,dunno,good} | wc -l`

nadd=`cat ${inprefix}.checked-add | wc -l`
nrem=`cat ${inprefix}.checked-remove | wc -l`
nduh=`cat ${inprefix}.checked-dunno | wc -l`

minlucro=$(( ( ( ( 1000 * ( $nadd + $nrem ) ) / $ntot ) + 5 ) / 10 ))
maxlucro=$(( ( ( ( 1000 * ( $nadd + $nrem + $nduh ) ) / $ntot ) + 5 ) / 10 ))

echo ' ' 1>&2
echo 'Lucro: entre '$minlucro'% e '$maxlucro'%.' 1>&2

