Edinburgh Speech Tools  2.1-release
scfg_test_main.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
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 /* THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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 1997 */
35 /*-----------------------------------------------------------------------*/
36 /* Test a stochastic context free grammar with respect to a given */
37 /* corpus. */
38 /* */
39 /* Can test against a bracket corpus or simply parse it */
40 /* */
41 /*=======================================================================*/
42 #include <cstdlib>
43 #include <cstdio>
44 #include <iostream>
45 #include <fstream>
46 #include <cstring>
47 #include "EST.h"
48 #include "EST_SCFG.h"
49 #include "siod.h"
50 
51 using namespace std;
52 
53 static EST_String outfile = "-";
54 
55 static int scfg_test_main(int argc, char **argv);
56 
57 
58 
59 int main(int argc, char **argv)
60 {
61 
62  scfg_test_main(argc,argv);
63 
64  exit(0);
65  return 0;
66 }
67 
68 static int scfg_test_main(int argc, char **argv)
69 {
70  // Top level function generates a probabilistic grammar
71  EST_Option al;
72  EST_StrList files;
73 
75  (argc, argv,
76  EST_String("[options]\n")+
77  "Summary: Test a stochastic context free grammar against a corpus\n"+
78  "-grammar <ifile> Grammar file, one rule per line.\n"+
79  "-corpus <ifile> Single Corpus file, one bracketed sentence per line.\n"+
80  "-crossbrackets Measure cross bracket performance.\n"+
81  "-heap <int> {210000}\n"+
82  " Set size of Lisp heap, needed for large corpora\n"+
83  "-o <ofile> Output file for parsed sentences.\n",
84  files, al);
85 
86  if (al.present("-o"))
87  outfile = al.val("-o");
88  else
89  outfile = "-";
90 
91  siod_init(al.ival("-heap"));
92 
93  EST_SCFG_traintest grammar;
94 
95  if (al.present("-grammar"))
96  {
97  grammar.load(al.val("-grammar"));
98  }
99  else
100  {
101  cerr << "scfg_test: no grammar specified" << endl;
102  exit(1);
103  }
104 
105  if (al.present("-corpus"))
106  {
107  grammar.load_corpus(al.val("-corpus"));
108  }
109  else
110  {
111  cerr << "scfg_test: no corpus specified" << endl;
112  exit(1);
113  }
114 
115  // Test and summarise parsing of corpus
116  if (al.present("-crossbrackets"))
117  grammar.test_crossbrackets(); // parse and test brackets
118  else
119  grammar.test_corpus(); // only cross entropy
120 
121  return 0;
122 }
EST_read_status load(const EST_String &filename)
Load grammar from named file.
Definition: EST_SCFG.cc:197
A class used to train (and test) SCFGs is an extension of EST_SCFG.
Definition: EST_SCFG.h:259
int main(int argc, char **argv)
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:82
EST_String outfile
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
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