Commit 87013ba29c376b432f41b99771ef7c81399d062f
1 parent
668cac4d1b
Exists in
master
change filter
Showing 1 changed file with 2 additions and 1 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 | # Check OTMEDIA_HOME env var | 11 | # Check OTMEDIA_HOME env var |
12 | if [ -z ${OTMEDIA_HOME} ] | 12 | if [ -z ${OTMEDIA_HOME} ] |
13 | then | 13 | then |
14 | OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0))) | 14 | OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0))) |
15 | export OTMEDIA_HOME=$OTMEDIA_HOME | 15 | export OTMEDIA_HOME=$OTMEDIA_HOME |
16 | fi | 16 | fi |
17 | 17 | ||
18 | # where is ScoringRes.sh | 18 | # where is ScoringRes.sh |
19 | MAIN_SCRIPT_PATH=$OTMEDIA_HOME/main_tools | 19 | MAIN_SCRIPT_PATH=$OTMEDIA_HOME/main_tools |
20 | 20 | ||
21 | # Scripts Path | 21 | # Scripts Path |
22 | SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts | 22 | SCRIPT_PATH=$OTMEDIA_HOME/tools/scripts |
23 | 23 | ||
24 | # Include scripts | 24 | # Include scripts |
25 | . $SCRIPT_PATH"/Tools.sh" | 25 | . $SCRIPT_PATH"/Tools.sh" |
26 | 26 | ||
27 | # where is ScoringRes.cfg | 27 | # where is ScoringRes.cfg |
28 | SCORINGRES_CONFIG_FILE=$OTMEDIA_HOME"/cfg/ScoringRes.cfg" | 28 | SCORINGRES_CONFIG_FILE=$OTMEDIA_HOME"/cfg/ScoringRes.cfg" |
29 | if [ -e $SCORINGRES_CONFIG_FILE ] | 29 | if [ -e $SCORINGRES_CONFIG_FILE ] |
30 | then | 30 | then |
31 | . $SCORINGRES_CONFIG_FILE | 31 | . $SCORINGRES_CONFIG_FILE |
32 | else | 32 | else |
33 | echo "ERROR : Can't find configuration file $SCORINGRES_CONFIG_FILE" >&2 | 33 | echo "ERROR : Can't find configuration file $SCORINGRES_CONFIG_FILE" >&2 |
34 | exit 1 | 34 | exit 1 |
35 | fi | 35 | fi |
36 | 36 | ||
37 | #---------------# | 37 | #---------------# |
38 | # Parse Options # | 38 | # Parse Options # |
39 | #---------------# | 39 | #---------------# |
40 | while getopts ":hDv:" opt | 40 | while getopts ":hDv:" opt |
41 | do | 41 | do |
42 | case $opt in | 42 | case $opt in |
43 | h) | 43 | h) |
44 | echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n" | 44 | echo -e "$0 [OPTIONS] <PASS_DIRECTORY>\n" |
45 | echo -e "\t Options:" | 45 | echo -e "\t Options:" |
46 | echo -e "\t\t-h :\tprint this message" | 46 | echo -e "\t\t-h :\tprint this message" |
47 | echo -e "\t\t-D :\tDEBUG mode on" | 47 | echo -e "\t\t-D :\tDEBUG mode on" |
48 | echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode" | 48 | echo -e "\t\t-v l :\tVerbose mode, l=(1|2|3) level mode" |
49 | exit 1 | 49 | exit 1 |
50 | ;; | 50 | ;; |
51 | D) | 51 | D) |
52 | DEBUG=1 | 52 | DEBUG=1 |
53 | ;; | 53 | ;; |
54 | v) | 54 | v) |
55 | VERBOSE=$OPTARG | 55 | VERBOSE=$OPTARG |
56 | ;; | 56 | ;; |
57 | :) | 57 | :) |
58 | echo "Option -$OPTARG requires an argument." >&2 | 58 | echo "Option -$OPTARG requires an argument." >&2 |
59 | exit 1 | 59 | exit 1 |
60 | ;; | 60 | ;; |
61 | \?) | 61 | \?) |
62 | echo "BAD USAGE : unknow opton -$OPTARG" | 62 | echo "BAD USAGE : unknow opton -$OPTARG" |
63 | #exit 1 | 63 | #exit 1 |
64 | ;; | 64 | ;; |
65 | esac | 65 | esac |
66 | 66 | ||
67 | done | 67 | done |
68 | 68 | ||
69 | # mode debug enable | 69 | # mode debug enable |
70 | if [ $DEBUG -eq 1 ] | 70 | if [ $DEBUG -eq 1 ] |
71 | then | 71 | then |
72 | set -x | 72 | set -x |
73 | echo -e "## Mode DEBUG ON ##" | 73 | echo -e "## Mode DEBUG ON ##" |
74 | fi | 74 | fi |
75 | 75 | ||
76 | # mode verbose enable | 76 | # mode verbose enable |
77 | if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi | 77 | if [ $VERBOSE -gt 0 ]; then echo -e "## Verbose level : $VERBOSE ##" ; fi |
78 | 78 | ||
79 | # Check USAGE by arguments number | 79 | # Check USAGE by arguments number |
80 | if [ $(($#-($OPTIND-1))) -ne 1 ] | 80 | if [ $(($#-($OPTIND-1))) -ne 1 ] |
81 | then | 81 | then |
82 | echo "BAD USAGE : SecondPass.sh [OPTIONS] <PASS_DIR>" | 82 | echo "BAD USAGE : SecondPass.sh [OPTIONS] <PASS_DIR>" |
83 | echo "$0 -h for more info" | 83 | echo "$0 -h for more info" |
84 | exit 1 | 84 | exit 1 |
85 | fi | 85 | fi |
86 | 86 | ||
87 | shift $((OPTIND-1)) | 87 | shift $((OPTIND-1)) |
88 | # check Pass directory - First argument | 88 | # check Pass directory - First argument |
89 | if [ -e $1 ] && [ -d $1 ] | 89 | if [ -e $1 ] && [ -d $1 ] |
90 | then | 90 | then |
91 | PASS_DIR=$(readlink -e $1) | 91 | PASS_DIR=$(readlink -e $1) |
92 | else | 92 | else |
93 | print_error "can't find $1 directory" | 93 | print_error "can't find $1 directory" |
94 | exit 1 | 94 | exit 1 |
95 | fi | 95 | fi |
96 | 96 | ||
97 | #-------------# | 97 | #-------------# |
98 | # GLOBAL VARS # | 98 | # GLOBAL VARS # |
99 | #-------------# | 99 | #-------------# |
100 | BASENAME=$(basename $PASS_DIR) | 100 | BASENAME=$(basename $PASS_DIR) |
101 | SCORING_DIR=$PASS_DIR/scoring | 101 | SCORING_DIR=$PASS_DIR/scoring |
102 | LOGFILE="$(dirname $PASS_DIR)/info_scoring.log" | 102 | LOGFILE="$(dirname $PASS_DIR)/info_scoring.log" |
103 | ERRORFILE="$(dirname $PASS_DIR)/error_scoring.log" | 103 | ERRORFILE="$(dirname $PASS_DIR)/error_scoring.log" |
104 | 104 | ||
105 | #------------------# | 105 | #------------------# |
106 | # Create WORKSPACE # | 106 | # Create WORKSPACE # |
107 | #------------------# | 107 | #------------------# |
108 | 108 | ||
109 | # Lock directory | 109 | # Lock directory |
110 | if [ -e $PASS_DIR/*.lock ]; then echo "$PASS_DIR is lock"; exit 1;fi | 110 | if [ -e $PASS_DIR/*.lock ]; then echo "$PASS_DIR is lock"; exit 1;fi |
111 | 111 | ||
112 | rm -r $SCORING_DIR > /dev/null 2>&1 | 112 | rm -r $SCORING_DIR > /dev/null 2>&1 |
113 | mkdir -p $SCORING_DIR | 113 | mkdir -p $SCORING_DIR |
114 | print_info "Make directory $SCORING_DIR" 1 | 114 | print_info "Make directory $SCORING_DIR" 1 |
115 | 115 | ||
116 | if [ ! -e $PASS_DIR/$BASENAME.SRT ] | 116 | if [ ! -e $PASS_DIR/$BASENAME.SRT ] |
117 | then | 117 | then |
118 | echo -e "no SRT file for $BASENAME\n" | 118 | echo -e "no SRT file for $BASENAME\n" |
119 | exit 0; | 119 | exit 0; |
120 | else | 120 | else |
121 | SRT_FILE=$PASS_DIR/$BASENAME.SRT | 121 | SRT_FILE=$PASS_DIR/$BASENAME.SRT |
122 | fi | 122 | fi |
123 | 123 | ||
124 | 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 ] | 124 | 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 ] |
125 | then | 125 | then |
126 | echo -e "no CTM files for $BASENAME\n"; | 126 | echo -e "no CTM files for $BASENAME\n"; |
127 | exit 1; | 127 | exit 1; |
128 | fi | 128 | fi |
129 | 129 | ||
130 | i=$((-3)) | 130 | i=$((-3)) |
131 | while read line | 131 | while read line |
132 | do | 132 | do |
133 | i=$(($i + 1)); | 133 | i=$(($i + 1)); |
134 | if [ $i -eq 4 ] | 134 | if [ $i -eq 4 ] |
135 | then | 135 | then |
136 | echo " $line" | 136 | echo " $line" |
137 | i=$((0)); | 137 | i=$((0)); |
138 | fi | 138 | fi |
139 | done < $SRT_FILE > $SCORING_DIR/$BASENAME.tmp.txt | 139 | done < $SRT_FILE > $SCORING_DIR/$BASENAME.tmp.txt |
140 | 140 | ||
141 | 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 | 141 | #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 |
142 | 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 | ||
142 | 143 | ||
143 | $SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm" | 144 | $SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm" |
144 | rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt | 145 | rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt |
145 | 146 | ||
146 | for ctmfile in $(ls $PASS_DIR/*.ctm) | 147 | for ctmfile in $(ls $PASS_DIR/*.ctm) |
147 | do | 148 | do |
148 | cp $ctmfile $SCORING_DIR/ | 149 | cp $ctmfile $SCORING_DIR/ |
149 | $BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all | 150 | $BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all |
150 | done | 151 | done |
151 | 152 | ||
152 | 153 | ||
153 | 154 | ||
154 | 155 |