/** * Create a LensKit recommender. * @param dao The data access object * @return The constructed recommender. */ public LenskitRecommender createRecommender(@WillNotClose DataAccessObject dao) throws RecommenderBuildException { LenskitConfiguration config = new LenskitConfiguration(); config.addComponent(dao); return createRecommender(config); }
/** * Build a recommender graph for this engine builder's configuration. * * Clients generally do not need to use this; it is exposed for the evaluator. * * @param dao The DAO, if available. * @return The graph. */ protected DAGNode<Component, Dependency> buildRecommenderGraph(DataAccessObject dao) { logger.debug("building graph from {} configurations", configurations.size()); RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.setClassLoader(classLoader); for (Pair<LenskitConfiguration, ModelDisposition> cfg : configurations) { rgb.addConfiguration(cfg.getLeft()); } LenskitConfiguration daoConfig; if (dao != null) { daoConfig = new LenskitConfiguration(); daoConfig.addComponent(dao); rgb.addConfiguration(daoConfig); } DAGNode<Component, Dependency> graph; try { graph = rgb.buildGraph(); } catch (ResolutionException e) { throw new RecommenderBuildException("Cannot resolve recommender graph", e); } return graph; }
cfg.addComponent(dao); rewriteBuilder.addBindings(cfg.getBindings()); rewrite = true;
@Test public void testInject() throws RecommenderBuildException { LenskitConfiguration config = new LenskitConfiguration(); config.addComponent(EntityCollectionDAO.create()); config.bind(ItemScorer.class).to(ConstantItemScorer.class); config.set(ConstantItemScorer.Value.class).to(Math.PI); try (LenskitRecommender rec = LenskitRecommenderEngine.build(config).createRecommender()) { ItemScorer scorer = rec.getItemScorer(); assertThat(scorer, notNullValue()); assertThat(scorer, instanceOf(ConstantItemScorer.class)); Map<Long, Double> v = scorer.score(42, LongUtils.packedSet(1, 2, 3, 5, 7)); assertThat(v.keySet(), hasSize(5)); assertThat(v.keySet(), containsInAnyOrder(1L, 2L, 3L, 5L, 7L)); assertThat(v.values(), everyItem(equalTo(Math.PI))); } } }
/** * Create a LensKit recommender. * @param dao The data access object * @return The constructed recommender. */ public LenskitRecommender createRecommender(@WillNotClose DataAccessObject dao) throws RecommenderBuildException { LenskitConfiguration config = new LenskitConfiguration(); config.addComponent(dao); return createRecommender(config); }
/** * Build a recommender graph for this engine builder's configuration. * * Clients generally do not need to use this; it is exposed for the evaluator. * * @param dao The DAO, if available. * @return The graph. */ protected DAGNode<Component, Dependency> buildRecommenderGraph(DataAccessObject dao) { logger.debug("building graph from {} configurations", configurations.size()); RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.setClassLoader(classLoader); for (Pair<LenskitConfiguration, ModelDisposition> cfg : configurations) { rgb.addConfiguration(cfg.getLeft()); } LenskitConfiguration daoConfig; if (dao != null) { daoConfig = new LenskitConfiguration(); daoConfig.addComponent(dao); rgb.addConfiguration(daoConfig); } DAGNode<Component, Dependency> graph; try { graph = rgb.buildGraph(); } catch (ResolutionException e) { throw new RecommenderBuildException("Cannot resolve recommender graph", e); } return graph; }
cfg.addComponent(dao); rewriteBuilder.addBindings(cfg.getBindings()); rewrite = true;