| 1 |  | 
|---|
| 2 | no_of_parts=0 | 
|---|
| 3 |  | 
|---|
| 4 | while [ $# -gt 2 ] | 
|---|
| 5 | do | 
|---|
| 6 | case $1 | 
|---|
| 7 | in | 
|---|
| 8 | -p) | 
|---|
| 9 | no_of_parts=$2 | 
|---|
| 10 | shift 2 | 
|---|
| 11 | ;; | 
|---|
| 12 |  | 
|---|
| 13 | *) | 
|---|
| 14 | echo "The arguments to use are" | 
|---|
| 15 | echo "-p: number of parts" | 
|---|
| 16 | shift 1 | 
|---|
| 17 | ;; | 
|---|
| 18 | esac | 
|---|
| 19 | done | 
|---|
| 20 |  | 
|---|
| 21 | if [ $# -lt 2 ] | 
|---|
| 22 | then | 
|---|
| 23 | echo | 
|---|
| 24 | echo "compdic is a tool to compile lists of automaton paths (words) into the automaton format" | 
|---|
| 25 | echo "suitable for use with lem, gue, cor, and kor components" | 
|---|
| 26 | echo | 
|---|
| 27 | echo "Usage:" | 
|---|
| 28 | echo "        compdic [-p <parts>] <wordlist> <automaton>" | 
|---|
| 29 | echo "where" | 
|---|
| 30 | echo "    <wordlist> - file containig a list of words, one per line, iso-8859-2 encoded" | 
|---|
| 31 | echo "    <automaton> - a file to which the compiled automaton (lem/gue/cor/kor format) should be written" | 
|---|
| 32 | exit 0 | 
|---|
| 33 | fi | 
|---|
| 34 |  | 
|---|
| 35 | if [ $no_of_parts -eq 0 ] | 
|---|
| 36 | then | 
|---|
| 37 | no_of_parts=$(( `cat $1 | wc -l` / 75000 + 1 )) | 
|---|
| 38 | fi | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | echo number of parts: $no_of_parts | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | tempdir=`mktemp -d /tmp/compdic.XXXXXX` | 
|---|
| 45 |  | 
|---|
| 46 | alphabet=`tempfile -d $tempdir` | 
|---|
| 47 |  | 
|---|
| 48 | cat <<EOF > $alphabet | 
|---|
| 49 | <eps> 0 | 
|---|
| 50 | a 1 | 
|---|
| 51 | A 2 | 
|---|
| 52 | ä 3 | 
|---|
| 53 | ± 4 | 
|---|
| 54 | ¡ 5 | 
|---|
| 55 | b 6 | 
|---|
| 56 | B 7 | 
|---|
| 57 | c 8 | 
|---|
| 58 | C 9 | 
|---|
| 59 | æ 10 | 
|---|
| 60 | Æ 11 | 
|---|
| 61 | d 12 | 
|---|
| 62 | D 13 | 
|---|
| 63 | e 14 | 
|---|
| 64 | E 15 | 
|---|
| 65 | é 16 | 
|---|
| 66 | ê 17 | 
|---|
| 67 | Ê 18 | 
|---|
| 68 | f 19 | 
|---|
| 69 | F 20 | 
|---|
| 70 | g 21 | 
|---|
| 71 | G 22 | 
|---|
| 72 | h 23 | 
|---|
| 73 | H 24 | 
|---|
| 74 | i 25 | 
|---|
| 75 | I 26 | 
|---|
| 76 | j 27 | 
|---|
| 77 | J 28 | 
|---|
| 78 | k 29 | 
|---|
| 79 | K 30 | 
|---|
| 80 | l 31 | 
|---|
| 81 | L 32 | 
|---|
| 82 | ³ 33 | 
|---|
| 83 | £ 34 | 
|---|
| 84 | m 35 | 
|---|
| 85 | M 36 | 
|---|
| 86 | n 37 | 
|---|
| 87 | N 38 | 
|---|
| 88 | ñ 39 | 
|---|
| 89 | Ñ 40 | 
|---|
| 90 | o 41 | 
|---|
| 91 | O 42 | 
|---|
| 92 | ö 43 | 
|---|
| 93 | ó 44 | 
|---|
| 94 | Ó 45 | 
|---|
| 95 | p 46 | 
|---|
| 96 | P 47 | 
|---|
| 97 | q 48 | 
|---|
| 98 | Q 49 | 
|---|
| 99 | r 50 | 
|---|
| 100 | R 51 | 
|---|
| 101 | s 52 | 
|---|
| 102 | S 53 | 
|---|
| 103 | ¶ 54 | 
|---|
| 104 | Š 55 | 
|---|
| 105 | t 56 | 
|---|
| 106 | T 57 | 
|---|
| 107 | u 58 | 
|---|
| 108 | U 59 | 
|---|
| 109 | ü 60 | 
|---|
| 110 | v 61 | 
|---|
| 111 | V 62 | 
|---|
| 112 | w 63 | 
|---|
| 113 | W 64 | 
|---|
| 114 | x 65 | 
|---|
| 115 | X 66 | 
|---|
| 116 | y 67 | 
|---|
| 117 | Y 68 | 
|---|
| 118 | z 69 | 
|---|
| 119 | Z 70 | 
|---|
| 120 | Œ 71 | 
|---|
| 121 | ¬ 72 | 
|---|
| 122 | ¿ 73 | 
|---|
| 123 | ¯ 74 | 
|---|
| 124 | 0 75 | 
|---|
| 125 | 1 76 | 
|---|
| 126 | 2 77 | 
|---|
| 127 | 3 78 | 
|---|
| 128 | 4 79 | 
|---|
| 129 | 5 80 | 
|---|
| 130 | 6 81 | 
|---|
| 131 | 7 82 | 
|---|
| 132 | 8 83 | 
|---|
| 133 | 9 84 | 
|---|
| 134 | _ 85 | 
|---|
| 135 | - 86 | 
|---|
| 136 | ? 87 | 
|---|
| 137 | ! 88 | 
|---|
| 138 | ~ 89 | 
|---|
| 139 | ; 90 | 
|---|
| 140 | , 91 | 
|---|
| 141 | / 92 | 
|---|
| 142 | * 93 | 
|---|
| 143 | + 94 | 
|---|
| 144 | EOF | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 | no_of_lines=$(( (`cat $1 | wc -l` / $no_of_parts) + 1 )) | 
|---|
| 148 |  | 
|---|
| 149 | split -l $no_of_lines $1 $tempdir/part. | 
|---|
| 150 |  | 
|---|
| 151 | automaton=$tempdir/output.fst | 
|---|
| 152 |  | 
|---|
| 153 | cat <<EOF | fstcompile --acceptor --isymbols=$alphabet --keep_isymbols > $automaton | 
|---|
| 154 | EOF | 
|---|
| 155 |  | 
|---|
| 156 | n=0 | 
|---|
| 157 |  | 
|---|
| 158 | for f in $tempdir/part.* | 
|---|
| 159 | do | 
|---|
| 160 | temp1=`tempfile -d $tempdir` | 
|---|
| 161 | temp2=`tempfile -d $tempdir` | 
|---|
| 162 | temp3=`tempfile -d $tempdir` | 
|---|
| 163 |  | 
|---|
| 164 | n=$(( $n + 1 )) | 
|---|
| 165 | echo processing part $n | 
|---|
| 166 |  | 
|---|
| 167 | cat $f |\ | 
|---|
| 168 | lst2fstext |\ | 
|---|
| 169 | fstcompile --acceptor --isymbols=$alphabet --keep_isymbols |\ | 
|---|
| 170 | fstrmepsilon |\ | 
|---|
| 171 | fstdeterminize > $temp1 | 
|---|
| 172 | fstminimize $temp1 $temp2 | 
|---|
| 173 |  | 
|---|
| 174 | fstunion $automaton $temp2 | fstrmepsilon | fstdeterminize > $temp3 | 
|---|
| 175 | fstminimize $temp3 $automaton | 
|---|
| 176 | done | 
|---|
| 177 |  | 
|---|
| 178 | cat $automaton | fsttopsort | fstprint --acceptor | fsm2aut | aut2fsa > $2 | 
|---|
| 179 | rm -r $tempdir | 
|---|