public Object2IntMap<NGram>[] nextNGramPair(int N) throws IOException {
final int[][] pair = nextPair();
if (pair == null) {
return null;
} else {
final NGramCarousel carousel = new NGramCarousel(N);
final Object2IntRBTreeMap<NGram>[] ngramPair = new Object2IntRBTreeMap[]{
new Object2IntRBTreeMap(),
new Object2IntRBTreeMap()
};
for (int l = 0; l < 2; l++) {
for (int i = 0; i < pair[l].length; i++) {
carousel.offer(pair[l][i]);
for (int n = 1; n <= carousel.maxNGram(); n++) {
final NGram ng = carousel.ngram(n);
if (ngramPair[l].containsKey(ng)) {
ngramPair[l].put(ng, ngramPair[l].getInt(ng) + 1);
} else {
ngramPair[l].put(ng, 1);
}
}
}
}
return ngramPair;
}
}