/** * Construct a new rating builder that is a copy of a particular rating. * @param r The rating to copy. * @return A rating builder that will initially build a copy of the specified rating. */ public static RatingBuilder copy(Rating r) { return r.copyBuilder(); }
/** * Construct a new rating builder that is a copy of a particular rating. * @param r The rating to copy. * @return A rating builder that will initially build a copy of the specified rating. */ public static RatingBuilder copy(Rating r) { return r.copyBuilder(); }
@Before public void initialize() throws IOException { predictOutputFile = folder.newFile("predictions.csv"); List<Rating> ratings = new ArrayList<>(); Generator<Rating> rgen = LenskitGenerators.ratings(); Set<Pair<Long,Long>> used = new HashSet<>(); while (ratings.size() < RATING_COUNT) { Rating r = rgen.next(); long uid = r.getUserId() % 5; Pair<Long,Long> ui = ImmutablePair.of(uid, r.getItemId()); if (used.contains(ui)) { continue; } used.add(ui); Rating r2 = r.copyBuilder() .setUserId(r.getUserId() % 5) .build(); ratings.add(r2); } assumeThat(ratings, hasSize(RATING_COUNT)); dao = StaticDataSource.fromList(ratings).get(); LenskitConfiguration config = new LenskitConfiguration(); config.bind(ItemScorer.class).to(UserMeanItemScorer.class); config.bind(UserMeanBaseline.class, ItemScorer.class).to(ItemMeanRatingItemScorer.class); tempEval.setRebuildPeriod(1L); tempEval.setDataSource(dao); tempEval.setAlgorithm("UserMeanBaseline", config); tempEval.setOutputFile(predictOutputFile); }