ScoringRes.sh 3.91 KB
#!/bin/bash

#####################################################
# File :    ScoringRes.sh                           #
# Brief :   Score result using SRT file             #
# Author :  Jean-François Rey                       #
# Version : 1.0                                     #
# Date :    11/07/13                                #
#####################################################

# Check OTMEDIA_HOME env var
if [ -z ${OTMEDIA_HOME} ]
then
    OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0)))
    export OTMEDIA_HOME=$OTMEDIA_HOME
fi

# where is ScoringRes.sh
MAIN_SCRIPT_PATH=$OTMEDIA_HOME/main_tools

# Scripts Path
SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts

# Include scripts
. $SCRIPT_PATH"/Tools.sh"

# where is ScoringRes.cfg
SCORINGRES_CONFIG_FILE=$OTMEDIA_HOME"/cfg/ScoringRes.cfg"
if [ -e $SCORINGRES_CONFIG_FILE ]
then
	. $SCORINGRES_CONFIG_FILE
else
	echo "ERROR : Can't find configuration file $SCORINGRES_CONFIG_FILE" >&2
	exit 1
fi

#---------------#
# Parse Options #
#---------------#
while getopts ":hDv:" opt
do
	case $opt in
		h)
			echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n"
            echo -e "\t Options:"
            echo -e "\t\t-h :\tprint this message"
            echo -e "\t\t-D :\tDEBUG mode on"
            echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode"
			exit 1
			;;
		D)
			DEBUG=1
			;;
        v)
            VERBOSE=$OPTARG
            ;;
		:)
			echo "Option -$OPTARG requires an argument." >&2
			exit 1
			;;
		\?)
			echo "BAD USAGE : unknow opton -$OPTARG"
			#exit 1
			;;
    esac

done

# mode debug enable
if [ $DEBUG -eq 1 ]
then
       set -x
       echo -e "## Mode DEBUG ON ##"
fi

# mode verbose enable
if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi

# Check USAGE by arguments number
if [ $(($#-($OPTIND-1))) -ne 1 ]
then
	echo "BAD USAGE : SecondPass.sh [OPTIONS] <PASS_DIR>"
	echo "$0 -h for more info"
    exit 1
fi

shift $((OPTIND-1))
# check Pass directory - First argument
if [ -e $1 ] && [ -d $1 ]
then
    PASS_DIR=$(readlink -e $1)
else
	print_error "can't find $1 directory"
	exit 1
fi

#-------------#
# GLOBAL VARS #
#-------------#
BASENAME=$(basename $PASS_DIR)
SCORING_DIR=$PASS_DIR/scoring
LOGFILE="$(dirname $PASS_DIR)/info_scoring.log"
ERRORFILE="$(dirname $PASS_DIR)/error_scoring.log"

#------------------#
# Create WORKSPACE #
#------------------#

# Lock directory
if [ -e $PASS_DIR/*.lock ]; then echo "$PASS_DIR is lock"; exit 1;fi

rm -r $SCORING_DIR > /dev/null 2>&1
mkdir -p $SCORING_DIR
print_info "Make directory $SCORING_DIR" 1

if [ ! -e $PASS_DIR/$BASENAME.SRT ]
then
    echo -e "no SRT file for $BASENAME\n"
    exit 0;
else
    SRT_FILE=$PASS_DIR/$BASENAME.SRT
fi

if [ ! -e $PASS_DIR/$BASENAME.1pass.ctm ] && [ ! -e $PASS_DIR/$BASENAME.2pass.ctm ] && [ ! -e $PASS_DIR/$BASENAME.3pass.ctm ] && [ ! -e $PASS_DIR/$BASENAME.allpass.ctm ]
then
    echo -e "no CTM files for $BASENAME\n";
    exit 1;
fi

i=$((-3))
while read line  
do
    i=$(($i + 1));   
    if [ $i -eq 4 ]
    then
        echo " $line"
        i=$((0));
    fi
done < $SRT_FILE > $SCORING_DIR/$BASENAME.tmp.txt

#cat $SCORING_DIR/$BASENAME.tmp.txt | sed -e "s|\n| |g" | $SCRIPT_PATH/CleanFilter.sh | $SCRIPT_PATH/ApplyCorrectionRules.pl ${LEXICON}.regex | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -t | sed -e "s|<s>||g" | sed -e "s|</s>||g" | sed -e "s|\n+| |g" > $SCORING_DIR/$BASENAME.tmp2.txt
cat $SCORING_DIR/$BASENAME.tmp.txt | sed -e "s|\n| |g" | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -t | sed -f $RULES/preprocess.regex | sed -f $RULES/lastprocess.regex | sed -e "s|<s>||g" | sed -e "s|</s>||g" | sed -e "s|\n+| |g" > $SCORING_DIR/$BASENAME.tmp2.txt

$SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm"
rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt

for ctmfile in $(ls $PASS_DIR/*.ctm)
do
    cp $ctmfile $SCORING_DIR/
    $BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all
done