Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
wfst_train_main.cc
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 1999 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author : Alan W Black */
34 /* Date : October 1999 */
35 /*-----------------------------------------------------------------------*/
36 /* A training method for splitting states in a WFST from data */
37 /* */
38 /*=======================================================================*/
39 #include <cstdlib>
40 #include <cstdio>
41 #include <iostream>
42 #include <fstream>
43 #include <cstring>
44 #include "EST.h"
45 #include "EST_simplestats.h"
46 #include "EST_WFST.h"
47 
48 LISP load_string_data(EST_WFST &wfst,EST_String &filename);
49 void wfst_train(EST_WFST &wfst, LISP data);
50 
51 static int wfst_train_main(int argc, char **argv);
52 
53 int main(int argc, char **argv)
54 {
55 
56  wfst_train_main(argc,argv);
57 
58  exit(0);
59  return 0;
60 }
61 
62 static int wfst_train_main(int argc, char **argv)
63 {
64  // Train a WFST from data building new states
65  EST_Option al;
66  EST_StrList files;
67  EST_String wfstfile;
68  FILE *ofd;
69 
70  parse_command_line
71  (argc, argv,
72  EST_String("[WFSTFILE] [input file0] ... [-o output file]\n")+
73  "Summary: Train a WFST on data\n"+
74  "-wfst <ifile> The WFST to start from\n"+
75  "-data <ifile> Sentences in the language recognised by WFST\n"+
76  "-o <ofile> Output file for trained WFST\n"+
77  "-heap <int> {210000}\n"+
78  " Set size of Lisp heap, needed for large rulesets\n",
79  files, al);
80 
81  if (al.present("-o"))
82  {
83  if ((ofd=fopen(al.val("-o"),"w")) == NULL)
84  EST_error("can't open output file for writing \"%s\"",
85  (const char *)al.val("-o"));
86  }
87  else
88  ofd = stdout;
89 
90  if (al.present("-wfst"))
91  wfstfile = al.val("-wfst");
92  else
93  EST_error("no WFST specified");
94 
95  siod_init(al.ival("-heap"));
96  siod_est_init();
97 
98  EST_WFST wfst;
99  LISP data;
100 
101  if (wfst.load(wfstfile) != format_ok)
102  EST_error("failed to read WFST from \"%s\"",
103  (const char *)wfstfile);
104 
105  data = load_string_data(wfst,al.val("-data"));
106 
107  wfst_train(wfst,data);
108 
109  if (wfst.save(al.val("-o")) != write_ok)
110  EST_error("failed to write trained WFST to \"%s\"",
111  (const char *)al.val("-o"));
112 
113  return 0;
114 
115 }
116 
a call representing a weighted finite-state transducer
Definition: EST_WFST.h:154
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:76
EST_write_status save(const EST_String &filename, const EST_String type="ascii")
?
Definition: EST_WFST.cc:349
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
EST_read_status load(const EST_String &filename)
?
Definition: EST_WFST.cc:508