• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*---------------------------------------------------------------------------*
2  *  srec_debug.c  *
3  *                                                                           *
4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5  *                                                                           *
6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7  *  you may not use this file except in compliance with the License.         *
8  *                                                                           *
9  *  You may obtain a copy of the License at                                  *
10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
11  *                                                                           *
12  *  Unless required by applicable law or agreed to in writing, software      *
13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15  *  See the License for the specific language governing permissions and      *
16  *  limitations under the License.                                           *
17  *                                                                           *
18  *---------------------------------------------------------------------------*/
19 
20 #include "srec_debug.h"
21 #include "passert.h"
22 #include "portable.h"
23 #include "srec_tokens.h"
24 
25 
sprint_altwords(srec * rec,altword_token * awtoken,char * buf)26 static char* sprint_altwords(srec* rec, altword_token* awtoken, char* buf)
27 {
28   char *bufp = &buf[0];
29 
30   if (awtoken == AWTNULL) buf[0] = 0;
31   else
32   {
33     for (; awtoken; awtoken = awtoken->next_token)
34     {
35       bufp += sprintf(bufp, "%d,", awtoken->word);
36       ASSERT(awtoken->costdelta != MAXcostdata);
37     }
38     if (bufp > &buf[0]) *(bufp - 1) = 0;
39   }
40   return &buf[0];
41 }
42 
print_fsmnode_token(srec * rec,ftokenID token_index,char * msg)43 void print_fsmnode_token(srec* rec, ftokenID token_index, char* msg)
44 {
45   fsmnode_token *ftoken;
46   char word_backtrace_trans[512];
47   char *p;
48   char buf[64];
49   if (token_index == MAXftokenID)
50   {
51     printf("%sftoken %d\n", msg, token_index);
52     return;
53   }
54   ftoken = &rec->fsmnode_token_array[token_index];
55   printf("%sftoken %d rec %d@%d fsmnode %d cost %d word %d(%s) word_backtrace %d next_token_index %d ", msg, token_index, rec->id, rec->current_search_frame, ftoken->FSMnode_index, ftoken->cost, ftoken->word,
56          sprint_altwords(rec, ftoken->aword_backtrace, buf),
57          ftoken->word_backtrace, ftoken->next_token_index);
58 
59   p = "null";
60   if (ftoken->word < rec->context->olabels->num_words)
61     p = rec->context->olabels->words[ftoken->word];
62   sprint_bword_token_backtrace(word_backtrace_trans, sizeof(word_backtrace_trans), rec, ftoken->word_backtrace);
63   printf(" [%s] %s\n", p, word_backtrace_trans);
64 }
65 
print_fsmnode_token_list(srec * rec,stokenID token_index,char * msg)66 void print_fsmnode_token_list(srec* rec, stokenID token_index, char* msg)
67 {
68   printf(msg);
69 
70   while (token_index != MAXftokenID)
71   {
72     fsmnode_token* ftoken = &rec->fsmnode_token_array[token_index];
73     print_fsmnode_token(rec, token_index, "");
74     token_index = ftoken->next_token_index;
75   }
76 }
77 
print_search_status(srec * rec)78 void print_search_status(srec* rec)
79 {
80   int count, count2;
81   printf("SEARCH STATUS .. frame %d\n", rec->current_search_frame);
82   printf("prune_delta %d active_fsmarc_tokens %d\n",
83          rec->prune_delta, rec->active_fsmarc_tokens);
84   printf("num_new_states %d/%d fsmarc_token_array_size %d freelist %d\n", rec->num_new_states, rec->max_new_states, rec->fsmarc_token_array_size, rec->fsmarc_token_freelist);
85   printf("active_fsmnode_tokens %d num_models %d fsmnode_token_array_size %d freelist %d\n", rec->active_fsmnode_tokens, rec->num_model_slots_allocated, rec->fsmnode_token_array_size, rec->fsmnode_token_freelist);
86   count = count_fsmnode_token_list(rec, rec->active_fsmnode_tokens);
87   count2 = count_fsmarc_token_list(rec, rec->active_fsmarc_tokens);
88   printf("number active: %d fsmnodes %d fsmarcs\n", count, count2);
89 }
90 
print_fsmarc_token(srec * rec,stokenID token_index,char * msg)91 void print_fsmarc_token(srec* rec, stokenID token_index, char* msg)
92 {
93   int i;
94   srec_context *context = rec->context;
95 
96   fsmarc_token* stoken = &rec->fsmarc_token_array[token_index];
97   FSMarc* arc = &context->FSMarc_list[stoken->FSMarc_index];
98   costdata* costs = &stoken->cost[0];
99   wordID* wordids = &stoken->word[0];
100 	frameID* duration = &stoken->duration[0];
101   wtokenID* word_backtrace = &stoken->word_backtrace[0];
102   bigcostdata cost_offset = rec->accumulated_cost_offset[rec->current_search_frame-1];
103   char word_backtrace_trans[256];
104 
105   printf("%sstoken %4d at arc %4d ilabel %4d nextnode %4d states", msg, token_index,
106          stoken->FSMarc_index, arc->ilabel, arc->to_node);
107   for (i = 0; i < stoken->num_hmm_states; i++)
108   {
109     char buf[64];
110     char *p = "null";
111     if (wordids[i] < context->olabels->num_words) p = context->olabels->words[wordids[i]];
112     sprint_bword_token_backtrace(word_backtrace_trans, 256, rec, word_backtrace[i]);
113     printf(" w%d(%s)/%s/c%d/C%d/B%d/%d(%s)", wordids[i],
114            sprint_altwords(rec, stoken->aword_backtrace[i], buf),
115            p, costs[i], costs[i] + cost_offset, word_backtrace[i], duration[i], word_backtrace_trans);
116   }
117   printf("\n");
118 }
119 
print_fsmarc_token_list(srec * rec,stokenID token_index,char * msg)120 void print_fsmarc_token_list(srec* rec, stokenID token_index, char* msg)
121 {
122   printf(msg);
123   while (token_index != MAXstokenID)
124   {
125     fsmarc_token* stoken = &rec->fsmarc_token_array[token_index];
126     print_fsmarc_token(rec, token_index, "");
127     token_index = stoken->next_token_index;
128   }
129 }
130