Edinburgh Speech Tools  2.1-release
wfst_train_main.cc
Go to the documentation of this file.
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 using namespace std;
49 
50 LISP load_string_data(EST_WFST &wfst,EST_String &filename);
51 void wfst_train(EST_WFST &wfst, LISP data);
52 
53 static int wfst_train_main(int argc, char **argv);
54 
55 int main(int argc, char **argv)
56 {
57 
58  wfst_train_main(argc,argv);
59 
60  exit(0);
61  return 0;
62 }
63 
64 static int wfst_train_main(int argc, char **argv)
65 {
66  // Train a WFST from data building new states
67  EST_Option al;
68  EST_StrList files;
69  EST_String wfstfile;
70 
72  (argc, argv,
73  EST_String("[WFSTFILE] [input file0] ... [-o output file]\n")+
74  "Summary: Train a WFST on data\n"+
75  "-wfst <ifile> The WFST to start from\n"+
76  "-data <ifile> Sentences in the language recognised by WFST\n"+
77  "-o <ofile> Output file for trained WFST\n"+
78  "-heap <int> {210000}\n"+
79  " Set size of Lisp heap, needed for large rulesets\n",
80  files, al);
81 
82  if (al.present("-wfst"))
83  wfstfile = al.val("-wfst");
84  else
85  EST_error("no WFST specified");
86 
87  siod_init(al.ival("-heap"));
88  siod_est_init();
89 
90  EST_WFST wfst;
91  LISP data;
92 
93  if (wfst.load(wfstfile) != format_ok)
94  EST_error("failed to read WFST from \"%s\"",
95  (const char *)wfstfile);
96 
97  data = load_string_data(wfst,al.val("-data"));
98 
99  wfst_train(wfst,data);
100 
101  if (wfst.save(al.val("-o")) != write_ok)
102  EST_error("failed to write trained WFST to \"%s\"",
103  (const char *)al.val("-o"));
104 
105  return 0;
106 
107 }
108 
LISP load_string_data(EST_WFST &wfst, EST_String &filename)
Definition: wfst_train.cc:83
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:82
void siod_est_init()
Definition: siod_est.cc:409
The file was written successfully.
void wfst_train(EST_WFST &wfst, LISP data)
Definition: wfst_train.cc:188
EST_write_status save(const EST_String &filename, const EST_String type="ascii")
?
Definition: EST_WFST.cc:353
int main(int argc, char **argv)
#define EST_error
Definition: EST_error.h:104
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
#define format_ok
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
int siod_init(int heap_size=DEFAULT_HEAP_SIZE)
Definition: siod.cc:58
EST_String
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
Definition: cmd_line.cc:101
EST_read_status load(const EST_String &filename)
?
Definition: EST_WFST.cc:521