/** * tests {@link ToItemPrefsMapper} using boolean data */ @Test public void testToItemPrefsMapperBooleanData() throws Exception { Mapper<LongWritable,Text, VarLongWritable,VarLongWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(new VarLongWritable(12L), new VarLongWritable(34L)); context.write(new VarLongWritable(56L), new VarLongWritable(78L)); EasyMock.replay(context); ToItemPrefsMapper mapper = new ToItemPrefsMapper(); setField(mapper, "booleanData", true); mapper.map(new LongWritable(123L), new Text("12,34"), context); mapper.map(new LongWritable(456L), new Text("56,78"), context); EasyMock.verify(context); }
/** * tests {@link UserVectorSplitterMapper} */ @Test public void testUserVectorSplitterMapper() throws Exception { Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f)); context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 10); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); EasyMock.verify(context); }
/** * tests {@link UserVectorSplitterMapper} in the special case that the number of preferences to be considered * is less than the number of available preferences */ @Test public void testUserVectorSplitterMapperOnlySomePrefsConsidered() throws Exception { Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatchesNaN(123L)); context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 1); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); EasyMock.verify(context); }
/** * tests {@link UserVectorSplitterMapper} in the special case that some userIDs shall be excluded */ @Test public void testUserVectorSplitterMapperUserExclusion() throws Exception { Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f)); context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); FastIDSet usersToRecommendFor = new FastIDSet(); usersToRecommendFor.add(123L); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 10); setField(mapper, "usersToRecommendFor", usersToRecommendFor); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); mapper.map(new VarLongWritable(456L), new VectorWritable(vector), context); EasyMock.verify(context); }
/** * tests {@link AggregateAndRecommendReducer} with a limit on the recommendations per user */ @Test public void testAggregateAndRecommendReducerLimitNumberOfRecommendations() throws Exception { Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new MutableRecommendedItem(1L, 2.8f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); similarityColumnOne.set(2, 0.5); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 1); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }
/** * tests {@link AggregateAndRecommendReducer} */ @Test public void testAggregateAndRecommendReducerExcludeRecommendationsBasedOnOneItem() throws Exception { Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new MutableRecommendedItem(1L, 2.8f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 3); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }
/** * tests {@link AggregateAndRecommendReducer} */ @Test public void testAggregateAndRecommendReducer() throws Exception { Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new MutableRecommendedItem(1L, 2.8f), new MutableRecommendedItem(2L, 2.0f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); similarityColumnOne.set(2, 0.5); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 3); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }