[555c7f8] | 1 | #! /bin/bash |
---|
| 2 | |
---|
| 3 | if [ $# -lt 2 ] |
---|
| 4 | then |
---|
| 5 | echo "Usage:" |
---|
| 6 | echo " compdic-update-fst <dictionary> <difference> <difference> ..." |
---|
| 7 | echo "where" |
---|
| 8 | echo " <dictionary> - fst format automaton" |
---|
| 9 | echo " <difference> - diff format file containing paths to be added/removed from dictionary" |
---|
| 10 | exit 0 |
---|
| 11 | fi |
---|
| 12 | |
---|
| 13 | tempdir=`mktemp -d /tmp/compdic.XXXXXX` |
---|
| 14 | |
---|
| 15 | dict=$1 |
---|
| 16 | shift |
---|
| 17 | |
---|
| 18 | dicplus=$tempdir/plus.dic |
---|
| 19 | fstplus=$tempdir/plus.fst |
---|
| 20 | dicminus=$tempdir/minus.dic |
---|
| 21 | fstminus=$tempdir/minus.fst |
---|
| 22 | |
---|
| 23 | touch $dicplus |
---|
| 24 | touch $dicminus |
---|
| 25 | |
---|
| 26 | while (($#)) |
---|
| 27 | do |
---|
| 28 | echo processing $1 ... |
---|
| 29 | cat $1 | egrep '^>' | sed -r 's/^> *//;s/[[:space:]].*$//' | canonize >> $dicplus |
---|
| 30 | cat $1 | egrep '^<' | sed -r 's/^< *//;s/[[:space:]].*$//' | canonize >> $dicminus |
---|
| 31 | shift |
---|
| 32 | done |
---|
| 33 | |
---|
| 34 | echo updating $dict ... |
---|
| 35 | |
---|
| 36 | if (( `cat $dicminus | wc -l` )) |
---|
| 37 | then |
---|
| 38 | tmpfst1=$tempdir/tmp1.fst |
---|
| 39 | echo "running compdic-dic-to-fst $dicminus $fstminus" |
---|
| 40 | compdic-dic-to-fst $dicminus $fstminus |
---|
| 41 | echo "running fstdifference $dict $fstminus | fstdeterminize > $tmpfst1" |
---|
| 42 | fstdifference $dict $fstminus > $tmpfst1 |
---|
| 43 | else |
---|
| 44 | tmpfst1=$dict |
---|
| 45 | fi |
---|
| 46 | |
---|
| 47 | if (( `cat $dicplus | wc -l` )) |
---|
| 48 | then |
---|
| 49 | tmpfst2=$tempdir/tmp2.fst |
---|
| 50 | echo "running compdic-dic-to-fst $dicplus $fstplus" |
---|
| 51 | compdic-dic-to-fst $dicplus $fstplus |
---|
| 52 | echo "running fstunion $tmpfst1 $fstplus | fstdeterminize | fstminimize > $tmpfst2" |
---|
| 53 | fstunion $tmpfst1 $fstplus > $tmpfst2 |
---|
| 54 | else |
---|
| 55 | tmpfst2=$tmpfst1 |
---|
| 56 | fi |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | echo "running mv ${dict} ${dict}~" |
---|
| 61 | mv ${dict} ${dict}~ |
---|
| 62 | |
---|
| 63 | echo "cat ${tmpfst2} | fstrmepsilon | fstdeterminize | fstminimize > ${dict}" |
---|
| 64 | cat ${tmpfst2} | fstrmepsilon | fstdeterminize | fstminimize > ${dict} |
---|
| 65 | chmod a+r ${dict} |
---|
| 66 | |
---|
| 67 | rm -r $tempdir |
---|