| 1 |
#!/bin/sh |
| 2 |
########################################################################### |
| 3 |
## ## |
| 4 |
## Language Technologies Institute ## |
| 5 |
## Carnegie Mellon University ## |
| 6 |
## Copyright (c) 2001-2008 ## |
| 7 |
## All Rights Reserved. ## |
| 8 |
## ## |
| 9 |
## Permission is hereby granted, free of charge, to use and distribute ## |
| 10 |
## this software and its documentation without restriction, including ## |
| 11 |
## without limitation the rights to use, copy, modify, merge, publish, ## |
| 12 |
## distribute, sublicense, and/or sell copies of this work, and to ## |
| 13 |
## permit persons to whom this work is furnished to do so, subject to ## |
| 14 |
## the following conditions: ## |
| 15 |
## 1. The code must retain the above copyright notice, this list of ## |
| 16 |
## conditions and the following disclaimer. ## |
| 17 |
## 2. Any modifications must be clearly marked as such. ## |
| 18 |
## 3. Original authors' names are not deleted. ## |
| 19 |
## 4. The authors' names are not used to endorse or promote products ## |
| 20 |
## derived from this software without specific prior written ## |
| 21 |
## permission. ## |
| 22 |
## ## |
| 23 |
## CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ## |
| 24 |
## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ## |
| 25 |
## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ## |
| 26 |
## SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ## |
| 27 |
## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ## |
| 28 |
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ## |
| 29 |
## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ## |
| 30 |
## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ## |
| 31 |
## THIS SOFTWARE. ## |
| 32 |
## ## |
| 33 |
########################################################################### |
| 34 |
## ## |
| 35 |
## Convert an EST WFST into C code (with awk and sed!) ## |
| 36 |
## ## |
| 37 |
########################################################################### |
| 38 |
|
| 39 |
|
| 40 |
sed '1,/EST_Header_End/d' $1 | |
| 41 |
awk 'BEGIN { |
| 42 |
mmm["a"] = 97; |
| 43 |
mmm["b"] = 98; |
| 44 |
mmm["c"] = 99; |
| 45 |
mmm["d"] = 100; |
| 46 |
mmm["e"] = 101; |
| 47 |
mmm["f"] = 102; |
| 48 |
mmm["g"] = 103; |
| 49 |
mmm["h"] = 104; |
| 50 |
mmm["i"] = 105; |
| 51 |
mmm["j"] = 106; |
| 52 |
mmm["k"] = 107; |
| 53 |
mmm["l"] = 108; |
| 54 |
mmm["m"] = 109; |
| 55 |
mmm["n"] = 110; |
| 56 |
mmm["o"] = 111; |
| 57 |
mmm["p"] = 112; |
| 58 |
mmm["q"] = 113; |
| 59 |
mmm["r"] = 114; |
| 60 |
mmm["s"] = 115; |
| 61 |
mmm["t"] = 116; |
| 62 |
mmm["u"] = 117; |
| 63 |
mmm["v"] = 118; |
| 64 |
mmm["w"] = 119; |
| 65 |
mmm["x"] = 120; |
| 66 |
mmm["y"] = 121; |
| 67 |
mmm["z"] = 122; |
| 68 |
mmm["#"] = 35; |
| 69 |
mmm["V"] = 86; |
| 70 |
mmm["N"] = 78; |
| 71 |
state = "0"; |
| 72 |
name="'`basename $1 .wfst`'"; |
| 73 |
} |
| 74 |
function symstate(sym,state) |
| 75 |
{ |
| 76 |
m = sprintf("((fsm_%s_state_%d * 128) + %d)",name,state,mmm[sym]); |
| 77 |
return m; |
| 78 |
} |
| 79 |
{if (NF == 3) |
| 80 |
{ |
| 81 |
state = substr($1,3); |
| 82 |
if (state != "0") |
| 83 |
{ |
| 84 |
printf("#define fsm_%s_trans_%d 0\n",name,trans); |
| 85 |
trans++; |
| 86 |
} |
| 87 |
printf("#define fsm_%s_state_%d %d\n",name,state,trans); |
| 88 |
} |
| 89 |
else if (NF == 4) |
| 90 |
{ |
| 91 |
printf("#define fsm_%s_trans_%d %s\n",name,trans,symstate($2,$3)); |
| 92 |
trans++; |
| 93 |
} |
| 94 |
} |
| 95 |
END {printf("#define fsm_%s_trans_%d 0\n",name,trans); |
| 96 |
trans++; |
| 97 |
printf("static short fsm_%s_trans[%d] = {\n",name,trans); |
| 98 |
for (i=0; i<trans-1; i++) |
| 99 |
{ |
| 100 |
printf(" fsm_%s_trans_%d,\n",name,i); |
| 101 |
} |
| 102 |
printf(" fsm_%s_trans_%d\n",name,i); |
| 103 |
printf("};\n"); |
| 104 |
printf("static cst_fsm fsm_%s = {\n",name); |
| 105 |
printf(" 128, /* vocab size */\n"); |
| 106 |
printf(" %d, /* num_transitions */\n",trans); |
| 107 |
printf(" fsm_%s_trans\n",name); |
| 108 |
printf("};\n"); |
| 109 |
}' |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|