1 /*************************************************************************/
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
6 /* All Rights Reserved. */
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 */
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 */
32 /*************************************************************************/
33 /* Author : Alan W Black */
34 /* Date : June 1997 */
35 /*-----------------------------------------------------------------------*/
37 /* Probabilistic parser for (S)CFG */
39 /*=======================================================================*/
43 #include "EST_SCFG_Chart.h"
45 LISP FT_PParse_Utt(LISP utt)
47 // Parse Words (using part of speech tags) using given
48 // probabilistic grammar
49 EST_Utterance *u = get_c_utt(utt);
52 rules = siod_get_lval("scfg_grammar", NULL);
56 EST_SCFG grammar(rules);
58 scfg_parse(u->relation("Word"),"phr_pos",
59 u->create_relation("Syntax"),grammar);
64 LISP FT_MultiParse_Utt(LISP utt)
66 // You give them a parser and they just want more ...
67 // Because in some modes utterance may contain multiple sentences
68 // and the grammars we have only have only deal in more
69 // traditional sentences this tries to split the utterance into
70 // sentences and parse them individualls and add them to
71 // a single Syntax relation as a list of trees.
72 EST_Utterance *u = get_c_utt(utt);
74 EST_Item *s,*e,*st,*et;
76 rules = siod_get_lval("scfg_grammar", NULL);
79 eos_tree = siod_get_lval("scfg_eos_tree",NULL);
80 u->create_relation("Syntax");
82 chart.set_grammar_rules(rules);
84 for (st=u->relation("Token")->head(); st; st = st->next())
86 for (et=st->next(); et; et=et->next())
87 if (wagon_predict(et,eos_tree) != 0)
89 // Now find related words
90 s = first_leaf(st)->as_relation("Word");
91 e = first_leaf(et->next())->as_relation("Word");
92 chart.setup_wfst(s,e,"phr_pos");
94 chart.extract_parse(u->relation("Syntax"),s,e,TRUE);
101 void MultiParse(EST_Utterance &u)
103 // You give them a parser and they just want more ...
104 // Because in some modes utterance may contain multiple sentences
105 // and the grammars we have only have only deal in more
106 // traditional sentences this tries to split the utterance into
107 // sentences and parse them individualls and add them to
108 // a single Syntax release as a list of trees.
109 LISP rules, eos_tree;
112 rules = siod_get_lval("scfg_grammar", NULL);
114 EST_error("Couldn't find grammar rules\n");
115 eos_tree = siod_get_lval("scfg_eos_tree",NULL);
116 u.create_relation("Syntax");
117 EST_SCFG_Chart chart;
118 chart.set_grammar_rules(rules);
120 // produce a parse wherever there is a sentence end marker or
121 // the end of utterance.
123 for (w = s = u.relation("Word")->head(); w; w = w->next())
124 if (w->f_present("sentence_end") || (w->next() == 0))
126 chart.setup_wfst(s, w->next(), "phr_pos");
128 chart.extract_parse(u.relation("Syntax"), s, w->next(), TRUE);
133 void festival_parser_init(void)
135 proclaim_module("parser");
137 festival_def_utt_module("ProbParse",FT_PParse_Utt,
139 Parse part of speech tags in Word relation. Loads the grammar \n\
140 from scfg_grammar_filename and saves the best parse\n\
141 in the Syntax Relation.");
142 festival_def_utt_module("MultiProbParse",FT_MultiParse_Utt,
143 "(MultiProbParse UTT)\n\
144 Parse part of speech tags in Word relation. Unlike ProbParse this \n\
145 allows multiple sentences to appear in the one utterance. The CART \n\
146 tree in eos_tree is used to define end of sentence. Loads the \n\
147 grammar from scfg_grammar_filename and saves the best parse\n\
148 in the Syntax Relation.");