@Override public Double get(long key) { if (vector.containsKey(key)) { return vector.get(key); } else { return defaultReturnValue(); } }
/** * Check that we score items but do not provide scores for items the user has previously rated. * User 5 has rated only item 8 previously. */ @Test public void testItemScorerNoRating() { long[] items = {7, 8}; ItemItemScorer scorer = session.get(ItemItemScorer.class); assertThat(scorer, notNullValue()); SparseVector scores = scorer.score(5, LongArrayList.wrap(items)); assertThat(scores, notNullValue()); assertThat(scores.size(), equalTo(1)); assertThat(scores.get(7), not(notANumber())); assertThat(scores.containsKey(8), equalTo(false)); }
/** * Check that we score items but do not provide scores for items the user has previously rated. * User 5 has rated only item 8 previously. */ @Test public void testItemScorerChannels() { long[] items = {7, 8}; ItemItemScorer scorer = session.get(ItemItemScorer.class); assertThat(scorer, notNullValue()); SparseVector scores = scorer.score(5, LongArrayList.wrap(items)); assertThat(scores, notNullValue()); assertThat(scores.size(), equalTo(1)); assertThat(scores.get(7), not(notANumber())); assertThat( scores.getChannelVector(ItemItemScorer.NEIGHBORHOOD_SIZE_SYMBOL).get(7), closeTo(1.0, 1.0e-5)); assertThat(scores.containsKey(8), equalTo(false)); long[] items2 = {7, 8, 9}; scorer = session.get(ItemItemScorer.class); assertThat(scorer, notNullValue()); scores = scorer.score(2, LongArrayList.wrap(items2)); assertThat( scores.getChannelVector(ItemItemScorer.NEIGHBORHOOD_SIZE_SYMBOL).get(9), closeTo(3.0, 1.0e-5)); // 1, 7, 8 }
@Override public boolean containsKey(long key) { return vector.containsKey(key); }