public void initializeDocument(Document doc){
  Map<String,Double> d=new Hashtable<String,Double>();
  double numDocs=wordlex == null ? 0 : wordlex.getNumDocs();
  for (int i=0; i < doc.tags.length; i++) {
    if (wordlex == null) {
      int rindex=random.nextInt(doc.words.length + 1);
      if (rindex < doc.words.length) {
        doc.reason[i]=doc.words[rindex];
      }
 else {
        doc.reason[i]=TagAllocationModel.NOISE;
      }
    }
 else {
      d.clear();
      double sampleWeight=0;
      for (int j=0; j < doc.words.length; j++) {
        Word w=wordlex.getWord(doc.words[j]);
        if (w != null) {
          double idf=numDocs / w.getDocumentFrequency();
          d.put(doc.words[j],idf);
          sampleWeight+=idf;
        }
      }
      d.put(TagAllocationModel.NOISE,sampleWeight / d.size());
      doc.reason[i]=sample(d);
    }
    if (!locked) {
      ntw.inc(doc.tags[i],doc.reason[i],1);
    }
  }
  for (  String word : doc.words) {
    nw.inc(word,doc.tags.length);
  }
}

public void initializeDocument ( Document doc ) { Map < String , Double > d = new Hashtable < String , Double > ( ) ; double numDocs = wordlex == null ? 0 : wordlex . getNumDocs ( ) ; for ( int i = 0 ; i < doc . tags . length ; i ++ ) { if ( wordlex == null ) { int rindex = random . nextInt ( doc . words . length + 1 ) ; if ( rindex < doc . words . length ) { doc . reason [ i ] = doc . words [ rindex ] ; } else { doc . reason [ i ] = TagAllocationModel . NOISE ; } } else { d . clear ( ) ; double sampleWeight = 0 ; for ( int j = 0 ; j < doc . words . length ; j ++ ) { Word w = wordlex . getWord ( doc . words [ j ] ) ; if ( w != null ) { double idf = numDocs / w . getDocumentFrequency ( ) ; d . put ( doc . words [ j ] , idf ) ; sampleWeight += idf ; } } d . put ( TagAllocationModel . NOISE , sampleWeight / d . size ( ) ) ; doc . reason [ i ] = sample ( d ) ; } if ( ! locked ) { ntw . inc ( doc . tags [ i ] , doc . reason [ i ] , 1 ) ; } } for ( String word : doc . words ) { nw . inc ( word , doc . tags . length ) ; } }
training only . initialize the document ' s tag allocation , and add the document ' s allocation to the global count of the model .
