Beispiel #1
0
int main(){
	initialize_dict();

	//for(int i=0; i<1000; ++i)
		//flash_page_erase(where_write_dict(0) + i*1024);

	for(int i=0; i<1000; ++i) masss[i]=0x6666;
	masss[0]=(0x11111111);
	masss[1]=(0x01111111);
	masss[2]=(0x10111111);
	masss[3]=(0x11011111);
	masss[4]=(0x11101111);
	masss[5]=(0x11111011);
	masss[6]=(0x11111101);
	masss[7]=(0x11111110);
	masss[8]=(0x00111111);
	flash_write_dict(masss, 9);
	for(int i=0; i<105; ++i) flash_write_dict(masss, 9);

	return 0;
}
Beispiel #2
0
/** 
 * <EN>
 * @brief  Load a language model.
 *
 * This function will create an LM process instance using the given LM
 * configuration, and load models specified in the configuration into
 * the instance.  Then the created instance will be installed to the
 * engine instance.  The lmconf should be registered to the 
 * recog->jconf before calling this function.
 *
 * To convert phoneme sequence to triphone at loading, you should
 * specify which AM to use with this LM by the argument am.
 *
 * </EN>
 *
 * <JA>
 * @brief 言語モデルを読み込む.
 *
 * この関数は,与えられた LM 設定に従って LM 処理インスタンスを生成し,
 * その中に言語モデルをロードします.その後,そのLM処理インスタンスは
 * 新たにエンジンインスタンスに登録されます.LM設定はこの関数を
 * 呼ぶ前にあらかじめ全体設定recog->jconfに登録されている必要があります.
 *
 * 辞書の読み込み時にトライフォンへの変換および音響モデルとのリンクが
 * 同時に行われます.このため,この言語モデルが使用する音響モデルの
 * インスタンスを引数 am として指定する必要があります.
 * 
 * </JA>
 * 
 * @param recog [i/o] engine instance
 * @param lmconf [in] LM configuration to load
 * 
 * @return TRUE on success, or FALSE on error.
 * 
 * @callgraph
 * @callergraph
 * @ingroup instance
 * 
 */
boolean
j_load_lm(Recog *recog, JCONF_LM *lmconf)
{
  JCONF_SEARCH *sh;
  PROCESS_LM *lm;
  PROCESS_AM *am, *atmp;

  jlog("STAT: *** loading LM%02d %s\n", lmconf->id, lmconf->name);

  /* find which am process instance to assign to each LM */
  am = NULL;
  for(sh=recog->jconf->search_root;sh;sh=sh->next) {
    if (sh->lmconf == lmconf) {
      for(atmp=recog->amlist;atmp;atmp=atmp->next) {
	if (sh->amconf == atmp->config) {
	  am = atmp;
	}
      }
    }
  }
  if (am == NULL) {
    jlog("ERROR: cannot find corresponding AM for LM%02d %s\n", lmconf->id, lmconf->name);
    jlog("ERROR: you should write all AM/LM combinations to be used for recognition with \"-SR\"\n");
    return FALSE;
  }

  /* create LM process instance */
  lm = j_process_lm_new(recog, lmconf);

  /* assign AM process instance to the LM instance */
  lm->am = am;

  /* load language model */
  if (lm->lmtype == LM_PROB) {
    /* LM (N-gram) */
    if ((lm->winfo = initialize_dict(lm->config, lm->am->hmminfo)) == NULL) {
      jlog("ERROR: m_fusion: failed to initialize dictionary\n");
      return FALSE;
    }
    if (lm->config->ngram_filename_lr_arpa || lm->config->ngram_filename_rl_arpa || lm->config->ngram_filename) {
      if ((lm->ngram = initialize_ngram(lm->config, lm->winfo)) == NULL) {
	jlog("ERROR: m_fusion: failed to initialize N-gram\n");
	return FALSE;
      }
    }
  }
  if (lm->lmtype == LM_DFA) {
    /* DFA */
    if (lm->config->dfa_filename != NULL && lm->config->dictfilename != NULL) {
      /* here add grammar specified by "-dfa" and "-v" to grammar list */
      multigram_add_gramlist(lm->config->dfa_filename, lm->config->dictfilename, lm->config, LM_DFA_GRAMMAR);
    }
    /* load all the specified grammars */
    if (multigram_load_all_gramlist(lm) == FALSE) {
      jlog("ERROR: m_fusion: some error occured in reading grammars\n");
      return FALSE;
    }
    /* setup for later wchmm building */
    multigram_update(lm);
    /* the whole lexicon will be forced to built in the boot sequence,
       so reset the global modification flag here */
    lm->global_modified = FALSE;
  }
  
  jlog("STAT: *** LM%02d %s loaded\n", lmconf->id, lmconf->name);

  return TRUE;
}
Beispiel #3
0
/** 
 * <EN>
 * @brief  Reload dictionaries.
 *
 * This function reload dictionaries from file.
 *
 * This function works only for N-gram LM.
 * It also re-create all the recognition process, even if it is grammar-based.
 *
 * @param recog [i/o] engine instance
 * @param lm [i/o] LM instance to reload
 * 
 * @return TRUE on success, or FALSE on error.
 * 
 */
