#! /bin/bash set -e if [ $# -lt 2 ] then echo "Usage:" echo " compdic-update-fst ..." echo "where" echo " - fst format automaton" echo " - diff format file containing paths to be added/removed from dictionary" exit 0 fi tempdir=`mktemp -d /tmp/compdic.XXXXXX` dict=$1 shift dicplus=$tempdir/plus.dic fstplus=$tempdir/plus.fst dicminus=$tempdir/minus.dic fstminus=$tempdir/minus.fst touch $dicplus touch $dicminus while (($#)) do echo processing $1 ... cat $1 | egrep '^>' | sed -r 's/^> *//;s/[[:space:]].*$//' | canonize >> $dicplus cat $1 | egrep '^<' | sed -r 's/^< *//;s/[[:space:]].*$//' | canonize >> $dicminus shift done echo updating $dict ... if ! (( `cat $dicminus $dicplus | wc -l` )) then echo "Empty diff." exit 1 fi if (( `cat $dicminus | wc -l` )) then tmpfst1=$tempdir/tmp1.fst echo "running compdic-dic-to-fst $dicminus $fstminus" compdic-dic-to-fst $dicminus $fstminus echo "running fstdifference $dict $fstminus | fstdeterminize > $tmpfst1" fstdifference $dict $fstminus > $tmpfst1 else tmpfst1=$dict fi if (( `cat $dicplus | wc -l` )) then tmpfst2=$tempdir/tmp2.fst echo "running compdic-dic-to-fst $dicplus $fstplus" compdic-dic-to-fst $dicplus $fstplus echo "running fstunion $tmpfst1 $fstplus | fstdeterminize | fstminimize > $tmpfst2" fstunion $tmpfst1 $fstplus > $tmpfst2 else tmpfst2=$tmpfst1 fi echo "running mv ${dict} ${dict}~" mv ${dict} ${dict}~ echo "cat ${tmpfst2} | fstrmepsilon | fstdeterminize | fstminimize > ${dict}" cat ${tmpfst2} | fstrmepsilon | fstdeterminize | fstminimize > ${dict} chmod a+r ${dict} rm -r $tempdir