source: src/compdic/compdic-update-fst

Last change on this file was c03f8a5, checked in by Tomasz Obrebski <obrebski@…>, 10 years ago

minor fixes

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