-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapertium-view.sh
executable file
·47 lines (39 loc) · 1.24 KB
/
apertium-view.sh
1
2
3
4
5
6
7
8
9
10
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
#!/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";