59 static
EST_IList int_EST_IList_kv_def_EST_IList_s;
60 static
int int_EST_IList_kv_def_int_s;
68 #if defined(INSTANTIATE_TEMPLATES) 69 #include "../base_class/EST_TList.cc" 73 #include "../base_class/EST_TKVL.cc" 83 Instantiate_TIterator_T(KVL_int_EST_IList_t, KVL_int_EST_IList_t::IPointer, KVI_int_EST_IList_t, KVL_int_EST_IList_itt)
87 template class
EST_TList< TLIST_KVI_int_EST_IList_t_VAL >;
88 template class
EST_TItem< TLIST_KVI_int_EST_IList_t_VAL >;
100 static int check_distinguished(
const EST_WFST &nmwfst,
111 for (p=head(); p != 0; p=p->
next())
115 else if (i < (*
this)(p))
136 for (p=ms->
head(); p != 0; p = p->
next())
139 ns = index.
val(istring,found);
156 pairs_done.
val(p,found);
171 Agenda multistate_agenda;
178 p_in_symbols.copy(ndwfst.p_in_symbols);
179 p_out_symbols.copy(ndwfst.p_out_symbols);
186 p_start_state = add_state(ndwfst.
ms_type(start_state));
187 start_state->
set_name(p_start_state);
189 multistate_agenda.append(start_state);
191 while (multistate_agenda.length() > 0)
194 current = multistate_agenda.
first();
195 multistate_agenda.remove(multistate_agenda.head());
197 cout <<
"Determinizing " << summary() <<
" Agenda " 198 << multistate_agenda.length() << endl;
201 for (sp=current->
head(); sp != 0; sp=sp->
next())
209 if (pair_check(pairs_done,i,o,p_out_symbols.length()) == 1)
215 if ((i==o) && (i==0))
217 nms = apply_multistate(ndwfst,current,i,o);
218 if ((nms->
length() == 0) ||
225 if (new_name == p_num_states)
227 ns = add_state(ndwfst.
ms_type(nms));
229 multistate_agenda.append(nms);
237 p_states[current->
name()]
238 ->add_transition(nms->
weight(),
253 int in,
int out)
const 261 for (p=ms->
head(); p != 0; p=p->
next())
279 for (p=ms->
head(); p != 0; p = p->
next())
285 else if ((p_states((*ms)(p))->type() ==
wfst_final) &&
312 static int is_a_member(
const EST_IList &ii,
int i)
326 int ie = p_in_symbols.name(
get_c_string(epsilon_label()));
327 int oe = p_out_symbols.name(
get_c_string(epsilon_label()));
329 for (p=ms->
head(); p != 0; p=p->
next())
332 for (p=ii.
head(); p != 0; p=p->
next())
344 if (!is_a_member(ii,nstate))
363 Agenda multistate_agenda;
365 int i,o, new_name, n;
371 p_in_symbols.copy(wl.
first().p_in_symbols);
372 p_out_symbols.copy(wl.
first().p_out_symbols);
376 for (p=wl.
tail(); p != 0; p=p->
prev())
378 if (!wl(p).deterministic())
380 cout <<
"...intersection deterministing" << endl;
382 wl(p).determinize(tt);
384 start_state->
add(wl(p).start_state());
387 p_start_state = add_state(intersect_state_type(wl,start_state));
389 start_state->
set_name(p_start_state);
391 multistate_agenda.append(start_state);
393 while (multistate_agenda.length() > 0)
395 current = multistate_agenda.
first();
396 multistate_agenda.remove(multistate_agenda.head());
398 cout <<
"Intersection " << summary() <<
" Agenda " 399 << multistate_agenda.length() << endl;
403 for (i=0; i < p_in_symbols.length(); i++)
405 for (o=0; o < p_out_symbols.length(); o++)
407 if ((i==o) && (i==0))
412 for (n=0,p=wl.
head(),q=current->
head();
413 (p != 0) && (q != 0);
415 nms->
add(wl(p).transition((*current)(q),i,o));
416 if (intersect_state_type(wl,nms) ==
wfst_error)
422 if (new_name == p_num_states)
424 ns = add_state(intersect_state_type(wl,nms));
426 multistate_agenda.append(nms);
434 p_states[current->
name()]
435 ->add_transition(nms->
weight(),nms->
name(),i,o);
455 (p != 0) && (q != 0);
495 check_distinguished(nmwfst,p,q,marks,assumptions);
503 marks.find_state_map(state_map,num_new_states);
507 p_in_symbols.copy(nmwfst.p_in_symbols);
508 p_out_symbols.copy(nmwfst.p_out_symbols);
510 init(num_new_states);
511 p_start_state = state_map(nmwfst.p_start_state);
515 if (p_states[state_map(i)] == 0)
516 p_states[state_map(i)] =
517 copy_and_map_states(state_map,nmwfst.
state(i),nmwfst);
522 static int check_distinguished(
const EST_WFST &nmwfst,
571 if (assumptions.
length() == 0)
575 for (yp=from_p.
head(),zp=from_q.
head();
576 yp != 0; yp=yp->
next(),zp=zp->
next())
577 if (check_distinguished(nmwfst,from_p(yp),from_q(zp),
597 void EST_WFST::extend_alphabets(
const EST_WFST &b)
605 for (i=0; i<p_in_symbols.length(); i++)
606 ivocab.
append(in_symbol(i));
607 for (i=0; i<b.p_in_symbols.
length(); i++)
610 for (i=0; i<p_out_symbols.length(); i++)
611 ovocab.
append(out_symbol(i));
612 for (i=0; i<b.p_out_symbols.
length(); i++)
616 p_in_symbols.init(ivocab);
617 p_out_symbols.init(ovocab);
632 int mapped_state= state_map(s->
transitions(i)->state());
653 for (i=0; i < num_states(); i++)
663 static int noloopstostart(
const EST_WFST &a)
683 int EST_WFST::deterministiconstartstates(
const EST_WFST &a,
const EST_WFST &b)
const 701 tt != 0; tt=tt->next())
709 else if (tab(in,out) == 1)
727 noloopstostart(a) && noloopstostart(b) &&
728 deterministiconstartstates(a,b))
733 smap[0] = start_state();
740 p_states[smap(i)] = copy_and_map_states(smap,b.
state(i),b);
744 for (p=s->transitions.head(); p != 0; p=p->
next())
746 int mapped_state= smap(s->transitions(p)->state());
748 p_states[start_state()]->
749 add_transition(s->transitions(p)->weight(),
751 in_symbol(b.
in_symbol(s->transitions(p)->in_symbol())),
752 out_symbol(b.
out_symbol(s->transitions(p)->out_symbol())));
764 p_states[smap(i)] = copy_and_map_states(smap,b.
state(i),b);
768 p_states[start_state()]->add_transition(0.0,smap[b.
start_state()],
769 in_epsilon(), out_epsilon());
793 for (i=0; i < num_states(); i++)
798 p_states[i]->add_transition(0.0,smap[b.
start_state()],
799 in_epsilon(), out_epsilon());
805 p_states[smap(i)] = copy_and_map_states(smap,b.
state(i),b);
817 Agenda multistate_agenda;
825 p_in_symbols.copy(a.p_in_symbols);
826 p_out_symbols.copy(b.p_out_symbols);
834 p_start_state = add_state(intersect_state_type(wl,start_state));
836 start_state->
set_name(p_start_state);
838 multistate_agenda.append(start_state);
840 while (multistate_agenda.length() > 0)
842 current = multistate_agenda.
first();
843 multistate_agenda.remove(multistate_agenda.head());
846 for (i=0; i < p_in_symbols.length(); i++)
851 wl.
first().transduce(current->
first(),i,transa);
852 for (p=transa.
head(); p != 0; p=p->
next())
860 for (q = transb.
head(); q != 0; q=q->
next())
863 nms->
add(transa(p)->state());
864 nms->
add(transb(q)->state());
866 if (intersect_state_type(wl,nms) ==
wfst_error)
872 if (new_name == p_num_states)
874 int ns = add_state(intersect_state_type(wl,nms));
876 multistate_agenda.append(nms);
882 p_states[current->
name()]
884 i,transb(q)->out_symbol());
927 ab.current_tag = ++traverse_tag;
928 for (
int i=0; i < ab.p_num_states; i++)
929 ab.can_reach_final(i);
935 int EST_WFST::can_reach_final(
int state)
941 else if (p_states[state]->type() ==
wfst_error)
943 else if (p_states[state]->tag() == current_tag)
954 for (i=p_states[state]->transitions.head(); i != 0; i=i->
next())
957 if (can_reach_final(p_states[state]->transitions(i)->state()))
962 p_states[state]->set_type(r);
967 p_states[state]->set_tag(current_tag);
981 tab.
resize(p_in_symbols.length(),p_out_symbols.length());
983 for (
int i=0; i < p_num_states; i++)
986 for (
EST_Litem *t=state(i)->transitions.head(); t != 0; t=t->
next())
988 if (tab(state(i)->transitions(t)->in_symbol(),
989 state(i)->transitions(t)->out_symbol()) == 1)
992 tab(state(i)->transitions(t)->in_symbol(),
993 state(i)->transitions(t)->out_symbol()) = 1;
void minimize(const EST_WFST &a)
Build minimized form of a.
void complement(const EST_WFST &a)
Build complement of a.
void add_assumption(int y, int z, wfst_assumes &assumptions)
int transition(int state, int in, int out) const
Find (first) new state given in and out symbols.
int deterministic() const
True if WFST is deterministic.
a call representing a weighted finite-state transducer
int equivalent_to(int y, int z, wfst_assumes &assumptions)
int multistate_index(EST_WFST_MultiStateIndex &index, EST_WFST_MultiState *ms, int proposed)
#define Instantiate_TStructIterator_T(CONTAINER, IP, ENTRY, TAG)
const T & last() const
return const reference to last item in list
LISP append(LISP l1, LISP l2)
int length(void) const
The number of members in the discrete.
EST_String itoString(int n)
Make a EST_String object from an integer.
void transition_all(int state, int in, int out, EST_WFST_MultiState *ms) const
Find all possible transitions for given state/input/output.
void intersection(EST_TList< EST_WFST > &wl)
A specialised hash table for when the key is an EST_String.
void determinize(const EST_WFST &a)
Build determinized form of a.
int in_symbol(const EST_String &s) const
Map input symbol to input alphabet index.
int index(EST_TList< T > &l, T &val, bool(*eq)(const EST_UItem *, const EST_UItem *)=NULL)
int undistinguished(int p, int q)
Declare_TList_T(EST_WFST_MultiState *, EST_WFST_MultiStateP) typedef EST_TKVI< int
an internal class to EST_WFST used in holding multi-states when determinizing and find the intersecti...
void fill(const T &v)
fill matrix with value v
const char * get_c_string(LISP x)
EST_String error_name(const EST_Features &a)
Templated Key-Value Item. Serves as the items in the list of the EST_TKVL class.
an internal class for EST_WFST used to represent a state in a WFST
V & val(const K &key, int &found) const
int out_symbol(const EST_String &s) const
Map output symbol to output alphabet index.
enum wfst_state_type type() const
void compose(const EST_WFST &a, const EST_WFST &b)
const EST_WFST_State * state(int i) const
Return internal state information.
EST_WFST_Transition * add_transition(float w, int end, int in, int out)
void concat(const EST_WFST &a, const EST_WFST &b)
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
void uunion(EST_TList< EST_WFST > &wl)
Templated Key-Value list. Objects of type EST_TKVL contain lists which are accessed by a key of type ...
const T & first() const
return const reference to first item in list
#define Instantiate_TIterator_T(CONTAINER, IP, ENTRY, TAG)
void set_type(wfst_state_type t)
EST_IList KVI_int_EST_IList_t
int distinguished(int p, int q)
void distinguish(int p, int q)
void add_epsilon_reachable(EST_WFST_MultiState *ms) const
Extend multi-state with epsilon reachable states.
void mark_undistinguished(wfst_marks &marks, wfst_assumes &assumptions)
Declare_TList_N(KVI_int_EST_IList_t, 0) typedef EST_TList< EST_WFST_MultiState * > Agenda
void append(const T &item)
add item onto end of list
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
#define Instantiate_TList_T_MIN(TYPE, TAG)
int strlist_member(const EST_StrList &l, const EST_String &s)
Return true if s is in list l.
enum wfst_state_type ms_type(EST_WFST_MultiState *ms) const
Given a multi-state return type (final, ok, error)
An open hash table. The number of buckets should be set to allow enough space that there are relative...
void remove_error_states(const EST_WFST &a)
Remove error states from the WFST.
EST_WFST_MultiState * apply_multistate(const EST_WFST &wfst, EST_WFST_MultiState *ms, int in, int out) const
Transduce a multi-state given n and out.
int length() const
number of key value pairs in list
void resize(int rows, int cols, int set=1)
resize matrix
void difference(const EST_WFST &a, const EST_WFST &b)
void copy(const EST_WFST &wfst)
Copy from existing wfst.
wfst_translist transitions
void clear(void)
remove all items in list
void resize(int n, int set=1)
resize vector
int num_transitions() const