コード例 #1
0
  @Test
  public void testSnapshot() throws RecommenderBuildException {
    List<Rating> rs = new ArrayList<Rating>();
    rs.add(Ratings.make(1, 5, 2));
    rs.add(Ratings.make(1, 7, 4));
    rs.add(Ratings.make(8, 4, 5));
    rs.add(Ratings.make(8, 5, 4));

    EventDAO dao = EventCollectionDAO.create(rs);

    LenskitConfiguration config = new LenskitConfiguration();
    config.bind(EventDAO.class).to(dao);
    config.bind(ItemScorer.class).to(UserUserItemScorer.class);
    config.bind(NeighborFinder.class).to(SnapshotNeighborFinder.class);

    LenskitRecommenderEngine engine = LenskitRecommenderEngine.build(config);
    Recommender rec = engine.createRecommender();
    assertThat(rec.getItemScorer(), instanceOf(UserUserItemScorer.class));
    assertThat(rec.getItemRecommender(), instanceOf(TopNItemRecommender.class));
    RatingPredictor pred = rec.getRatingPredictor();
    assertThat(pred, instanceOf(SimpleRatingPredictor.class));

    Recommender rec2 = engine.createRecommender();
    assertThat(rec2.getItemScorer(), not(sameInstance(rec.getItemScorer())));
  }
コード例 #2
0
  @SuppressWarnings("deprecation")
  @Test
  public void testUserUserRecommenderEngineCreate() {
    Recommender rec = engine.createRecommender();

    assertThat(rec.getItemScorer(), instanceOf(UserUserItemScorer.class));
    assertThat(rec.getItemRecommender(), instanceOf(TopNItemRecommender.class));
    RatingPredictor pred = rec.getRatingPredictor();
    assertThat(pred, instanceOf(SimpleRatingPredictor.class));
    assertThat(((SimpleRatingPredictor) pred).getScorer(), sameInstance(rec.getItemScorer()));
  }