49 qmap_error_margin = 0;
50 e_move_symbol_index = 0;
62 if(nodes.head() !=
NULL )
63 return nodes(nodes.head());
65 cerr <<
"LAttice has no nodes !" << endl;
72 bool Lattice::build_qmap(Bigram &g,
float error_margin)
85 Tlist<float> list_qmap;
87 qmap_error_margin = error_margin;
89 for (i = 0; i < g.size(); ++i){
90 for (j = 0; j < g.size(); ++j){
93 for(l_ptr=list_qmap.head();l_ptr != 0; l_ptr=l_ptr->
next())
94 if(fabs(list_qmap(l_ptr) - g.p(i,j)) <= error_margin){
100 list_qmap.append(g.p(i,j));
107 for(l_ptr=list_qmap.head();l_ptr != 0; l_ptr=l_ptr->
next())
108 if(fabs(list_qmap(l_ptr)) <= error_margin){
119 for(l_ptr=list_qmap.head();l_ptr != 0; l_ptr=l_ptr->
next())
125 for(l_ptr=list_qmap.head();l_ptr != 0; l_ptr=l_ptr->
next())
126 qmap(i++) = list_qmap(l_ptr);
131 cerr <<
"Built qmap with " << i <<
" entries" << endl;
138 Lattice::build_nmap(Bigram &g)
147 Tlist<EST_String> list_nmap;
150 for (j = 0; j < g.size() - 2; ++j){
151 if(g.words(j) ==
"!ENTER"){
152 cerr <<
"Wordlist contains special word !ENTER" << endl;
155 if(g.words(j) ==
"!EXIT"){
156 cerr <<
"Wordlist contains special word !EXIT" << endl;
165 for (j = 0; j < g.size() - 2; ++j)
166 list_nmap.append(g.words(j));
169 list_nmap.append(
"!ENTER");
170 list_nmap.append(
"!EXIT");
174 cerr << list_nmap << endl;
177 for(l_ptr=list_nmap.head();l_ptr != 0; l_ptr=l_ptr->
next())
183 for(l_ptr=list_nmap.head();l_ptr != 0; l_ptr=l_ptr->
next())
184 nmap(j++) = list_nmap(l_ptr);
187 cerr <<
"Built nmap with " << j <<
" entries" << endl;
194 Lattice::construct_alphabet(Bigram &g)
197 int i,j,enteri,exiti,aindex,qindex,nindex,count;
202 if(!build_qmap(g,1.0e-02) || !build_nmap(g))
207 Tlist<symbol_t*> list_alphabet;
212 enteri = g.size() - 2;
213 exiti = g.size() - 1;
218 for (j = 0; j < g.size(); ++j){
220 cerr <<
"constructing alphabet " << (
int)((
float)j*100/(float)g.size()) <<
"% \r";
223 nindex = nmap_name_to_index(
"!ENTER");
225 nindex = nmap_name_to_index(
"!EXIT");
227 nindex = nmap_name_to_index(g.words(j));
229 for (i = 0; i < g.size(); ++i){
231 qindex = qmap_value_to_index(g.p(i,j));
235 for(a_ptr=list_alphabet.tail();a_ptr!=
NULL;a_ptr=a_ptr->
prev()){
236 if( (list_alphabet(a_ptr)->nmap_index == nindex) &&
237 (list_alphabet(a_ptr)->qmap_index == qindex) ){
244 if(list_alphabet(a_ptr)->nmap_index != nindex)
253 list_alphabet.append(sym);
259 nindex = nmap_name_to_index(
"!ENTER");
260 qindex = qmap_value_to_index(0);
262 for(a_ptr=list_alphabet.tail();a_ptr!=
NULL;a_ptr=a_ptr->
prev())
263 if( (list_alphabet(a_ptr)->nmap_index == nindex) &&
264 (list_alphabet(a_ptr)->qmap_index == qindex) ){
273 list_alphabet.append(sym);
280 list_alphabet.append(sym);
285 for(a_ptr=list_alphabet.head();a_ptr !=
NULL; a_ptr=a_ptr->
next())
289 alphabet.resize(count);
291 for(a_ptr=list_alphabet.head();a_ptr !=
NULL; a_ptr=a_ptr->
next())
292 alphabet(count++) = *(list_alphabet(a_ptr));
295 list_alphabet.clear();
297 e_move_symbol_index = alphabet_index_lookup(-1,-1);
299 cerr <<
"Alphabet has " << count <<
" symbols " << endl;
306 Lattice::construct(Bigram &g)
318 int enteri = g.size() - 2;
319 int exiti = g.size() - 1;
320 int from_name,to_name;
327 nodes.append(enter_node);
330 for(i=0; i<nmap.n(); i++){
336 if(nmap(i) ==
"!ENTER"){
338 symbol = alphabet_index_lookup(i,qmap_value_to_index(0));
348 if(nmap(i) ==
"!EXIT")
349 final_nodes.append(n);
355 for (i = 0; i < g.size(); ++i){
356 cerr <<
"building lattice " << (
int)((
float)i*100/(float)g.size()) <<
"% \r";
357 for (j = 0; j < g.size(); ++j){
361 if((j != enteri) && (i != exiti)){
368 from_name = nmap_name_to_index(
"!ENTER");
370 from_name = nmap_name_to_index(g.words(i));
373 to_name = nmap_name_to_index(
"!EXIT");
375 to_name= nmap_name_to_index(g.words(j));
377 for (n_ptr = nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next()){
378 int name = nodes(n_ptr)->name(nodes(n_ptr)->name.head());
379 if(name == from_name)
386 cerr <<
"Couldn't find 'from' node " << nmap_index_to_name(from_name) << endl;
391 cerr <<
"Couldn't find 'to' node " << nmap_index_to_name(to_name) << endl;
396 symbol = alphabet_index_lookup(to_name,qmap_value_to_index(g.p(i,j)));
398 cerr <<
"Couldn't lookup symbol in alphabet !" << endl;
415 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
417 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
421 for (n_ptr = final_nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next())
424 cerr <<
"NFA has " << c1
425 <<
" nodes (" << c3 <<
" final)" 426 <<
" and " << c2 <<
" arcs" << endl;
450 int c,count,current_label,new_arcs_made;
455 cerr <<
"sorting arc lists" << endl;
458 cerr <<
"making new nodes" << endl;
472 if(new_node ==
NULL){
473 cerr <<
"Could not allocate any more memory";
476 new_node->
name = nodes(nodes.head())->name;
477 new_nodes.
append(new_node);
481 for (n_ptr = nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next()){
483 for (a_ptr = nodes(n_ptr)->arcs_out.head(); a_ptr != 0; a_ptr = a_ptr->
next()){
485 current_label = nodes(n_ptr)->arcs_out(a_ptr)->label;
490 new_name = nodes(n_ptr)->arcs_out(a_ptr)->to->name;
491 if(
final(nodes(n_ptr)->arcs_out(a_ptr)->to) )
493 while((a_ptr !=
NULL) &&
495 (nodes(n_ptr)->arcs_out(a_ptr->
next())->label == current_label)){
498 if( !is_final &&
final(nodes(n_ptr)->arcs_out(a_ptr->
next())->to) )
507 for (n2_ptr = new_nodes.
head(); n2_ptr != 0; n2_ptr = n2_ptr->
next())
508 if( new_nodes(n2_ptr)->name == new_name ){
516 if(new_node ==
NULL){
517 cerr <<
"Could not allocate any more memory";
519 for (n2_ptr = new_nodes.
head(); n2_ptr != 0; n2_ptr = n2_ptr->
next())
521 cerr <<
" after making " << count <<
" nodes" << endl;
525 new_node->
name = new_name;
526 new_nodes.
append(new_node);
529 new_final_nodes.
append(new_node);
543 for (n_ptr = new_nodes.
head(); n_ptr != 0; n_ptr = n_ptr->
next()){
546 cerr <<
"Processing node " << c
547 <<
" arcs=" << new_arcs_made <<
" \r";
551 for(l_ptr=new_nodes(n_ptr)->name.
head(); l_ptr != 0; l_ptr = l_ptr->
next()){
553 for(n2_ptr = nodes.head(); n2_ptr != 0; n2_ptr = n2_ptr->
next()){
555 if(nodes(n2_ptr)->name(nodes(n2_ptr)->name.head()) ==
556 new_nodes(n_ptr)->name(l_ptr))
557 arc_list += nodes(n2_ptr)->arcs_out;
574 for(a_ptr=arc_list.
head();a_ptr!=
NULL;a_ptr=a_ptr->
next()){
576 current_label=arc_list(a_ptr)->label;
581 new_name2 = arc_list(a_ptr)->to->name;
582 if(
final(arc_list(a_ptr)->to) )
584 while((a_ptr !=
NULL) &&
586 (arc_list(a_ptr->
next())->label == current_label)){
588 if( !is_final &&
final(arc_list(a_ptr)->to) )
597 for (n2_ptr = new_nodes.
head(); n2_ptr != 0; n2_ptr = n2_ptr->
next())
598 if( new_nodes(n2_ptr)->name == new_name2 ){
605 if(new_node ==
NULL){
606 cerr <<
"Could not allocate any more memory";
608 for (n2_ptr = new_nodes.
head(); n2_ptr != 0; n2_ptr = n2_ptr->
next())
610 cerr <<
" after making " << count <<
" nodes" << endl;
614 new_node->
name = new_name2;
615 new_nodes.
append(new_node);
616 link(new_nodes(n_ptr),new_node,current_label);
619 new_final_nodes.
append(new_node);
623 link(new_nodes(n_ptr),new_nodes(n2_ptr),current_label);
636 for (n_ptr = nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next())
643 final_nodes=new_final_nodes;
644 new_final_nodes.
clear();
647 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
649 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
653 for (n_ptr = final_nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next())
656 cerr <<
"DFA has " << c1
657 <<
" nodes (" << c3 <<
" final)" 658 <<
" and " << c2 <<
" arcs" << endl;
676 cerr <<
"Can't link null nodes" << endl;
685 new_arc->
label = label;
699 for (n_ptr = nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next()){
723 int num_nodes = nodes.length();
725 dst =
new bool*[num_nodes];
727 cerr <<
"Not enough memory" << endl;
730 for(i=0;i<num_nodes;i++){
731 dst[i] =
new bool[num_nodes];
733 cerr <<
"Not enough memory" << endl;
736 for(j=0;j<num_nodes;j++)
741 cerr <<
"final/non-final scan";
743 for(i=0,n_ptr=nodes.head();n_ptr->
next()!=
NULL;n_ptr=n_ptr->
next(),i++){
744 for(j=i+1,n2_ptr=n_ptr->
next();n2_ptr!=
NULL;n2_ptr=n2_ptr->
next(),j++){
746 if(
final(nodes(n_ptr)) && !
final(nodes(n2_ptr)))
748 else if(!
final(nodes(n_ptr)) &&
final(nodes(n2_ptr)))
762 if(!build_transition_function()){
763 cerr <<
"Couldn't build transition function" << endl;
767 if(!build_distinguished_state_table_from_transition_function(dst)){
768 cerr <<
"Couldn't build dst from transition function" << endl;
773 for(i=0;i<num_nodes;i++)
785 int i,j,i1,j1,scan_count,this_symbol;
799 for(i=0,n_ptr=nodes.head();n_ptr->
next()!=
NULL;n_ptr=n_ptr->
next(),i++){
801 for(j=i+1,n2_ptr=n_ptr->
next();n2_ptr!=
NULL;n2_ptr=n2_ptr->
next(),j++){
803 cerr <<
"scan " << scan_count <<
" : " << i <<
"," << j <<
" \r";
811 s_ptr=nodes(n_ptr)->arcs_out.head();
812 while(s_ptr !=
NULL){
816 this_symbol=nodes(n_ptr)->arcs_out(s_ptr)->label;
817 i1 = node_index(nodes(n_ptr)->arcs_out(s_ptr)->to);
820 for(a_ptr=nodes(n2_ptr)->arcs_out.head();
822 if(nodes(n2_ptr)->arcs_out(a_ptr)->label == this_symbol)
823 j1 = node_index(nodes(n2_ptr)->arcs_out(a_ptr)->to);
826 this_symbol=nodes(n2_ptr)->arcs_out(s_ptr)->label;
827 j1 = node_index(nodes(n2_ptr)->arcs_out(s_ptr)->to);
830 for(a_ptr=nodes(n_ptr)->arcs_out.head();
832 if(nodes(n_ptr)->arcs_out(a_ptr)->label == this_symbol)
833 i1 = node_index(nodes(n_ptr)->arcs_out(a_ptr)->to);
842 if( ( (i1>=0) && (j1>=0) && dst[i1][j1]) ||
843 ( (i1>=0) && (j1<0) ) ||
844 ( (j1>=0) && (i1<0) ) )
853 if( (s_ptr==
NULL) && (flag2) ){
854 s_ptr=nodes(n2_ptr)->arcs_out.head();
870 int i,j,i2,j2,k,scan_count;
871 int num_nodes = nodes.length();
872 int num_symbols = alphabet.n();
882 for(i=0;i<num_nodes-1;i++){
884 cerr <<
"scan " << scan_count <<
" : row " 887 for(j=i+1;j<num_nodes;j++){
891 for(k=0;k<num_symbols;k++){
896 if((i2<0) && (j2>=0)){
901 }
else if((j2<0) && (i2>=0)){
906 }
else if( (i2>0) && (j2>0) && dst[i2][j2] ){
931 int num_nodes = nodes.length();
935 if(!build_distinguished_state_table(dst)){
936 cerr <<
"Couldn't build distinguished state table" << endl;
941 int count=0,count2=0;
942 for(i=0;i<num_nodes-1;i++)
943 for(j=i+1;j<num_nodes;j++)
949 cerr <<
"There are " << count <<
" undistinguished pairs of nodes and " 950 << count2 <<
" distinguished pairs" << endl;
963 for(i=0,n_ptr=nodes.head();n_ptr->
next()!=
NULL;n_ptr=n_ptr->
next(),i++){
965 cerr <<
"merge, processing row " << i <<
" \r";
967 for(j=i+1,n2_ptr=n_ptr->
next();n2_ptr!=
NULL;n2_ptr=n2_ptr->
next(),j++){
974 merge_list.
append(nodes(n_ptr));
975 merge_list.
append(nodes(n2_ptr));
982 bool add1=
false,add2=
false;
983 for(n3_ptr=merge_list.
head();n3_ptr!=
NULL;n3_ptr=n3_ptr->
next()){
984 if(merge_list(n3_ptr) == nodes(n_ptr))
986 if(merge_list(n3_ptr) == nodes(n2_ptr))
992 merge_list.
append(nodes(n_ptr));
994 }
else if(add2 && !add1){
995 merge_list.
append(nodes(n2_ptr));
1010 for(n_ptr=merge_list.
head();n_ptr!=
NULL;n_ptr=n_ptr->
next())
1012 cerr <<
"merging " << count <<
" nodes out of ";
1015 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next())
1019 merge_nodes(merge_list);
1023 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next())
1025 cerr <<
" leaving " << count << endl;
1034 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
1036 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
1040 cerr <<
"Minimum state DFA has " << c1
1041 <<
" nodes and " << c2 <<
" arcs " << endl;
1046 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
1048 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
1052 cerr <<
"Pruned minimum state DFA has " << c1
1053 <<
" nodes and " << c2 <<
" arcs" << endl;
1055 for(i=0;i<num_nodes;i++)
1073 EST_Litem *n_ptr,*n2_ptr,*a_ptr,*a2_ptr;
1075 new_node =
new Node;
1085 for(a_ptr=l(n_ptr)->arcs_out.
head();a_ptr!=
NULL;a_ptr=a_ptr->
next())
1086 new_node->
arcs_out.append(l(n_ptr)->arcs_out(a_ptr));
1092 for(n2_ptr=nodes.head();n2_ptr!=
NULL;n2_ptr=n2_ptr->
next()){
1093 for(a2_ptr=nodes(n2_ptr)->arcs_out.head();a2_ptr!=
NULL;a2_ptr=a2_ptr->
next()){
1094 if(nodes(n2_ptr)->arcs_out(a2_ptr)->to == l(n_ptr))
1095 nodes(n2_ptr)->arcs_out(a2_ptr)->to = new_node;
1104 for(n2_ptr=nodes.head();n2_ptr!=
NULL;n2_ptr=n2_ptr->
next())
1105 if(nodes(n2_ptr) == l(n_ptr)){
1107 nodes(n2_ptr)->arcs_out.clear();
1108 delete nodes(n2_ptr);
1109 nodes.remove(n2_ptr);
1113 nodes.append(new_node);
1126 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
1129 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
1132 cerr <<
"merging arcs from node " << ++count
1133 <<
", before:" << count2;
1135 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr->
next()!=
NULL; a_ptr=a_ptr->
next()){
1138 for(a2_ptr=a_ptr->
next();a2_ptr!=
NULL; a2_ptr=a2_ptr->
next())
1140 if((nodes(n_ptr)->arcs_out(a_ptr)->label ==
1141 nodes(n_ptr)->arcs_out(a2_ptr)->label) &&
1143 (nodes(n_ptr)->arcs_out(a_ptr)->to ==
1144 nodes(n_ptr)->arcs_out(a2_ptr)->to) ){
1146 delete nodes(n_ptr)->arcs_out(a2_ptr);
1147 a2_ptr=nodes(n_ptr)->arcs_out.remove(a2_ptr);
1154 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
1157 cerr<<
", after:" << count2 << endl;
1161 cerr <<
" \r" << endl;
1172 for(a_ptr=arcs.
head(); a_ptr != 0; a_ptr=a_ptr->
next() ){
1173 prune_arc(node, arcs(a_ptr));
1183 remove_arc_from_nodes_out_list(node,arc);
1202 for (a_ptr = n->
arcs_out.head(); a_ptr != 0; a_ptr = a_ptr->
next())
1235 if(index < nmap.n())
1238 cerr <<
"Warning : nmap index " << index <<
" out of range" << endl;
1257 if(name > nmap(mid))
1260 else if(name < nmap(mid))
1271 cerr <<
"Lattice::nmap_name_to_index failed for '" 1272 << name <<
"'" << endl;
1280 else if(name == nmap(j))
1283 cerr <<
"Lattice::nmap_name_to_index failed for '" 1284 << name <<
"'" << endl;
1299 if(index < qmap.n())
1302 cerr <<
"Warning : qmap index " << index <<
" out of range" << endl;
1321 if(value > qmap(mid))
1324 else if(value < qmap(mid))
1335 if( fabs(qmap(i) - value) < fabs(qmap(j) - value) )
1349 for (n_ptr = nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next()){
1350 if(nodes(n_ptr) == n)
1351 return nodes.index(n_ptr);
1376 for (n_ptr = nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next()){
1380 for (n2_ptr = nodes.head(); n2_ptr != 0; n2_ptr = n2_ptr->
next()){
1382 for (a_ptr = nodes(n2_ptr)->arcs_out.head(); a_ptr != 0; a_ptr = a_ptr->
next())
1383 if(nodes(n2_ptr)->arcs_out(a_ptr)->to == nodes(n_ptr)){
1385 if(nodes(n2_ptr)->arcs_out(a_ptr)->label != e_move_symbol_index){
1386 word = alphabet_index_to_symbol(nodes(n2_ptr)->arcs_out(a_ptr)->label)->nmap_index;
1401 for(w_ptr=word_list.
head();w_ptr!=
NULL;w_ptr=w_ptr->
next()){
1404 new_node =
new Node;
1406 new_arc->
label = e_move_symbol_index;
1407 new_arc->
to = nodes(n_ptr);
1408 new_node->
arcs_out.append(new_arc);
1411 for (n2_ptr = nodes.head(); n2_ptr != 0; n2_ptr = n2_ptr->
next()){
1413 for (a_ptr = nodes(n2_ptr)->arcs_out.head(); a_ptr != 0; a_ptr = a_ptr->
next()){
1414 if(nodes(n2_ptr)->arcs_out(a_ptr)->to == nodes(n_ptr)){
1416 word = alphabet_index_to_symbol(nodes(n2_ptr)->arcs_out(a_ptr)->label)->nmap_index;
1417 if(word == word_list(w_ptr)){
1420 nodes(n2_ptr)->arcs_out(a_ptr)->to = new_node;
1426 nodes.append(new_node);
1455 if(final_nodes.length() > 1){
1456 cerr <<
" making single EXIT node" << endl;
1459 new_node =
new Node;
1461 for(n_ptr=final_nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
1464 new_arc->
label = e_move_symbol_index;
1465 new_arc->
to = final_nodes(n_ptr);
1466 final_nodes(n_ptr)->arcs_out.append(new_arc);
1472 final_nodes.clear();
1475 nodes.append(new_node);
1476 final_nodes.append(new_node);
1481 for(n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next()){
1483 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL; a_ptr=a_ptr->
next())
1487 cerr <<
"HTKified DFA has " << c1
1488 <<
" nodes and " << c2 <<
" arcs" << endl;
1497 for (n_ptr = final_nodes.head(); n_ptr != 0; n_ptr = n_ptr->
next())
1498 if(final_nodes(n_ptr) == n)
1511 name+=nmap_index_to_name(l(l_ptr)) +
",";
1525 return alphabet_symbol_to_index(&sym);
1532 if(index < alphabet.n())
1533 return &(alphabet[index]);
1535 cerr <<
"Warning : alphabet index " << index <<
" out of range" << endl;
1555 if(*sym > alphabet(mid))
1558 else if(*sym < alphabet(mid))
1565 if(*sym == alphabet(i))
1568 cerr <<
"Lattice::alphabet_symbol_to_index failed for '" 1569 << *sym <<
"' 1" << endl;
1575 if(*sym == alphabet(i))
1577 else if(*sym == alphabet(j))
1580 cerr <<
"Lattice::alphabet_symbol_to_index failed for '" 1581 << *sym <<
"' 2" << endl;
1583 cerr << i <<
" " << alphabet(i) << endl;
1584 cerr << j <<
" " << alphabet(j) << endl;
1607 int num_nodes = nodes.length();
1608 int num_symbols = alphabet.
n();
1610 if (num_nodes <= 0) {
1611 cerr <<
"No nodes, no transition function" << endl;
1615 cerr <<
"Warning : discarding existing transition function" << endl;
1618 tf =
new int*[num_nodes];
1619 for(i=0;i<num_nodes;i++)
1620 tf[i] =
new int[num_symbols];
1623 cerr <<
"Not enough memory to build transition function" 1624 <<
"(needed " << num_nodes*num_symbols*
sizeof(
int) <<
" bytes)" << endl;
1628 for(i=0,n_ptr=nodes.head();n_ptr!=
NULL;n_ptr=n_ptr->
next(),i++){
1630 cerr <<
"building transition function " << (
int)((
float)(i+1)*100/(
float)num_nodes) <<
"% \r";
1632 for(j=0;j<alphabet.n();j++){
1635 for(a_ptr=nodes(n_ptr)->arcs_out.head();a_ptr!=
NULL;a_ptr=a_ptr->
next()){
1637 if(j == nodes(n_ptr)->arcs_out(a_ptr)->label){
1638 tf[i][j] = node_index(nodes(n_ptr)->arcs_out(a_ptr)->to);
1669 if(start_node ==
NULL){
1670 start_node = nodes(nodes.head());
1671 current_symbol = input.
head();
1675 if(current_symbol ==
NULL){
1676 if(
final(start_node) )
1685 float max=-10000000;
1686 for (a_ptr = start_node->
arcs_out.head(); a_ptr != 0; a_ptr = a_ptr->
next()){
1688 if( alphabet_index_to_symbol(start_node->
arcs_out(a_ptr)->label)->nmap_index
1689 == nmap_name_to_index(input(current_symbol)) ){
1691 float x = viterbi_transduce(input,
1693 current_symbol->
next(),
1695 + qmap_index_to_value(alphabet_index_to_symbol(start_node->
arcs_out(a_ptr)->label)->qmap_index);
1721 if(start_node ==
NULL){
1722 start_node = nodes(nodes.head());
1728 if(current_frame == observations.
num_frames()){
1729 if(
final(start_node) )
1738 if(score < -100000){
1743 float max=-10000000;
1744 for (a_ptr = start_node->
arcs_out.head(); a_ptr != 0; a_ptr = a_ptr->
next()){
1747 alphabet_index_to_symbol(start_node->
arcs_out(a_ptr)->label)->nmap_index
1750 float this_observation = observations.
a(current_frame,observation_element);
1755 float x = viterbi_transduce(observations,
1761 + qmap_index_to_value(alphabet_index_to_symbol(start_node->
arcs_out(a_ptr)->label)->qmap_index)
1775 int observation_element =
1776 alphabet_index_to_symbol(start_node->
arcs_out(best)->label)->nmap_index;
1778 float this_observation = observations.
a(current_frame,observation_element);
1780 score += qmap_index_to_value(alphabet_index_to_symbol(start_node->
arcs_out(best)->label)->qmap_index) + this_observation;
1785 cerr << max << endl;
float mid(const EST_Item &item)
symbol_t * alphabet_index_to_symbol(int index)
void qsort(EST_TList< T > &a)
EST_String name_as_string(EST_IList &l)
bool build_transition_function()
bool build_distinguished_state_table(bool **&dst)
void sort_unique(EST_TList< T > &l)
EST_String nmap_index_to_name(int index)
int alphabet_index_lookup(int nmap_index, int qmap_index)
float qmap_index_to_value(int index)
void remove_arc_from_nodes_out_list(Node *n, Arc *a)
void ptr_qsort(EST_TList< T > &a)
int qmap_value_to_index(float value)
bool build_distinguished_state_table_from_transition_function(bool **&dst)
int index(EST_TList< T > &l, T &val, bool(*eq)(const EST_UItem *, const EST_UItem *)=NULL)
void prune_arcs(Node *node, EST_TList< Arc * > arcs)
float max(float a, float b)
bool build_distinguished_state_table_direct(bool **&dst)
int alphabet_symbol_to_index(symbol_t *sym)
void sort_by_label(EST_TList< Lattice::Arc * > &l)
bool operator!=(const symbol_t &s2) const
float & a(ssize_t i, int c=0)
bool accepts(EST_TList< symbol_t * > &string)
EST_Item * link(int l, EST_Item *n)
void merge_nodes(EST_TList< Node * > &l)
int nmap_name_to_index(const EST_String &name)
ssize_t num_frames() const
return number of frames in track
void merge_sort_unique(EST_TList< T > &l, EST_TList< T > &m)
void append(const T &item)
add item onto end of list
bool link(Node *n1, Node *n2, int label)
EST_TList< Arc * > arcs_out
void prune_arc(Node *node, Arc *arc)
float viterbi_transduce(EST_TList< EST_String > &input, EST_TList< Arc * > &path, EST_Litem *current_symbol=NULL, Node *start_node=NULL)
void clear(void)
remove all items in list