@Test public void testToUsersReducerMinPreferencesUserIgnored() throws Exception { Reducer<VarLongWritable,VarLongWritable,VarLongWritable,VectorWritable>.Context context = EasyMock.createMock(Reducer.Context.class); ToUserVectorsReducer reducer = new ToUserVectorsReducer(); setField(reducer, "minPreferences", 2); EasyMock.replay(context); reducer.reduce(new VarLongWritable(123), Collections.singletonList(new VarLongWritable(456)), context); EasyMock.verify(context); }
@Override protected void reduce(VarLongWritable userID, Iterable<VarLongWritable> itemPrefs, Context context) throws IOException, InterruptedException { Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); for (VarLongWritable itemPref : itemPrefs) { int index = TasteHadoopUtils.idToIndex(itemPref.get()); float value = itemPref instanceof EntityPrefWritable ? ((EntityPrefWritable) itemPref).getPrefValue() : 1.0f; userVector.set(index, value); } if (userVector.getNumNondefaultElements() >= minPreferences) { userVectorWritable.set(userVector); userVectorWritable.setWritesLaxPrecision(true); context.getCounter(Counters.USERS).increment(1); context.write(userID, userVectorWritable); } }
ToUserVectorsReducer extends
    Reducer<VarLongWritable,VarLongWritable,VarLongWritable,VectorWritable> { @Override protected void reduce(VarLongWritable userID, Iterable<VarLongWritable> itemPrefs, Context context) throws IOException, InterruptedException { Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); for (VarLongWritable itemPref : itemPrefs) { int index = TasteHadoopUtils.idToIndex(itemPref.get()); float value = itemPref instanceof EntityPrefWritable ? ((EntityPrefWritable) itemPref).getPrefValue() : 1.0f; userVector.set(index, value); } if (userVector.getNumNondefaultElements() >= minPreferences) { userVectorWritable.set(userVector); userVectorWritable.setWritesLaxPrecision(true); context.getCounter(Counters.USERS).increment(1); context.write(userID, userVectorWritable); } } }
ToUserVectorsReducer extends
    Reducer<VarLongWritable,VarLongWritable,VarLongWritable,VectorWritable> { @Override protected void reduce(VarLongWritable userID, Iterable<VarLongWritable> itemPrefs, Context context) throws IOException, InterruptedException { Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); for (VarLongWritable itemPref : itemPrefs) { int index = TasteHadoopUtils.idToIndex(itemPref.get()); float value = itemPref instanceof EntityPrefWritable ? ((EntityPrefWritable) itemPref).getPrefValue() : 1.0f; userVector.set(index, value); } if (userVector.getNumNondefaultElements() >= minPreferences) { userVectorWritable.set(userVector); userVectorWritable.setWritesLaxPrecision(true); context.getCounter(Counters.USERS).increment(1); context.write(userID, userVectorWritable); } }  }
ToUserVectorsReducer extends
    Reducer<VarLongWritable,VarLongWritable,VarLongWritable,VectorWritable> { @Override protected void reduce(VarLongWritable userID, Iterable<VarLongWritable> itemPrefs, Context context) throws IOException, InterruptedException { Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); for (VarLongWritable itemPref : itemPrefs) { int index = TasteHadoopUtils.idToIndex(itemPref.get()); float value = itemPref instanceof EntityPrefWritable ? ((EntityPrefWritable) itemPref).getPrefValue() : 1.0f; userVector.set(index, value); } if (userVector.getNumNondefaultElements() >= minPreferences) { userVectorWritable.set(userVector); userVectorWritable.setWritesLaxPrecision(true); context.getCounter(Counters.USERS).increment(1); context.write(userID, userVectorWritable); } }   }
ToUserVectorsReducer extends
    Reducer<VarLongWritable,VarLongWritable,VarLongWritable,VectorWritable> { @Override protected void reduce(VarLongWritable userID, Iterable<VarLongWritable> itemPrefs, Context context) throws IOException, InterruptedException { Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); for (VarLongWritable itemPref : itemPrefs) { int index = TasteHadoopUtils.idToIndex(itemPref.get()); float value = itemPref instanceof EntityPrefWritable ? ((EntityPrefWritable) itemPref).getPrefValue() : 1.0f; userVector.set(index, value); } if (userVector.getNumNondefaultElements() >= minPreferences) { userVectorWritable.set(userVector); userVectorWritable.setWritesLaxPrecision(true); context.getCounter(Counters.USERS).increment(1); context.write(userID, userVectorWritable); } }   static final String MIN_PREFERENCES_PER_USER; }