julius/result_msock.c

Go to the documentation of this file.
00001 
00017 /*
00018  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00019  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00020  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00021  * All rights reserved
00022  */
00023 
00024 #include <julius.h>
00025 #include <time.h>
00026 
00027 /**********************************************************************/
00028 /* process online/offline status  */
00029 
00040 static void
00041 msock_status_process_online()
00042 {
00043   module_send(module_sd, "<STARTPROC/>\n.\n");
00044 }
00055 static void
00056 msock_status_process_offline()
00057 {
00058   module_send(module_sd, "<STOPPROC/>\n.\n");
00059 }
00060 
00061 /**********************************************************************/
00062 /* decode outcode "WLPSwlps" to each boolean value */
00063 /* default: "WLPS" */
00064 static boolean out1_word = FALSE, out1_lm = FALSE, out1_phone = FALSE, out1_score = FALSE;
00065 static boolean out2_word = TRUE, out2_lm = TRUE, out2_phone = TRUE, out2_score = TRUE;
00066 static boolean out1_never = TRUE, out2_never = FALSE;
00067 #ifdef CONFIDENCE_MEASURE
00068 static boolean out2_cm = TRUE;
00069 #endif
00070 
00083 void
00084 decode_output_selection(char *str)
00085 {
00086   int i;
00087   out1_word = out1_lm = out1_phone = out1_score = FALSE;
00088   out2_word = out2_lm = out2_phone = out2_score = FALSE;
00089 #ifdef CONFIDENCE_MEASURE
00090   out2_cm = FALSE;
00091 #endif
00092   for(i = strlen(str) - 1; i >= 0; i--) {
00093     switch(str[i]) {
00094     case 'W': out2_word  = TRUE; break;
00095     case 'L': out2_lm    = TRUE; break;
00096     case 'P': out2_phone = TRUE; break;
00097     case 'S': out2_score = TRUE; break;
00098     case 'w': out1_word  = TRUE; break;
00099     case 'l': out1_lm    = TRUE; break;
00100     case 'p': out1_phone = TRUE; break;
00101     case 's': out1_score = TRUE; break;
00102 #ifdef CONFIDENCE_MEASURE
00103     case 'C': out2_cm    = TRUE; break;
00104 #endif
00105     default:
00106       j_printerr("Error: unknown outcode `%c', ignored\n", str[i]);
00107       break;
00108     }
00109   }
00110   out1_never = ! (out1_word | out1_lm | out1_phone | out1_score);
00111   out2_never = ! (out2_word | out2_lm | out2_phone | out2_score
00112 #ifdef CONFIDENCE_MEASURE
00113                   | out2_cm
00114 #endif
00115                   );
00116 
00117 }
00118 
00133 static void
00134 msock_word_out1(WORD_ID w, WORD_INFO *winfo)
00135 {
00136   int j;
00137   static char buf[MAX_HMMNAME_LEN];
00138 
00139   if (out1_word) {
00140     module_send(module_sd, " WORD=\"%s\"", winfo->woutput[w]);
00141   }
00142   if (out1_lm) {
00143     module_send(module_sd, " CLASSID=\"%s\"", winfo->wname[w]);
00144   }
00145   if (out1_phone) {
00146     module_send(module_sd, " PHONE=\"");
00147     for(j=0;j<winfo->wlen[w];j++) {
00148       center_name(winfo->wseq[w][j]->name, buf);
00149       if (j == 0) module_send(module_sd, "%s", buf);
00150       else module_send(module_sd, " %s", buf);
00151     }
00152     module_send(module_sd, "\"");
00153   }
00154 }
00155 
00170 static void
00171 msock_word_out2(WORD_ID w, WORD_INFO *winfo)
00172 {
00173   int j;
00174   static char buf[MAX_HMMNAME_LEN];
00175 
00176   if (out2_word) {
00177     module_send(module_sd, " WORD=\"%s\"", winfo->woutput[w]);
00178   }
00179   if (out2_lm) {
00180     module_send(module_sd, " CLASSID=\"%s\"", winfo->wname[w]);
00181   }
00182   if (out2_phone) {
00183     module_send(module_sd, " PHONE=\"");
00184     for(j=0;j<winfo->wlen[w];j++) {
00185       center_name(winfo->wseq[w][j]->name, buf);
00186       if (j == 0) module_send(module_sd, "%s", buf);
00187       else module_send(module_sd, " %s", buf);
00188     }
00189     module_send(module_sd, "\"");
00190   }
00191 }
00192 
00193 
00194 /**********************************************************************/
00195 /* 1st pass output */
00196 
00207 static void
00208 msock_pass1_begin()
00209 {
00210 }
00211 
00234 static void
00235 msock_pass1_current(int t, WORD_ID *seq, int num, LOGPROB score, LOGPROB LMscore, WORD_INFO *winfo)
00236 {
00237   int i;
00238 
00239   if (out1_never) return;       /* no output specified */
00240 
00241   if (out1_score) {
00242     module_send(module_sd, "<RECOGOUT>\n  <PHYPO PASS=\"1\" SCORE=\"%f\" FRAME=\"%d\" TIME=\"%ld\">\n", score, t, time(NULL));
00243   } else {
00244     module_send(module_sd, "<RECOGOUT>\n  <PHYPO PASS=\"1\" FRAME=\"%d\" TIME=\"%ld\">\n", t, time(NULL));
00245   }
00246   for (i=0;i<num;i++) {
00247     module_send(module_sd, "    <WHYPO");
00248     msock_word_out1(seq[i], winfo);
00249     module_send(module_sd, "/>\n");
00250   }
00251   module_send(module_sd, "  </PHYPO>\n</RECOGOUT>\n.\n");
00252 }
00253 
00277 static void
00278 msock_pass1_final(WORD_ID *seq, int num, LOGPROB score, LOGPROB LMscore, WORD_INFO *winfo)
00279 {
00280   int i;
00281 
00282   if (out1_never) return;       /* no output specified */
00283 
00284   if (out1_score) {
00285     module_send(module_sd, "<RECOGOUT>\n  <SHYPO PASS=\"1\" SCORE=\"%f\">\n", score);
00286   } else {
00287     module_send(module_sd, "<RECOGOUT>\n  <SHYPO PASS=\"1\">\n", score);
00288   }
00289   for (i=0;i<num;i++) {
00290     module_send(module_sd, "    <WHYPO");
00291     msock_word_out1(seq[i], winfo);
00292     module_send(module_sd, "/>\n");
00293   }
00294   module_send(module_sd, "  </SHYPO>\n</RECOGOUT>\n.\n");
00295 }
00296 
00307 static void
00308 msock_pass1_end()
00309 {
00310   /* no op */
00311 }
00312 
00313 /**********************************************************************/
00314 /* 2nd pass output */
00315 
00328 static void
00329 msock_pass2_begin()
00330 {
00331   if (out2_never) return;       /* no output */
00332   module_send(module_sd, "<RECOGOUT>\n");
00333 }
00334 
00351 static void
00352 msock_pass2(NODE *hypo, int rank, WORD_INFO *winfo)
00353 {
00354   int i;
00355 
00356   if (out2_never) return;       /* no output specified */
00357 
00358   if (hypo == NULL) return;
00359 
00360   module_send(module_sd, "  <SHYPO RANK=\"%d\"", rank);
00361   if (out2_score) {
00362     module_send(module_sd, " SCORE=\"%f\"", hypo->score);
00363 #ifdef USE_NGRAM
00364     if (separate_score_flag) {
00365       module_send(module_sd, " AMSCORE=\"%f\" LMSCORE=\"%f\"", hypo->score - hypo->totallscore, hypo->totallscore);
00366     }
00367 #endif
00368   }
00369 #ifdef USE_DFA
00370   /* output which grammar the best hypothesis belongs to */
00371   /* determine only by the last word */
00372   module_send(module_sd, " GRAM=\"%d\"", multigram_get_gram_from_category(winfo->wton[hypo->seq[0]]));
00373 #endif
00374   
00375   module_send(module_sd, ">\n");
00376   for (i=hypo->seqnum-1;i>=0;i--) {
00377     module_send(module_sd, "    <WHYPO");
00378     msock_word_out2(hypo->seq[i], winfo);
00379 #ifdef CONFIDENCE_MEASURE
00380 #ifdef CM_MULTIPLE_ALPHA
00381     /* currently not handle multiple alpha output */
00382 #else
00383     if (out2_cm) {
00384       module_send(module_sd, " CM=\"%5.3f\"", hypo->cmscore[i]);
00385     }
00386 #endif
00387 #endif /* CONFIDENCE_MEASURE */
00388     module_send(module_sd, "/>\n");
00389   }
00390   
00391   module_send(module_sd, "  </SHYPO>\n");
00392 }
00393 
00404 static void
00405 msock_pass2_end()
00406 {
00407   if (out2_never) return;       /* no output */
00408   module_send(module_sd, "</RECOGOUT>\n.\n");
00409 }
00410 
00411 
00412 #ifdef GRAPHOUT
00413 
00414 /**********************************************************************/
00415 /* word graph output */
00416 
00431 static void
00432 msock_graph(WordGraph *root, WORD_INFO *winfo)
00433 {
00434   WordGraph *wg;
00435   int i;
00436   int nodenum, arcnum;
00437 
00438   nodenum = graph_totalwordnum;
00439   arcnum = 0;
00440   for(wg=root;wg;wg=wg->next) {
00441     arcnum += wg->rightwordnum;
00442   }
00443   
00444   module_send(module_sd, "<GRAPHOUT NODENUM=\"%d\" ARCNUM=\"%d\">\n", nodenum, arcnum);
00445 
00446   for(wg=root;wg;wg=wg->next) {
00447     module_send(module_sd, "    <NODE GID=\"%d\"", wg->id);
00448     msock_word_out2(wg->wid, winfo);
00449     module_send(module_sd, " BEGIN=\"%d\"", wg->lefttime);
00450     module_send(module_sd, " END=\"%d\"", wg->righttime);
00451     module_send(module_sd, "/>\n");
00452   }
00453   for(wg=root;wg;wg=wg->next) {
00454     for(i=0;i<wg->rightwordnum;i++) {
00455       module_send(module_sd, "    <ARC FROM=\"%d\" TO=\"%d\"/>\n", wg->id, wg->rightword[i]->id);
00456     }
00457   }
00458   module_send(module_sd, "</GRAPHOUT>\n.\n");
00459 }
00460 
00461 #endif /* GRAPHOUT */
00462   
00463 
00464 /**********************************************************************/
00465 /* when search failed */
00466 
00479 static void
00480 msock_pass2_failed(WORD_INFO *winfo)
00481 {
00482   if (out2_never) return;       /* no output */
00483   module_send(module_sd, "<RECOGFAIL/>\n.\n");
00484 }
00485 
00500 static void
00501 msock_rejected(const char *s)
00502 {
00503   module_send(module_sd, "<REJECTED REASON=\"%s\"/>\n.\n", s);
00504 }
00505 
00506 /**********************************************************************/
00507 /* output recording status changes */
00508 
00519 void
00520 msock_status_recready()
00521 {
00522   module_send(module_sd, "<INPUT STATUS=\"LISTEN\" TIME=\"%ld\"/>\n.\n", time(NULL));
00523 }
00534 void
00535 msock_status_recstart()
00536 {
00537   module_send(module_sd, "<INPUT STATUS=\"STARTREC\" TIME=\"%ld\"/>\n.\n", time(NULL));
00538 }
00549 void
00550 msock_status_recend()
00551 {
00552   module_send(module_sd, "<INPUT STATUS=\"ENDREC\" TIME=\"%ld\"/>\n.\n", time(NULL));
00553 }
00566 void
00567 msock_status_param(HTK_Param *param)
00568 {
00569   module_send(module_sd, "<INPUTPARAM FRAMES=\"%d\" MSEC=\"%d\"/>\n.\n", param->samplenum, param->samplenum * (int)((float)para.smp_period * (float)para.frameshift / 10000.0));
00570 }
00571 
00572 /**********************************************************************/
00573 /* register functions for module output */
00574 
00585 void
00586 setup_result_msock()
00587 {
00588   if (!module_mode) {
00589     j_error("Error: result_msock: not in module mode!\n");
00590   }
00591   status_process_online = msock_status_process_online;
00592   status_process_offline = msock_status_process_offline;
00593   status_recready      = msock_status_recready;
00594   status_recstart      = msock_status_recstart;
00595   status_recend        = msock_status_recend;
00596   status_param         = msock_status_param;
00597   result_pass1_begin   = msock_pass1_begin;
00598   result_pass1_current = msock_pass1_current;
00599   result_pass1_final   = msock_pass1_final;
00600   result_pass1_end     = msock_pass1_end;
00601   result_pass2_begin   = msock_pass2_begin;
00602   result_pass2         = msock_pass2;
00603   result_pass2_end     = msock_pass2_end;
00604   result_pass2_failed  = msock_pass2_failed;
00605   result_rejected      = msock_rejected;
00606   result_gmm           = msock_gmm;
00607 #ifdef GRAPHOUT
00608   result_graph         = msock_graph;
00609 #endif
00610 }

Generated on Tue Dec 26 16:16:33 2006 for Julius by  doxygen 1.5.0