boolean
j_reload_adddict(Recog *recog, PROCESS_LM *lm)
{
  RecogProcess *p, *ptmp;
  JCONF_SEARCH *sh;
  PROCESS_AM *am, *atmp;
  
  jlog("STAT: *** reloading (additional) dictionary of LM%02d %s\n", lm->config->id, lm->config->name);

  /* free current dictionary */
  if (lm->winfo) word_info_free(lm->winfo);
  if (lm->grammars) multigram_free_all(lm->grammars);
  if (lm->dfa) dfa_info_free(lm->dfa);

  /* free all current process instanfces */
  p = recog->process_list;
  while(p) {
    ptmp = p->next;
    j_recogprocess_free(p);
    p = ptmp;
  }
  recog->process_list = NULL;

  /* reload dictionary */
  if (lm->lmtype == LM_PROB) {

    if ((lm->winfo = initialize_dict(lm->config, lm->am->hmminfo)) == NULL) {
      jlog("ERROR: m_fusion: failed to reload dictionary\n");
      return FALSE;
    }
    if (lm->config->ngram_filename_lr_arpa || lm->config->ngram_filename_rl_arpa || lm->config->ngram_filename) {
      /* re-map dict item to N-gram entry */
      if (make_voca_ref(lm->ngram, lm->winfo) == FALSE) {
	jlog("ERROR: m_fusion: failed to map words in additional dictionary to N-gram\n");
	return FALSE;
      }
#if 0
      /* post-fix EOS / BOS uni prob for SRILM */
      fix_uniprob_srilm(ngram, winfo);
#endif
    }
  }

#if 0
  /* grammar case: not tested */
  if (lm->lmtype == LM_DFA) {
    if (lm->config->dfa_filename != NULL && lm->config->dictfilename != NULL) {
      /* here add grammar specified by "-dfa" and "-v" to grammar list */
      multigram_add_gramlist(lm->config->dfa_filename, lm->config->dictfilename, lm->config, LM_DFA_GRAMMAR);
    }
    /* load all the specified grammars */
    if (multigram_load_all_gramlist(lm) == FALSE) {
      jlog("ERROR: m_fusion: some error occured in reading grammars\n");
      return FALSE;
    }
    /* setup for later wchmm building */
    multigram_update(lm);
    /* the whole lexicon will be forced to built in the boot sequence,
       so reset the global modification flag here */
    lm->global_modified = FALSE;
  }
#endif

  /* re-create all recognition process instance */
  for(sh=recog->jconf->search_root;sh;sh=sh->next) {
    if (j_launch_recognition_instance(recog, sh) == FALSE) {
      jlog("ERROR: m_fusion: failed to re-start recognizer instance \"%s\"\n", sh->name);
      return FALSE;
    }
  }

  /* the created process will be live=FALSE, active = 1, so
     the new recognition instance is dead now but
     will be made live at next session */

  /* tell engine to update */
  recog->process_want_reload = TRUE;

  jlog("STAT: *** LM%02d %s additional dictionary reloaded\n", lm->config->id, lm->config->name);

  return TRUE;
}