public BigramCollocation [ ] find ( Corpus corpus , int k ) { BigramCollocation [ ] bigrams = new BigramCollocation [ k ] ; HeapSelect < BigramCollocation > heap = new HeapSelect <> ( bigrams ) ; Iterator < Bigram > iterator = corpus . getBigrams ( ) ; while ( iterator . hasNext ( ) ) { Bigram bigram = iterator . next ( ) ; int c12 = corpus . getBigramFrequency ( bigram ) ; if ( c12 > minFreq ) { int c1 = corpus . getTermFrequency ( bigram . w1 ) ; int c2 = corpus . getTermFrequency ( bigram . w2 ) ; double score = likelihoodRatio ( c1 , c2 , c12 , corpus . size ( ) ) ; heap . add ( new BigramCollocation ( bigram . w1 , bigram . w2 , c12 , - score ) ) ; } } heap . sort ( ) ; BigramCollocation [ ] collocations = new BigramCollocation [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { BigramCollocation bigram = bigrams [ k - i - 1 ] ; collocations [ i ] = new BigramCollocation ( bigram . w1 ( ) , bigram . w2 ( ) , bigram . frequency ( ) , - bigram . score ( ) ) ; } return collocations ; }
Finds top k bigram collocations in the given corpus .