public void add(String[] words,int size, boolean unigrams) {
    List gram = new ArrayList(size);
    //create uni-grams so n-grams can be created.
    if (unigrams) {
      for (int wi=0,wn=words.length;wi<wn;wi++) {
        wordMap.add(words[wi]);
      }
    }
    for (int wi=0,wn=words.length;wi<wn;wi++) {
      //create all n-gram which start with wi
      gram.clear();
      gram.add(words[wi]);
      for (int gi=2;gi<=size;gi++) {
        if (wi+gi-1 < words.length) {
          gram.add(words[wi+gi-1]);
          NGram ngram = nGramFactory.createNGram(gram);
          if (ngram != null) {
            gramSet.add(ngram);
          }
          else {
            throw new NullPointerException();
          }
        }
      }
    }
  }
public void add ( String [ ] words , int size , boolean unigrams ) { List gram = new ArrayList ( size ) ; if ( unigrams ) { for ( int wi = 0 , wn = words . length ; wi < wn ; wi ++ ) { wordMap . add ( words [ wi ] ) ; } } for ( int wi = 0 , wn = words . length ; wi < wn ; wi ++ ) { gram . clear ( ) ; gram . add ( words [ wi ] ) ; for ( int gi = 2 ; gi <= size ; gi ++ ) { if ( wi + gi - 1 < words . length ) { gram . add ( words [ wi + gi - 1 ] ) ; NGram ngram = nGramFactory . createNGram ( gram ) ; if ( ngram != null ) { gramSet . add ( ngram ) ; } else { throw new NullPointerException ( ) ; } } } } }
Adds n-grams for consisting of the specified words of the specified size (and smaller) to this
n-gram dictionary.
@param words The words from which n-grams are derived.
@param size The size of the n-grams to collect.