*** lm/src/ngram.cc	2012/01/27 21:47:30	1.119
--- lm/src/ngram.cc	2012/03/06 08:12:26
***************
*** 608,616 ****
      if (hiddenVocabFile != 0) {
  	hiddenEvents = new SubVocab(*vocab);
  	assert(hiddenEvents);
! 
! 	File file(hiddenVocabFile, "r");
! 	hiddenEvents->read(file);
      }
  
      SubVocab *classVocab = 0;
--- 608,616 ----
      if (hiddenVocabFile != 0) {
  	hiddenEvents = new SubVocab(*vocab);
  	assert(hiddenEvents);
! 	/*
! 	 * Defer reading the hidden vocab file until LM is created.
! 	 */
      }
  
      SubVocab *classVocab = 0;
***************
*** 646,651 ****
--- 646,659 ----
  		        new Ngram(*vocab, order);
      assert(ngramLM != 0);
  
+     /* 
+      * Read hidden vocab words and their properties
+      */
+     if (hiddenVocabFile != 0) {
+ 	File file(hiddenVocabFile, "r");
+ 	((HiddenNgram *)ngramLM)->readHiddenVocab(file);
+     }
+ 
      if (skipOOVs) {
  	ngramLM->skipOOVs() = true;
      }
*** lm/src/HiddenNgram.cc	2012/01/20 05:58:39	1.22
--- lm/src/HiddenNgram.cc	2012/03/06 19:04:25
***************
*** 223,232 ****
       */
      if (!Ngram::read(file, limitVocab)) {
  	return false;
!     } else {
  	/*
  	 * Read vocab property specs from the LM file
  	 */
  	char *line;
  
  	while ((line = file.getline())) {
--- 223,243 ----
       */
      if (!Ngram::read(file, limitVocab)) {
  	return false;
!     } 
! 
      /*
       * Read vocab property specs from the LM file
       */
+     if (!readHiddenVocab(file)) {
+ 	return false;
+     }
+ 
+     return true;
+ }
+ 
+ Boolean
+ HiddenNgram::readHiddenVocab(File &file)
+ {
      char *line;
  
      while ((line = file.getline())) {
***************
*** 245,251 ****
  	    /*
  	     * First word on line defines the vocabulary item
  	     */
! 	    VocabIndex word = vocab.addWord(argv[0]);
  
  	    static unsigned deleteWords;
  	    static unsigned repeatWords;
--- 256,262 ----
  	/*
  	 * First word on line defines the vocabulary item
  	 */
! 	VocabIndex word = hiddenVocab.addWord(argv[0]);
  
  	static unsigned deleteWords;
  	static unsigned repeatWords;
***************
*** 297,303 ****
  	}
  
  	return true;
-     }
  }
  
  Boolean
--- 308,313 ----
***************
*** 309,314 ****
--- 319,334 ----
  
      fprintf(file, "\n");
  
+     if (!writeHiddenVocab(file)) {
+ 	return false;
+     }
+ 
+     return true;
+ }
+ 
+ Boolean
+ HiddenNgram::writeHiddenVocab(File &file)
+ {
      LHashIter<VocabIndex, HiddenVocabProps> iter(vocabProps);
  
      HiddenVocabProps *props;
***************
*** 321,327 ****
  	    fprintf(file, " -%s %u", PROP_DELETE, props->deleteWords);
  	}
  	if (props->repeatWords) {
! 	    fprintf(file, " -%s %u", PROP_DELETE, props->repeatWords);
  	}
  	if (props->insertWord != Vocab_None) {
  	    fprintf(file, " -%s %s", PROP_INSERT,
--- 341,347 ----
  	    fprintf(file, " -%s %u", PROP_DELETE, props->deleteWords);
  	}
  	if (props->repeatWords) {
! 	    fprintf(file, " -%s %u", PROP_REPEAT, props->repeatWords);
  	}
  	if (props->insertWord != Vocab_None) {
  	    fprintf(file, " -%s %s", PROP_INSERT,
***************
*** 869,875 ****
  	stats.numWords += len;
      }
  
!     if (debug(DEBUG_PRINT_VITERBI)) {
  	len = trellis.where();
  	makeArray(HiddenNgramState, bestStates, len);
  
--- 889,895 ----
  	stats.numWords += len;
      }
  
!     if (!notHidden && debug(DEBUG_PRINT_VITERBI)) {
  	len = trellis.where();
  	makeArray(HiddenNgramState, bestStates, len);
  
*** lm/src/HiddenNgram.h	2007/01/24 19:47:10	1.1
--- lm/src/HiddenNgram.h	2012/03/06 07:39:10
***************
*** 72,77 ****
--- 72,80 ----
      Boolean read(File &file, Boolean limitVocab = false);
      Boolean write(File &file);
  
+     Boolean readHiddenVocab(File &file);
+     Boolean writeHiddenVocab(File &file);
+ 
      const HiddenVocabProps &getProps(VocabIndex word);
  
  protected:
