78 p_distinguished_symbol = 0;
91 delete_rule_prob_cache();
100 for (r=rs; r !=
NIL; r=
cdr(r))
131 delete_rule_prob_cache();
133 find_terms_nonterms(nt_list,term_list,lrules);
134 nonterminals.init(nt_list);
135 terminals.init(term_list);
138 p_distinguished_symbol =
141 cerr <<
"SCFG: no distinguished symbol" << endl;
143 for (r=lrules; r !=
NIL; r=
cdr(r))
148 cerr <<
"SCFG rule is malformed" << endl;
179 for (r=
NIL,p=rules.head(); p != 0; p=p->
next())
201 rs =
vload(filename,1);
218 if ((fd=fopen(outfile,
"w")) ==
NULL)
220 cerr <<
"scfg_train: failed to open file \"" << outfile <<
221 "\" for writing" << endl;
226 for (r=get_rules(); r !=
NIL; r=
cdr(r))
236 void EST_SCFG::rule_prob_cache()
242 p_prob_B =
new double**[num_nonterminals()];
243 p_prob_U =
new double*[num_nonterminals()];
244 for (i=0; i < num_nonterminals(); i++)
246 p_prob_B[i] =
new double*[num_nonterminals()];
247 p_prob_U[i] =
new double[num_terminals()];
248 memset(p_prob_U[i],0,
sizeof(
double)*num_terminals());
249 for (j=0; j < num_nonterminals(); j++)
251 p_prob_B[i][j] =
new double[num_nonterminals()];
252 memset(p_prob_B[i][j],0,
sizeof(
double)*num_nonterminals());
256 set_rule_prob_cache();
264 for (pp=rules.head(); pp != 0; pp = pp->
next())
268 int p = rules(pp).mother();
269 int q = rules(pp).daughter1();
270 int r = rules(pp).daughter2();
271 p_prob_B[p][q][r] = rules(pp).prob();
275 int p = rules(pp).mother();
276 int m = rules(pp).daughter1();
277 p_prob_U[p][m] = rules(pp).prob();
282 void EST_SCFG::delete_rule_prob_cache()
289 for (i=0; i < num_nonterminals(); i++)
291 for (j=0; j < num_nonterminals(); j++)
292 delete [] p_prob_B[i][j];
293 delete [] p_prob_B[i];
294 delete [] p_prob_U[i];
306 return s <<
"<<EST_SCFG_Rule>>";
310 #if defined(INSTANTIATE_TEMPLATES) 311 #include "../base_class/EST_TList.cc" 312 #include "../base_class/EST_TSortable.cc"
EST_read_status load(const EST_String &filename)
Load grammar from named file.
ostream & operator<<(ostream &s, const EST_SCFG_Rule &rule)
void find_terms_nonterms(EST_StrList &nt, EST_StrList &t, LISP rules)
void set_rule_prob_cache()
(re-)set rule probability caches
float get_c_float(LISP x)
#define Instantiate_TList(TYPE)
int siod_llength(LISP list)
#define Declare_TList(TYPE)
A stochastic context free grammar rule.
EST_Item * daughter2(const EST_Item *n)
return second daughter of n
void set_rules(LISP rules)
Set (or reset) rules from external source after construction.
EST_write_status save(const EST_String &filename)
Save current grammar to named file.
LISP vload(const char *fname, long cflag)
void set_rule(double prob, int p, int m)
const char * get_c_string(LISP x)
LISP cons(LISP x, LISP y)
The file was written successfully.
LISP get_rules()
Return rules as LISP list.
void append(const T &item)
add item onto end of list
void pprint_to_fd(FILE *fd, LISP exp)
LISP rintern(const char *name)
int strlist_member(const EST_StrList &l, const EST_String &s)
Return true if s is in list l.
void reverse(EST_Wave &sig)
EST_Item * daughter1(const EST_Item *n)
return first daughter of n
void clear(void)
remove all items in list