ScoringRes.sh
3.91 KB
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
#!/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