CollocReducer extends Reducer<GramKey, Gram, Gram, Gram> { @Override protected void reduce(GramKey key, Iterable<Gram> values, Context context) throws IOException, InterruptedException { Gram.Type keyType = key.getType(); if (keyType == Gram.Type.UNIGRAM) { processUnigram(values.iterator(), context); } else if (keyType == Gram.Type.HEAD || keyType == Gram.Type.TAIL) { processSubgram(values.iterator(), context); } else { context.getCounter(Skipped.MALFORMED_TYPES).increment(1); } }   static final String MIN_SUPPORT; static final int DEFAULT_MIN_SUPPORT; }
@Test public void testReduce() throws Exception { Gram[][] input = { {new Gram("the", Gram.Type.UNIGRAM), new Gram("the", Gram.Type.UNIGRAM), new Gram("the", Gram.Type.UNIGRAM)}, {new Gram("the", Gram.Type.HEAD), new Gram("the best", Gram.Type.NGRAM), new Gram("the worst", Gram.Type.NGRAM)}, {new Gram("of", Gram.Type.HEAD), new Gram("of times", Gram.Type.NGRAM), new Gram("of times", Gram.Type.NGRAM)}, {new Gram("times", Gram.Type.TAIL), new Gram("of times", Gram.Type.NGRAM), new Gram("of times", Gram.Type.NGRAM)}}; Gram[][] values = {{new Gram("the", 2, Gram.Type.UNIGRAM), new Gram("the", 2, Gram.Type.UNIGRAM)}, {new Gram("the best", 1, Gram.Type.NGRAM), new Gram("the", 2, Gram.Type.HEAD)}, {new Gram("the worst", 1, Gram.Type.NGRAM), new Gram("the", 2, Gram.Type.HEAD)}, {new Gram("of times", 2, Gram.Type.NGRAM), new Gram("of", 2, Gram.Type.HEAD)}, {new Gram("of times", 2, Gram.Type.NGRAM), new Gram("times", 2, Gram.Type.TAIL)}}; for (Gram[] v : values) { context.write(v[0], v[1]); } EasyMock.replay(context); CollocReducer c = new CollocReducer(); GramKey key = new GramKey(); byte[] empty = new byte[0]; for (Gram[] ii : input) { key.set(ii[0], empty); Collection<Gram> vv = Lists.newLinkedList(); vv.addAll(Arrays.asList(ii)); c.reduce(key, vv, context); } EasyMock.verify(context); }