Blame view

main_tools/ScoringRes.sh 5.06 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
  
  $SCRIPT_PATH/srt2stm.pl $SCORING_DIR/$BASENAME.tmp2.txt > "$SCORING_DIR/$BASENAME.stm"
f34231730   Jean-François Rey   add lia_ne + crf+...
157

7f1c831f7   Jean-François Rey   Can't fix bug fro...
158
159
  ## TODO
  # lia_ne bug...
fa2309079   Jean-François Rey   update scoring te...
160
161
162
  export LIA_TAGG_LANG="french"
  export LIA_TAGG="$OTMEDIA_HOME/tools/lia_ltbox/lia_tagg/"
  export LIA_NE="$OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/"
7f1c831f7   Jean-François Rey   Can't fix bug fro...
163
164
165
  #cat $SCORING_DIR/$BASENAME.tmp2.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
  cat $SCORING_DIR/$BASENAME.stm | $SCRIPT_PATH/BdlexUC.pl $RULES/basic -f | iconv -t ISO-8859-1 -f UTF-8 > $SCORING_DIR/$BASENAME.tmp3.txt
  $OTMEDIA_HOME/tools/lia_ltbox/lia_ne_v2.2/script/lia_ne_tagg_stm $SCORING_DIR/$BASENAME.tmp3.txt $SCORING_DIR/$BASENAME.tmp3.tag
5d9d4173d   Jean-François Rey   update
166

7f1c831f7   Jean-François Rey   Can't fix bug fro...
167
  rm $SCORING_DIR/$BASENAME.tmp.txt $SCORING_DIR/$BASENAME.tmp2.txt $SCORING_DIR/$BASENAME.tmp3.txt
e6be5137b   Jean-François Rey   reinitialized pro...
168

b427f103e   Jean-François Rey   update log info p...
169
  print_info "Scoring using sclite" 1
e6be5137b   Jean-François Rey   reinitialized pro...
170
171
172
  for ctmfile in $(ls $PASS_DIR/*.ctm)
  do
      cp $ctmfile $SCORING_DIR/
b427f103e   Jean-François Rey   update log info p...
173
      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...
174
175
      $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...
176
  print_info "[${BASENAME}] <= ScoringRes End | $(date +'%d/%m/%y %H:%M:%S')" 1
e6be5137b   Jean-François Rey   reinitialized pro...
177