Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
scfg_test_main.cc
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
51static EST_String outfile = "-";
52
53static int scfg_test_main(int argc, char **argv);
54
55/** @name <command>scfg_test</command> <emphasis>Test the output of a parser</emphasis>
56 @id scfg-make-manual
57 * @toc
58 */
59
60
61//@{
62
63
64/**@name Synopsis
65 */
66//@{
67
68//@synopsis
69
70/**
71
72This program applies a stochastic context free grammar to a given
73corpus and reports the parsing accuracy and cross bracketing
74accuracy of the grammar with respect to the grammar.
75
76 */
77
78//@}
79
80/**@name OPTIONS
81 */
82//@{
83
84//@options
85
86//@}
87
88
89int main(int argc, char **argv)
90{
91
92 scfg_test_main(argc,argv);
93
94 exit(0);
95 return 0;
96}
97
98static int scfg_test_main(int argc, char **argv)
99{
100 // Top level function generates a probabilistic grammar
103
104 parse_command_line
105 (argc, argv,
106 EST_String("[options]\n")+
107 "Summary: Test a stochastic context free grammar against a corpus\n"+
108 "-grammar <ifile> Grammar file, one rule per line.\n"+
109 "-corpus <ifile> Single Corpus file, one bracketed sentence per line.\n"+
110 "-crossbrackets Measure cross bracket performance.\n"+
111 "-heap <int> {210000}\n"+
112 " Set size of Lisp heap, needed for large corpora\n"+
113 "-o <ofile> Output file for parsed sentences.\n",
114 files, al);
115
116 if (al.present("-o"))
117 outfile = al.val("-o");
118 else
119 outfile = "-";
120
121 siod_init(al.ival("-heap"));
122
123 EST_SCFG_traintest grammar;
124
125 if (al.present("-grammar"))
126 {
127 grammar.load(al.val("-grammar"));
128 }
129 else
130 {
131 cerr << "scfg_test: no grammar specified" << endl;
132 exit(1);
133 }
134
135 if (al.present("-corpus"))
136 {
137 grammar.load_corpus(al.val("-corpus"));
138 }
139 else
140 {
141 cerr << "scfg_test: no corpus specified" << endl;
142 exit(1);
143 }
144
145 // Test and summarise parsing of corpus
146 if (al.present("-crossbrackets"))
147 grammar.test_crossbrackets(); // parse and test brackets
148 else
149 grammar.test_corpus(); // only cross entropy
150
151 return 0;
152}
void load_corpus(const EST_String &filename)
EST_read_status load(const EST_String &filename)
Load grammar from named file.
Definition EST_SCFG.cc:193