Edinburgh Speech Tools  2.1-release
EST_WFST.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 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 : November 1997 */
35 /*-----------------------------------------------------------------------*/
36 /* */
37 /* A class for representing Weighted Finite State Transducers */
38 /* */
39 /* This is based on various papers by Mehryar Mohri but not forgetting */
40 /* the Kay and Kaplan stuff as well as my own Koskenniemi implementation */
41 /* and finite state machine manipulations in my earlier lives */
42 /* */
43 /*=======================================================================*/
44 
45 #include <iostream>
46 #include "EST_Pathname.h"
47 #include "EST_cutils.h"
48 #include "EST_Token.h"
49 #include "EST_FileType.h"
50 #include "EST_WFST.h"
51 
52 #include "EST_TVector.h"
53 
54 Declare_TList_T(EST_WFST_Transition *, EST_WFST_TransitionP)
55 Declare_TVector_Base_T(EST_WFST_State *, NULL, NULL, EST_WFST_StateP)
56 
57 
58 #if defined(INSTANTIATE_TEMPLATES)
59 #include "../base_class/EST_TList.cc"
60 
61 Instantiate_TList_T(EST_WFST_Transition *, EST_WFST_TransitionP)
62 
63 #include "../base_class/EST_TVector.cc"
64 
65 Instantiate_TVector_T(EST_WFST_State *, EST_WFST_StateP)
66 
67 #endif
68 
69 using namespace std;
70 
71 // Used for marking states duration traversing functions
72 int EST_WFST::traverse_tag = 0;
73 
75 {
76  p_name = name;
77  p_type = wfst_error;
78  p_tag = 0;
79 }
80 
81 EST_WFST_State::EST_WFST_State(const EST_WFST_State &state)
82 {
83  EST_Litem *p;
84 
85  p_name = state.p_name;
86  p_type = state.p_type;
87  p_tag = state.p_tag;
88  for (p=state.transitions.head(); p != 0; p=p->next())
89  transitions.append(new EST_WFST_Transition(*state.transitions(p)));
90 }
91 
93 {
94  EST_Litem *p;
95 
96  for (p=transitions.head(); p != 0; p=p->next())
97  delete transitions(p);
98 
99 }
100 
102  int end,
103  int in,
104  int out)
105 {
106  // Add new transition
107  EST_WFST_Transition *s = new EST_WFST_Transition(w,end,in,out);
108  transitions.append(s);
109  return s;
110 }
111 
113 {
114  clear();
115 }
116 
118 {
119 
120  // delete up to p_num_states, rather than p_states.length() as
121  // only up to there is necessarily filled
122  for (int i=0; i < p_num_states; ++i)
123  delete p_states[i];
124  p_num_states = 0;
125  p_cumulate = 0;
126 }
127 
129 {
130  p_num_states = 0;
131  init(0);
132  p_start_state = 0;
133  current_tag = 0;
134 }
135 
136 void EST_WFST::copy(const EST_WFST &wfst)
137 {
138  clear();
139  p_in_symbols = wfst.p_in_symbols;
140  p_out_symbols = wfst.p_out_symbols;
141  p_start_state = wfst.p_start_state;
142  current_tag = wfst.current_tag;
143  p_num_states = wfst.p_num_states;
144  p_states.resize(p_num_states);
145  for (int i=0; i < p_num_states; ++i)
146  p_states[i] = new EST_WFST_State(*wfst.state(i));
147 }
148 
149 void EST_WFST::init(int init_num_states)
150 {
151  int i;
152 
153  clear();
154 
155  p_states.resize(init_num_states);
156  for (i=0; i < p_states.length(); i++)
157  p_states[i] = 0;
158  p_num_states = init_num_states;
159 
160 }
161 
162 void EST_WFST::init(LISP in_alphabet,LISP out_alphabet)
163 {
164  EST_StrList in,out;
165  LISP iin,oout;
166 
167  in.append("__epsilon__");
168  in.append("=");
169  for (iin=in_alphabet; iin != NIL; iin=cdr(iin))
170  if ((!streq(get_c_string(car(iin)),"__epsilon__")) &&
171  (!streq(get_c_string(car(iin)),"=")))
172  in.append(get_c_string(car(iin)));
173 
174  out.append("__epsilon__");
175  out.append("=");
176  for (oout=out_alphabet; oout != NIL; oout=cdr(oout))
177  if ((!streq(get_c_string(car(oout)),"__epsilon__")) &&
178  (!streq(get_c_string(car(oout)),"=")))
179  out.append(get_c_string(car(oout)));
180 
181  p_in_symbols.init(in);
182  p_out_symbols.init(out);
183 
184 }
185 
186 int EST_WFST::transduce(int state,const EST_String &in,EST_String &out) const
187 {
188  int nstate;
189  int in_i = p_in_symbols.name(in);
190  int out_i=0;
191 
192  if (in_i == -1)
193  {
194  cerr << "WFST transduce: \"" << in << "\" not in alphabet" << endl;
195  return WFST_ERROR_STATE;
196  }
197 
198  nstate = transduce(state,in_i,out_i);
199 
200  out = p_out_symbols.name(out_i);
201 
202  return nstate;
203 }
204 
205 void EST_WFST::transduce(int state,int in,wfst_translist &out) const
206 {
207  EST_WFST_State *s = p_states(state);
208  EST_Litem *i;
209 
210  for (i=s->transitions.head(); i != 0; i=i->next())
211  {
212  if (in == s->transitions(i)->in_symbol())
213  {
214  if (cumulate())
215  s->transitions(i)->set_weight(1+s->transitions(i)->weight());
216  out.append(s->transitions(i));
217  }
218  }
219 
220  // could return if any transitions were found
221 }
222 
223 int EST_WFST::transduce(int state,int in,int &out) const
224 {
225  EST_WFST_State *s = p_states(state);
226  EST_Litem *i;
227 
228  for (i=s->transitions.head(); i != 0; i=i->next())
229  {
230  if (in == s->transitions(i)->in_symbol())
231  {
232  out = s->transitions(i)->out_symbol();
233  return s->transitions(i)->state();
234  }
235  }
236 
237  return WFST_ERROR_STATE; // no match
238 }
239 
240 int EST_WFST::transition(int state,const EST_String &inout) const
241 {
242  if (inout.contains("/"))
243  return transition(state,inout.before("/"),inout.after("/"));
244  else
245  return transition(state,inout,inout);
246 }
247 
248 int EST_WFST::transition(int state,const EST_String &in,
249  const EST_String &out) const
250 {
251  int in_i = p_in_symbols.name(in);
252  int out_i = p_out_symbols.name(out);
253 
254  if ((in_i == -1) || (out_i == -1))
255  {
256  cerr << "WFST: one of " << in << "/" << out << " not in alphabet"
257  << endl;
258  return WFST_ERROR_STATE;
259  }
260 
261  return transition(state,in_i,out_i);
262 }
263 
264 int EST_WFST::transition(int state,int in, int out) const
265 {
266  // Finds first transition (hopefully deterministic)
267  float prob;
268  return transition(state,in,out,prob);
269 }
270 
271 EST_WFST_Transition *EST_WFST::find_transition(int state,int in, int out) const
272 {
273  // Finds first transition (hopefully deterministic)
274  EST_WFST_State *s = p_states(state);
275  EST_Litem *i;
276 
277  for (i=s->transitions.head(); i != 0; i=i->next())
278  {
279  if ((in == s->transitions(i)->in_symbol()) &&
280  (out == s->transitions(i)->out_symbol()))
281  {
282  if (cumulate())
283  s->transitions(i)->set_weight(1+s->transitions(i)->weight());
284  return s->transitions(i);
285  }
286  }
287 
288  return 0; // no match
289 }
290 
291 int EST_WFST::transition(int state,int in, int out,float &prob) const
292 {
293  // Finds first transition (hopefully deterministic)
294  EST_WFST_Transition *trans = find_transition(state,in,out);
295 
296  if (trans == 0)
297  {
298  prob = 0;
299  return WFST_ERROR_STATE;
300  }
301  else
302  {
303  prob = trans->weight();
304  return trans->state();
305  }
306 }
307 
309 {
310  int i;
311  EST_Litem *j;
312  int num_transitions, type, in, out, next_state;
313  float weight;
314 
315  for (i=0; i<p_num_states; i++)
316  {
317  num_transitions = p_states[i]->num_transitions();
318  fwrite(&num_transitions,4,1,fd);
319  if (p_states[i]->type() == wfst_final)
320  type = WFST_FINAL;
321  else if (p_states[i]->type() == wfst_nonfinal)
322  type = WFST_NONFINAL;
323  else if (p_states[i]->type() == wfst_licence)
324  type = WFST_LICENCE;
325  else
326  type = WFST_ERROR;
327  fwrite(&type,4,1,fd);
328  for (j=p_states[i]->transitions.head(); j != 0; j=j->next())
329  {
330  in = p_states[i]->transitions(j)->in_symbol();
331  out = p_states[i]->transitions(j)->out_symbol();
332  next_state = p_states[i]->transitions(j)->state();
333  weight = p_states[i]->transitions(j)->weight();
334 
335  if (in == out)
336  {
337  in *= -1;
338  fwrite(&in,4,1,fd);
339  }
340  else
341  {
342  fwrite(&in,4,1,fd);
343  fwrite(&out,4,1,fd);
344  }
345  fwrite(&next_state,4,1,fd);
346  fwrite(&weight,4,1,fd);
347  }
348  }
349 
350  return write_ok;
351 }
352 
354  const EST_String type)
355 {
356  FILE *ofd;
357  int i;
358  static EST_Regex needquotes(".*[()'\";., \t\n\r].*");
359  EST_Litem *j;
360 
361  if (filename == "-")
362  ofd = stdout;
363  else if ((ofd = fopen(filename,"wb")) == NULL)
364  {
365  cerr << "WFST: cannot write to file \"" << filename << "\"" << endl;
366  return misc_write_error;
367  }
368 
369  fprintf(ofd,"EST_File fst\n");
370  fprintf(ofd,"DataType %s\n",(const char *)type);
371  fprintf(ofd,"in %s\n",
372  (const char *)quote_string(EST_String("(")+
373  p_in_symbols.print_to_string(TRUE)+")",
374  "\"","\\",1));
375  fprintf(ofd,"out %s\n",
376  (const char *)quote_string(EST_String("(")+
377  p_out_symbols.print_to_string(TRUE)+")",
378  "\"","\\",1));
379  fprintf(ofd,"NumStates %d\n",p_num_states);
380  fprintf(ofd, "ByteOrder %s\n", ((EST_NATIVE_BO == bo_big) ? "10" : "01"));
381  fprintf(ofd,"EST_Header_End\n");
382 
383  if (type == "binary")
384  save_binary(ofd);
385  else
386  {
387  for (i=0; i < p_num_states; i++)
388  {
389  EST_WFST_State *s=p_states[i];
390  fprintf(ofd,"((%d ",s->name());
391  switch(s->type())
392  {
393  case wfst_final:
394  fprintf(ofd,"final ");
395  break;
396  case wfst_nonfinal:
397  fprintf(ofd,"nonfinal ");
398  break;
399  case wfst_licence:
400  fprintf(ofd,"licence ");
401  break;
402  default:
403  fprintf(ofd,"error ");
404  }
405  fprintf(ofd,"%d)\n",s->num_transitions());
406  for (j=s->transitions.head(); j != 0; j=j->next())
407  {
408  EST_String in = p_in_symbols.name(s->transitions(j)->in_symbol());
409  EST_String out=p_out_symbols.name(s->transitions(j)->out_symbol());
410  if (in.matches(needquotes))
411  fprintf(ofd," (%s ",(const char *)quote_string(in,"\"","\\",1));
412  else
413  fprintf(ofd," (%s ",(const char *)in);
414  if (out.matches(needquotes))
415  fprintf(ofd," %s ",(const char *)quote_string(out,"\"","\\",1));
416  else
417  fprintf(ofd," %s ",(const char *)out);
418  fprintf(ofd,"%d %g)\n",
419  s->transitions(j)->state(),
420  s->transitions(j)->weight());
421  }
422  fprintf(ofd,")\n");
423  }
424  }
425  if (ofd != stdout)
426  fclose(ofd);
427 
428  return write_ok;
429 }
430 
431 static float get_float(FILE *fd,int swap)
432 {
433  float f;
434  if (fread(&f,4,1,fd) != 1)
435  {
436  cerr << "Could not get float from WFST" << endl;
437  return 0;
438  }
439  if (swap) swapfloat(&f);
440  return f;
441 }
442 
443 static int get_int(FILE *fd,int swap)
444 {
445  int i;
446  if (fread(&i,4,1,fd) != 1)
447  {
448  cerr << "Could not get int from WFST" << endl;
449  return 0;
450  }
451  if (swap)
452  return SWAPINT(i);
453  else
454  return i;
455 }
456 
458  EST_Option &hinfo,
459  int num_states,
460  int swap)
461 {
462  (void)hinfo;
463  EST_read_status r;
464  int i,j, s;
465  int num_trans, state_type;
466  int in_sym, out_sym, next_state;
467  float trans_cost;
468 
469  r = format_ok;
470 
471  for (i=0; i < num_states; i++)
472  {
473  num_trans = get_int(fd,swap);
474  state_type = get_int(fd,swap);
475 
476  if (state_type == WFST_FINAL)
477  s = add_state(wfst_final);
478  else if (state_type == WFST_NONFINAL)
479  s = add_state(wfst_nonfinal);
480  else if (state_type == WFST_LICENCE)
481  s = add_state(wfst_licence);
482  else if (state_type == WFST_ERROR)
483  s = add_state(wfst_error);
484  else
485  {
486  cerr << "WFST load: unknown state type \"" <<
487  state_type << "\"" << endl;
488  r = read_format_error;
489  break;
490  }
491 
492  if (s != i)
493  {
494  cerr << "WFST load: internal error: unexpected state misalignment"
495  << endl;
496  r = read_format_error;
497  break;
498  }
499 
500  for (j=0; j < num_trans; j++)
501  {
502  in_sym = get_int(fd,swap);
503  if (in_sym < 0)
504  {
505  in_sym *= -1;
506  out_sym = in_sym;
507  }
508  else
509  out_sym = get_int(fd,swap);
510  next_state = get_int(fd,swap);
511  trans_cost = get_float(fd,swap);
512 
513  p_states[i]->add_transition(trans_cost,next_state,in_sym,out_sym);
514  }
515  }
516 
517  return r;
518 }
519 
520 
522 {
523  // Load a WFST from a file
524  FILE *fd;
525  EST_TokenStream ts;
526  EST_Option hinfo;
527  bool ascii;
528  EST_EstFileType t;
529  EST_read_status r;
530  int i,s;
531  int swap;
532 
533  if ((fd=fopen(filename,"r")) == NULL)
534  {
535  cerr << "WFST load: unable to open \"" << filename
536  << "\" for reading" << endl;
537  return read_error;
538  }
539  ts.open(fd,FALSE);
540  ts.set_quotes('"','\\');
541 
542  if (((r = read_est_header(ts, hinfo, ascii, t)) != format_ok) ||
543  (t != est_file_fst))
544  {
545  cerr << "WFST load: not a WFST file \"" << filename << "\"" <<endl;
546  return misc_read_error;
547  }
548 
549  // Value is a quoted quoted s-expression. Two reads is the
550  // safest way to unquote them
551  LISP inalpha =
553  LISP outalpha =
555  p_start_state = 0;
556 
557  clear();
558  init(inalpha,outalpha);
559 
560  int num_states = hinfo.ival("NumStates");
561  r = format_ok;
562 
563  if (!ascii)
564  {
565  if (!hinfo.present("ByteOrder"))
566  swap = FALSE; // ascii or not there for some reason
567  else if (((hinfo.val("ByteOrder") == "01") ? bo_little : bo_big)
568  != EST_NATIVE_BO)
569  swap = TRUE;
570  else
571  swap = FALSE;
572  r = load_binary(fd,hinfo,num_states,swap);
573  }
574  else
575  {
576  for (i=0; i < num_states; i++)
577  {
578  LISP sd = lreadf(fd);
579  if (i != get_c_int(car(car(sd))))
580  {
581  cerr << "WFST load: expected description of state " << i <<
582  " but found \"" << siod_sprint(sd) << "\"" << endl;
583  r = read_format_error;
584  break;
585  }
586  if (streq("final",get_c_string(car(cdr(car(sd))))))
587  s = add_state(wfst_final);
588  else if (streq("nonfinal",get_c_string(car(cdr(car(sd))))))
589  s = add_state(wfst_nonfinal);
590  else if (streq("licence",get_c_string(car(cdr(car(sd))))))
591  s = add_state(wfst_licence);
592  else
593  {
594  cerr << "WFST load: unknown state type \"" <<
595  siod_sprint(car(cdr(car(sd)))) << "\"" << endl;
596  r = read_format_error;
597  break;
598  }
599 
600  if (s != i)
601  {
602  cerr << "WFST load: internal error: unexpected state misalignment"
603  << endl;
604  r = read_format_error;
605  break;
606  }
607  if (load_transitions_from_lisp(s,cdr(sd)) != format_ok)
608  {
609  r = read_format_error;
610  break;
611  }
612  }
613  }
614 
615  fclose(fd);
616 
617  return r;
618 }
619 
620 EST_read_status EST_WFST::load_transitions_from_lisp(int s, LISP trans)
621 {
622  LISP t;
623 
624  for (t=trans; t != NIL; t=cdr(t))
625  {
626  float w = get_c_float(siod_nth(3,car(t)));
627  int end = get_c_int(siod_nth(2,car(t)));
628  int in = p_in_symbols.name(get_c_string(siod_nth(0,car(t))));
629  int out = p_out_symbols.name(get_c_string(siod_nth(1,car(t))));
630 
631  if ((in == -1) || (out == -1))
632  {
633  cerr << "WFST load: unknown vocabulary in state transition"
634  << endl;
635  cerr << "WFST load: " << siod_sprint(car(t)) << endl;
636  ssize_t i;
637  /* Remove all added transitions: */
638  for (i=0;i<p_states[s]->transitions.length();i++)
639  delete (p_states[s]->transitions).nth(i);
640  return read_format_error;
641  }
642  p_states[s]->add_transition(w,end,in,out);
643  }
644  return format_ok;
645 }
646 
648 {
649  int i;
650  int tt=0;
651 
652  for (i=0; i < p_num_states; i++)
653  tt += p_states(i)->transitions.length();
654 
655  return EST_String("WFST ")+itoString(p_num_states)+" states "+
656  itoString(tt)+" transitions ";
657 }
658 
659 
660 void EST_WFST::more_states(int new_max)
661 {
662  int i;
663 
664  p_states.resize(new_max);
665  for (i=p_num_states; i < new_max; i++)
666  p_states[i] = 0;
667 }
668 
670 {
671  // Add new state of given type
672  EST_WFST_State *s = new EST_WFST_State(p_num_states);
673 
674  if (p_num_states >= p_states.length())
675  {
676  // Need more space for states
677  more_states((int)((float)(p_states.length()+1)*1.5));
678  }
679 
680  p_states[p_num_states] = s;
681  s->set_type(state_type);
682  p_num_states++;
683 
684  return s->name();
685 }
686 
688 {
689  // cumulate transitions during recognition
690  EST_Litem *j;
691  int i;
692 
693  p_cumulate = 1;
694  for (i=0; i < p_num_states; i++)
695  {
696  EST_WFST_State *s=p_states[i];
697  for (j=s->transitions.head(); j !=0; j=j->next())
698  s->transitions(j)->set_weight(0);
699  }
700 }
701 
703 {
704  EST_Litem *j;
705  int i;
706  float t;
707 
708  p_cumulate = 0;
709  for (i=0; i < p_num_states; i++)
710  {
711  EST_WFST_State *s=p_states[i];
712  for (t=0,j=s->transitions.head(); j !=0; j=j->next())
713  t += s->transitions(j)->weight();
714  if (t > 0)
715  for (j=s->transitions.head(); j !=0; j=j->next())
716  s->transitions(j)->set_weight(s->transitions(j)->weight()/t);
717  }
718 }
int transduce(const EST_WFST &wfst, const EST_StrList &in, EST_StrList &out)
#define WFST_LICENCE
Definition: EST_WFST.h:91
float end(const EST_Item &item)
Definition: EST_item_aux.cc:96
int contains(const char *s, ssize_t pos=-1) const
Does it contain this substring?
Definition: EST_String.h:365
int transition(int state, int in, int out) const
Find (first) new state given in and out symbols.
Definition: EST_WFST.cc:264
float get_c_float(LISP x)
Definition: slib.cc:1858
EST_write_status
#define SWAPINT(x)
Definition: EST_cutils.h:75
#define WFST_FINAL
Definition: EST_WFST.h:88
int transduce(int state, int in, int &out) const
Transduce in to out from state.
Definition: EST_WFST.cc:223
int add_state(enum wfst_state_type state_type)
Add a new state, returns new name.
Definition: EST_WFST.cc:669
an internal class for EST_WFST for representing transitions in an WFST
Definition: EST_WFST.h:61
a call representing a weighted finite-state transducer
Definition: EST_WFST.h:154
void clear()
clear removing existing states if any
Definition: EST_WFST.cc:117
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:82
A Regular expression class to go with the CSTR EST_String class.
Definition: EST_Regex.h:56
EST_EstFileType
Definition: EST_FileType.h:50
long int get_c_int(LISP x)
Definition: slib.cc:1850
#define NIL
Definition: siod_defs.h:92
int state() const
Definition: EST_WFST.h:76
#define WFST_NONFINAL
Definition: EST_WFST.h:89
EST_String itoString(int n)
Make a EST_String object from an integer.
Definition: util_io.cc:141
#define WFST_ERROR
Definition: EST_WFST.h:90
int ssize_t
#define Instantiate_TVector_T(TYPE, TAG)
Definition: EST_TVectorI.h:52
#define streq(X, Y)
Definition: EST_cutils.h:57
EST_write_status save_binary(FILE *fd)
Definition: EST_WFST.cc:308
#define WFST_ERROR_STATE
Definition: EST_WFST.h:52
float weight() const
Definition: EST_WFST.h:75
void start_cumulate()
Clear and start cumulation.
Definition: EST_WFST.cc:687
LISP siod_nth(int nth, LISP list)
Definition: siod.cc:214
EST_UItem * next()
Definition: EST_UList.h:55
int open(const EST_String &filename)
open a EST_TokenStream for a file.
Definition: EST_Token.cc:213
void stop_cumulate()
Stop cumulation and calculate probabilities on transitions.
Definition: EST_WFST.cc:702
An error occurred while reading.
LISP lreadf(FILE *f)
Definition: slib.cc:1582
~EST_WFST()
Definition: EST_WFST.cc:112
const char * get_c_string(LISP x)
Definition: slib.cc:638
EST_String siod_sprint(LISP exp)
Definition: slib_file.cc:208
#define misc_write_error
wfst_state_type
Definition: EST_WFST.h:85
an internal class for EST_WFST used to represent a state in a WFST
Definition: EST_WFST.h:98
The file was written successfully.
enum wfst_state_type type() const
Definition: EST_WFST.h:116
void swapfloat(float *f)
Definition: EST_swapping.cc:53
EST_WFST()
?
Definition: EST_WFST.cc:128
LISP read_from_string(const char *)
Definition: slib_str.cc:65
const EST_WFST_State * state(int i) const
Return internal state information.
Definition: EST_WFST.h:226
EST_WFST_State(int name)
Definition: EST_WFST.cc:74
EST_WFST_Transition * add_transition(float w, int end, int in, int out)
Definition: EST_WFST.cc:101
#define FALSE
Definition: EST_bool.h:119
EST_write_status save(const EST_String &filename, const EST_String type="ascii")
?
Definition: EST_WFST.cc:353
EST_read_status read_est_header(EST_TokenStream &ts, EST_Option &hinfo, bool &ascii, EST_EstFileType &t)
Definition: est_file.cc:143
Declare_TList_T(EST_WFST_Transition *, EST_WFST_TransitionP) Declare_TVector_Base_T(EST_WFST_State *
#define misc_read_error
The file exists but is not in the format specified.
NULL
Definition: EST_WFST.cc:55
EST_read_status load_binary(FILE *fd, EST_Option &hinfo, int num_states, int swap)
Definition: EST_WFST.cc:457
f
Definition: EST_item_aux.cc:48
void set_type(wfst_state_type t)
Definition: EST_WFST.h:117
void set_quotes(char q, char e)
set characters to be used as quotes and escape, and set quote mode
Definition: EST_Token.h:353
int matches(const char *e, ssize_t pos=0) const
Exactly match this string?
Definition: EST_String.cc:651
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
void append(const T &item)
add item onto end of list
Definition: EST_TList.h:196
#define Declare_TVector_Base_T(TYPE, DEFAULT, ERROR, TAG)
Definition: EST_TVectorI.h:64
EST_read_status
size_t length(void) const
Length of string ({not} length of underlying chunk)
Definition: EST_String.h:231
EST_WFST_Transition * find_transition(int state, int in, int out) const
Find (first) transition given in and out symbols.
Definition: EST_WFST.cc:271
#define format_ok
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
EST_String summary() const
Definition: EST_WFST.cc:647
#define EST_NATIVE_BO
Definition: EST_cutils.h:72
EST_UItem * head() const
Definition: EST_UList.h:97
#define Instantiate_TList_T(TYPE, TAG)
Definition: EST_TListI.h:58
LISP car(LISP x)
Definition: slib_list.cc:115
EST_String after(int pos, int len=1) const
Part after pos+len.
Definition: EST_String.h:308
void init(int init_num_states=10)
Clear with (estimation of number of states required)
Definition: EST_WFST.cc:149
EST_String before(int pos, int len=0) const
Part before position.
Definition: EST_String.h:276
EST_String
int name() const
Definition: EST_WFST.h:114
EST_String quote_string(const EST_String &s, const EST_String &quote, const EST_String &escape, int force)
Definition: EST_Token.cc:844
#define TRUE
Definition: EST_bool.h:118
void copy(const EST_WFST &wfst)
Copy from existing wfst.
Definition: EST_WFST.cc:136
wfst_translist transitions
Definition: EST_WFST.h:104
EST_read_status load(const EST_String &filename)
?
Definition: EST_WFST.cc:521
LISP cdr(LISP x)
Definition: slib_list.cc:124
int num_transitions() const
Definition: EST_WFST.h:115