Commit 7233ba134b95010863116f0d8d9f0af746a80deb

Authored by Jean-François Rey
1 parent 5d9d4173d6
Exists in master

up

Showing 1 changed file with 2 additions and 2 deletions Inline Diff

main_tools/ScoringRes.sh
1 #!/bin/bash 1 #!/bin/bash
2 2
3 ##################################################### 3 #####################################################
4 # File : ScoringRes.sh # 4 # File : ScoringRes.sh #
5 # Brief : Score result using SRT file # 5 # Brief : Score result using SRT file #
6 # Author : Jean-François Rey # 6 # Author : Jean-François Rey #
7 # Version : 1.0 # 7 # Version : 1.0 #
8 # Date : 11/07/13 # 8 # Date : 11/07/13 #
9 ##################################################### 9 #####################################################
10 10
11 echo "### ScoringRes.sh ###" 11 echo "### ScoringRes.sh ###"
12 12
13 # Check OTMEDIA_HOME env var 13 # Check OTMEDIA_HOME env var
14 if [ -z ${OTMEDIA_HOME} ] 14 if [ -z ${OTMEDIA_HOME} ]
15 then 15 then
16 OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0))) 16 OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0)))
17 export OTMEDIA_HOME=$OTMEDIA_HOME 17 export OTMEDIA_HOME=$OTMEDIA_HOME
18 fi 18 fi
19 19
20 # where is ScoringRes.sh 20 # where is ScoringRes.sh
21 MAIN_SCRIPT_PATH=$OTMEDIA_HOME/main_tools 21 MAIN_SCRIPT_PATH=$OTMEDIA_HOME/main_tools
22 22
23 # Scripts Path 23 # Scripts Path
24 SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts 24 SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts
25 25
26 # Include scripts 26 # Include scripts
27 . $SCRIPT_PATH"/Tools.sh" 27 . $SCRIPT_PATH"/Tools.sh"
28 28
29 # where is ScoringRes.cfg 29 # where is ScoringRes.cfg
30 SCORINGRES_CONFIG_FILE=$OTMEDIA_HOME"/cfg/ScoringRes.cfg" 30 SCORINGRES_CONFIG_FILE=$OTMEDIA_HOME"/cfg/ScoringRes.cfg"
31 if [ -e $SCORINGRES_CONFIG_FILE ] 31 if [ -e $SCORINGRES_CONFIG_FILE ]
32 then 32 then
33 . $SCORINGRES_CONFIG_FILE 33 . $SCORINGRES_CONFIG_FILE
34 else 34 else
35 echo "ERROR : Can't find configuration file $SCORINGRES_CONFIG_FILE" >&2 35 echo "ERROR : Can't find configuration file $SCORINGRES_CONFIG_FILE" >&2
36 exit 1 36 exit 1
37 fi 37 fi
38 38
39 #---------------# 39 #---------------#
40 # Parse Options # 40 # Parse Options #
41 #---------------# 41 #---------------#
42 while getopts ":hDv:" opt 42 while getopts ":hDv:" opt
43 do 43 do
44 case $opt in 44 case $opt in
45 h) 45 h)
46 echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n" 46 echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n"
47 echo -e "\t Options:" 47 echo -e "\t Options:"
48 echo -e "\t\t-h :\tprint this message" 48 echo -e "\t\t-h :\tprint this message"
49 echo -e "\t\t-D :\tDEBUG mode on" 49 echo -e "\t\t-D :\tDEBUG mode on"
50 echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode" 50 echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode"
51 exit 1 51 exit 1
52 ;; 52 ;;
53 D) 53 D)
54 DEBUG=1 54 DEBUG=1
55 ;; 55 ;;
56 v) 56 v)
57 VERBOSE=$OPTARG 57 VERBOSE=$OPTARG
58 ;; 58 ;;
59 :) 59 :)
60 echo "Option -$OPTARG requires an argument." >&2 60 echo "Option -$OPTARG requires an argument." >&2
61 exit 1 61 exit 1
62 ;; 62 ;;
63 \?) 63 \?)
64 echo "BAD USAGE : unknow opton -$OPTARG" 64 echo "BAD USAGE : unknow opton -$OPTARG"
65 #exit 1 65 #exit 1
66 ;; 66 ;;
67 esac 67 esac
68 68
69 done 69 done
70 70
71 # mode debug enable 71 # mode debug enable
72 if [ $DEBUG -eq 1 ] 72 if [ $DEBUG -eq 1 ]
73 then 73 then
74 set -x 74 set -x
75 echo -e "## Mode DEBUG ON ##" 75 echo -e "## Mode DEBUG ON ##"
76 fi 76 fi
77 77
78 # mode verbose enable 78 # mode verbose enable
79 if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi 79 if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi
80 80
81 # Check USAGE by arguments number 81 # Check USAGE by arguments number
82 if [ $(($#-($OPTIND-1))) -ne 1 ] 82 if [ $(($#-($OPTIND-1))) -ne 1 ]
83 then 83 then
84 echo "BAD USAGE : SecondPass.sh [OPTIONS] <PASS_DIR>" 84 echo "BAD USAGE : SecondPass.sh [OPTIONS] <PASS_DIR>"
85 echo "$0 -h for more info" 85 echo "$0 -h for more info"
86 exit 1 86 exit 1
87 fi 87 fi
88 88
89 shift $((OPTIND-1)) 89 shift $((OPTIND-1))
90 # check Pass directory - First argument 90 # check Pass directory - First argument
91 if [ -e $1 ] && [ -d $1 ] 91 if [ -e $1 ] && [ -d $1 ]
92 then 92 then
93 PASS_DIR=$(readlink -e $1) 93 PASS_DIR=$(readlink -e $1)
94 else 94 else
95 print_error "can't find $1 directory" 95 print_error "can't find $1 directory"
96 exit 1 96 exit 1
97 fi 97 fi
98 98
99 #-------------# 99 #-------------#
100 # GLOBAL VARS # 100 # GLOBAL VARS #
101 #-------------# 101 #-------------#
102 BASENAME=$(basename $PASS_DIR) 102 BASENAME=$(basename $PASS_DIR)
103 SCORING_DIR=$PASS_DIR/scoring 103 SCORING_DIR=$PASS_DIR/scoring
104 LOGFILE="$PASS_DIR/info_scoring.log" 104 LOGFILE="$PASS_DIR/info_scoring.log"
105 ERRORFILE="$PASS_DIR/error_scoring.log" 105 ERRORFILE="$PASS_DIR/error_scoring.log"
106 106
107 print_info "[${BASENAME}] => ScoringRes start | $(date +'%d/%m/%y %H:%M:%S')" 1 107 print_info "[${BASENAME}] => ScoringRes start | $(date +'%d/%m/%y %H:%M:%S')" 1
108 108
109 #------------------# 109 #------------------#
110 # Create WORKSPACE # 110 # Create WORKSPACE #
111 #------------------# 111 #------------------#
112 112
113 # Lock directory 113 # Lock directory
114 if [ -e $PASS_DIR/*.lock ] 114 if [ -e $PASS_DIR/*.lock ]
115 then 115 then
116 print_warn "[${BASENAME}] Directory is locked -> exit" 2; 116 print_warn "[${BASENAME}] Directory is locked -> exit" 2;
117 exit 1 117 exit 1
118 fi 118 fi
119 119
120 rm -r $SCORING_DIR > /dev/null 2>&1 120 rm -r $SCORING_DIR > /dev/null 2>&1
121 mkdir -p $SCORING_DIR 121 mkdir -p $SCORING_DIR
122 print_info "Make directory $SCORING_DIR" 1 122 print_info "Make directory $SCORING_DIR" 1
123 123
124 if [ ! -e $PASS_DIR/$BASENAME.SRT ] 124 if [ ! -e $PASS_DIR/$BASENAME.SRT ]
125 then 125 then
126 print_warn "[${BASENAME}] No SRT file -> exit" 2 126 print_warn "[${BASENAME}] No SRT file -> exit" 2
127 exit 0; 127 exit 0;
128 else 128 else
129 SRT_FILE=$PASS_DIR/$BASENAME.SRT 129 SRT_FILE=$PASS_DIR/$BASENAME.SRT
130 print_info "[${BASENAME}] SRT file : $BASENAME.SRT" 1 130 print_info "[${BASENAME}] SRT file : $BASENAME.SRT" 1
131 fi 131 fi
132 132
133 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 ] 133 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 ]
134 then 134 then
135 print_error "[${BASENAME}] No CTM files -> exit\n"; 135 print_error "[${BASENAME}] No CTM files -> exit\n";
136 exit 1; 136 exit 1;
137 fi 137 fi
138 138
139 print_info "[${BASENAME}] Create stm file from SRT" 1 139 print_info "[${BASENAME}] Create stm file from SRT" 1
140 i=$((-3)) 140 i=$((-3))
141 while read line 141 while read line
142 do 142 do
143 i=$(($i + 1)); 143 i=$(($i + 1));
144 if [ $i -eq 4 ] 144 if [ $i -eq 4 ]
145 then 145 then
146 echo " $line" 146 echo " $line"
147 i=$((0)); 147 i=$((0));
148 fi 148 fi
149 done < $SRT_FILE > $SCORING_DIR/$BASENAME.tmp.txt 149 done < $SRT_FILE > $SCORING_DIR/$BASENAME.tmp.txt
150 150
151 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 151 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
152 #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 152 #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
153 153
154 $SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm" 154 $SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm"
155 155
156 export LIA_TAGG_LANG="french" 156 export LIA_TAGG_LANG="french"
157 export LIA_TAGG="$OTMEDIA_HOME/tools/lia_ltbox/lia_tagg/" 157 export LIA_TAGG="$OTMEDIA_HOME/tools/lia_ltbox/lia_tagg/"
158 export LIA_NE="$OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/" 158 export LIA_NE="$OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/"
159 #cat $SCORING_DIR/$BASENAME.tmp.txt | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -f | iconv -t ISO-8859-1 -f UTF-8 | $OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/script/lia_ne_tagg_txt > $SCORING_DIR/$BASENAME.tmp2.tag 159 #cat $SCORING_DIR/$BASENAME.tmp.txt | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -f | iconv -t ISO-8859-1 -f UTF-8 | $OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/script/lia_ne_tagg_txt > $SCORING_DIR/$BASENAME.tmp2.tag
160 160
161 cat $SCORING_DIR/$BASENAME.tmp.txt | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -f | iconv -t ISO-8859-1 -f UTF-8 > $SCORING_DIR/$BASENAME.tmp2.txt 161 cat $SCORING_DIR/$BASENAME.tmp2.txt | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -f | iconv -t ISO-8859-1 -f UTF-8 > $SCORING_DIR/$BASENAME.tmp3.txt
162 $OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/script/lia_ne_tagg_stm $SCORING_DIR/$BASENAME.tmp2.txt $SCORING_DIR/$BASENAME.tmp2.tag 162 $OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/script/lia_ne_tagg_stm $SCORING_DIR/$BASENAME.tmp3.txt $SCORING_DIR/$BASENAME.tmp2.tag
163 163
164 rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt 164 rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt
165 165
166 print_info "Scoring using sclite" 1 166 print_info "Scoring using sclite" 1
167 for ctmfile in $(ls $PASS_DIR/*.ctm) 167 for ctmfile in $(ls $PASS_DIR/*.ctm)
168 do 168 do
169 cp $ctmfile $SCORING_DIR/ 169 cp $ctmfile $SCORING_DIR/
170 print_info "$BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all" 3 170 print_info "$BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all" 3
171 $BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all 171 $BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all
172 done 172 done
173 173
174 print_info "[${BASENAME}] <= ScoringRes End | $(date +'%d/%m/%y %H:%M:%S')" 1 174 print_info "[${BASENAME}] <= ScoringRes End | $(date +'%d/%m/%y %H:%M:%S')" 1
175 175
176 176
177 177