Blame view

main_tools/ScoringRes.sh 4.4 KB
e6be5137b   Jean-François Rey   reinitialized pro...
1
2
3
4
5
6
7
8
9
  #!/bin/bash
  
  #####################################################
  # File :    ScoringRes.sh                           #
  # Brief :   Score result using SRT file             #
  # Author :  Jean-François Rey                       #
  # Version : 1.0                                     #
  # Date :    11/07/13                                #
  #####################################################
f37e72eaf   Jean-François Rey   up
10
  echo "### ScoringRes.sh ###"
e6be5137b   Jean-François Rey   reinitialized pro...
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
  # 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>
  "
              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
b427f103e   Jean-François Rey   update log info p...
103
104
105
106
  LOGFILE="$PASS_DIR/info_scoring.log"
  ERRORFILE="$PASS_DIR/error_scoring.log"
  
  print_info "[${BASENAME}] => ScoringRes start | $(date +'%d/%m/%y %H:%M:%S')" 1
e6be5137b   Jean-François Rey   reinitialized pro...
107
108
109
110
111
112
  
  #------------------#
  # Create WORKSPACE #
  #------------------#
  
  # Lock directory
b427f103e   Jean-François Rey   update log info p...
113
114
115
116
117
  if [ -e $PASS_DIR/*.lock ]
  then
      print_warn "[${BASENAME}] Directory is locked -> exit" 2;
      exit 1
  fi
e6be5137b   Jean-François Rey   reinitialized pro...
118
119
120
121
122
123
124
  
  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
b427f103e   Jean-François Rey   update log info p...
125
      print_warn "[${BASENAME}] No SRT file -> exit" 2
e6be5137b   Jean-François Rey   reinitialized pro...
126
127
128
      exit 0;
  else
      SRT_FILE=$PASS_DIR/$BASENAME.SRT
b427f103e   Jean-François Rey   update log info p...
129
      print_info "[${BASENAME}] SRT file : $BASENAME.SRT" 1
e6be5137b   Jean-François Rey   reinitialized pro...
130
131
132
133
  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
b427f103e   Jean-François Rey   update log info p...
134
135
      print_error "[${BASENAME}] No CTM files -> exit
  ";
e6be5137b   Jean-François Rey   reinitialized pro...
136
137
      exit 1;
  fi
b427f103e   Jean-François Rey   update log info p...
138
  print_info "[${BASENAME}] Create stm file from SRT" 1
e6be5137b   Jean-François Rey   reinitialized pro...
139
140
141
142
143
144
145
146
147
148
  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
0bf609bcc   Jean-François Rey   update and add sc...
149
150
151
152
153
154
  cat $SCORING_DIR/$BASENAME.tmp.txt | sed -e "s|
  | |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|
  +| |g" > $SCORING_DIR/$BASENAME.tmp2.txt
  #cat $SCORING_DIR/$BASENAME.tmp.txt | sed -e "s|
  | |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|
  +| |g" > $SCORING_DIR/$BASENAME.tmp2.txt
e6be5137b   Jean-François Rey   reinitialized pro...
155
156
157
  
  $SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm"
  rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt
b427f103e   Jean-François Rey   update log info p...
158
  print_info "Scoring using sclite" 1
e6be5137b   Jean-François Rey   reinitialized pro...
159
160
161
  for ctmfile in $(ls $PASS_DIR/*.ctm)
  do
      cp $ctmfile $SCORING_DIR/
b427f103e   Jean-François Rey   update log info p...
162
      print_info "$BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all" 3
e6be5137b   Jean-François Rey   reinitialized pro...
163
164
      $BIN_PATH/sclite -D -F -r $SCORING_DIR/$BASENAME.stm stm -h $SCORING_DIR/$(basename $ctmfile) ctm -o all
  done
b427f103e   Jean-François Rey   update log info p...
165
  print_info "[${BASENAME}] <= ScoringRes End | $(date +'%d/%m/%y %H:%M:%S')" 1
e6be5137b   Jean-François Rey   reinitialized pro...
166