Difference between revisions of "Apertium-view.sh"

From Apertium
Jump to navigation Jump to search
 
Line 49: Line 49:
rm -f "$TEEMODE";
rm -f "$TEEMODE";
</pre>
</pre>

See https://gist.github.com/1495251 for a simpler solution

Latest revision as of 08:49, 19 December 2011

Usage:

$ echo 'Diversi entitajiet'| apertium-destxt | apertium-view.sh -d . mt-he
#!/bin/bash

ARGS=$(getopt "uad:" $*);
set -- $ARGS;
for i; do
  case "$i" in 
    -d) shift; DIRECTORY=$1; shift;;
    -u) UWORDS="no"; shift;;
    -a) OPTION_TAGGER="-m"; shift;;
    --) shift; break;;
  esac;
done;
if [ "$UWORDS" = "no" ]; then OPTION="-n"; else OPTION="-g"; fi;

case "$#" in 
     1) PAIR=$1;;
     *) echo 'error'; exit;;
esac;

TEEMODE=`mktemp teemode.XXXXXXXX`;
MODE=$DIRECTORY/modes/$1.mode;
i=1;
tr '|' '\n' < "$MODE" | grep -v '^\s*$' | while read cmd;
do
    if [ $i -ne 1 ]; then echo -n "|"; fi
    echo -n $cmd " | tee /tmp/apertium-view-$i.out " ;
    (( i = $i + 1 ));
done > "$TEEMODE";
echo '' >> $TEEMODE;

# Run translation:
bash "$TEEMODE" $OPTION $OPTION_TAGGER >/dev/null;

# Print all stages:
tr '|' '\n' < "$TEEMODE" | sed "s/\$1/$OPTION/
s/\$2/$OPTION_TAGGER/" |\
awk -F'tee ' '# Every other line should be a tee, then a command
/tee \/tmp\/apertium-view-/ {while(("cat "$2 | getline line)>0){print line;};print ""; next}
//                          {$0="| "$0" |"; 
                             s=sprintf("%"length($0)"s","");gsub(" ","_",s);print s; # pretty
                             print;
                             s=sprintf("%"length($0)"s","");gsub(" ","‾",s);print s; # pretty
			     }' 


rm -f "$TEEMODE";

See https://gist.github.com/1495251 for a simpler solution