/** * Build a configured recommender graph from the specified configurations. * @return The configuration graph. * @throws IOException if there is an error loading the configurations * @throws RecommenderConfigurationException if there is an error building the configurations */ private DAGNode<Component,Dependency> makeNewGraph(Context ctx) throws IOException, RecommenderConfigurationException { RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addConfiguration(makeDataConfig(ctx)); for (LenskitConfiguration config: ctx.environment.loadConfigurations(ctx.getConfigFiles())) { rgb.addConfiguration(config); } try { return rgb.buildGraph(); } catch (ResolutionException e) { throw new RecommenderConfigurationException("Cannot configure recommender", e); } }
/** * Get a mockup of the full recommender graph. This fully resolves the graph so that * it can be analyzed, but does not create any objects. * * @return The full graph. * @deprecated This shouldn't be used anymore. */ @Deprecated public DAGNode<Component,Dependency> buildGraph() throws RecommenderConfigurationException { RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addBindings(bindings); rgb.addRoots(roots); try { return rgb.buildGraph(); } catch (ResolutionException e) { throw new RecommenderConfigurationException("Cannot resolve configuration graph", e); } } }
private DAGNode<Component, Dependency> createRecommenderGraph(LenskitConfiguration config) throws RecommenderConfigurationException { Preconditions.checkNotNull(config, "extra configuration"); final DAGNode<Component, Dependency> toBuild; RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addBindings(config.getBindings()); DependencySolver solver = rgb.buildDependencySolver(); try { toBuild = solver.rewrite(graph); } catch (ResolutionException ex) { throw new RecommenderConfigurationException("error reconfiguring recommender", ex); } GraphtUtils.checkForPlaceholders(toBuild, logger); return toBuild; }
/** * Add a recommender configuration. * @param config The configuration. * @return The graph builder (for chaining). */ public RecommenderGraphBuilder addConfiguration(LenskitConfiguration config) { addBindings(config.getBindings()); addRoots(config.getRoots()); return this; }
/** * 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; }
RecommenderGraphBuilder rewriteBuilder = new RecommenderGraphBuilder(); boolean rewrite = false; for (Pair<LenskitConfiguration,ModelDisposition> cfg: configurations) { switch (cfg.getRight()) { case EXCLUDED: rewriteBuilder.addBindings(cfg.getLeft().getBindings()); rewriteBuilder.addRoots(cfg.getLeft().getRoots()); rewrite = true; break; LenskitConfiguration cfg = new LenskitConfiguration(); cfg.addComponent(dao); rewriteBuilder.addBindings(cfg.getBindings()); rewrite = true; DependencySolver rewriter = rewriteBuilder.buildDependencyUnsolver(); try { graph = rewriter.rewrite(graph);
/** * Build a dependency 'unsolver' from the provided bindings. The resulting solver, when rewriting * a graph, will replace bound targets with placeholders. * @return The dependency solver. */ public DependencySolver buildDependencyUnsolver() { return buildDependencySolverImpl(SolveDirection.UNSOLVE); }
public DAGNode<Component,Dependency> buildGraph() throws ResolutionException { DependencySolver solver = buildDependencySolver(); for (Class<?> root: roots) { solver.resolve(Desires.create(null, root, true)); } return solver.getGraph(); }
/** * 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; }
RecommenderGraphBuilder rewriteBuilder = new RecommenderGraphBuilder(); boolean rewrite = false; for (Pair<LenskitConfiguration,ModelDisposition> cfg: configurations) { switch (cfg.getRight()) { case EXCLUDED: rewriteBuilder.addBindings(cfg.getLeft().getBindings()); rewriteBuilder.addRoots(cfg.getLeft().getRoots()); rewrite = true; break; LenskitConfiguration cfg = new LenskitConfiguration(); cfg.addComponent(dao); rewriteBuilder.addBindings(cfg.getBindings()); rewrite = true; DependencySolver rewriter = rewriteBuilder.buildDependencyUnsolver(); try { graph = rewriter.rewrite(graph);
/** * Add a recommender configuration. * @param config The configuration. * @return The graph builder (for chaining). */ public RecommenderGraphBuilder addConfiguration(LenskitConfiguration config) { addBindings(config.getBindings()); addRoots(config.getRoots()); return this; }
/** * Build a dependency solver from the provided bindings. * * @return The dependency solver. */ public DependencySolver buildDependencySolver() { return buildDependencySolverImpl(SolveDirection.SOLVE); }
public DAGNode<Component,Dependency> buildGraph() throws ResolutionException { DependencySolver solver = buildDependencySolver(); for (Class<?> root: roots) { solver.resolve(Desires.create(null, root, true)); } return solver.getGraph(); }
/** * Test that we can bind a file parameter to a string and have it work. * * @throws InjectionException if there is an (unexpected) injection failure. */ @Test @Ignore("this test is no longer effective") @SuppressWarnings("unchecked") public void testSetFile() throws InjectionException { LenskitConfiguration config = new LenskitConfiguration(); config.clearRoots(); // config.bind(EventFormat.class).to(Formats.ml100kFormat()); RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addConfiguration(config); try (Injector inj = new StaticInjector(rgb.buildGraph())) { // File f = inj.getInstance(AnnotationBuilder.of(EventFile.class).build(), File.class); // assertThat(f.getName(), equalTo("ratings.foodat")); } } }
/** * Get a mockup of the full recommender graph. This fully resolves the graph so that * it can be analyzed, but does not create any objects. * * @return The full graph. * @deprecated This shouldn't be used anymore. */ @Deprecated public DAGNode<Component,Dependency> buildGraph() throws RecommenderConfigurationException { RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addBindings(bindings); rgb.addRoots(roots); try { return rgb.buildGraph(); } catch (ResolutionException e) { throw new RecommenderConfigurationException("Cannot resolve configuration graph", e); } } }
RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); for (LenskitConfiguration config : configurations) { rgb.addBindings(config.getBindings()); DependencySolver solver = rgb.buildDependencySolver(); try { graph = solver.rewrite(graph);
/** * Build a dependency solver from the provided bindings. * * @return The dependency solver. */ public DependencySolver buildDependencySolver() { return buildDependencySolverImpl(SolveDirection.SOLVE); }
/** * Build a recommender graph (but don't instantiate any objects). * * @param defaults Additional configuration. This configuration comes <em>before</em> the * algorithm's configuration, so it is overridden if appropriate. It is used * for providing things such as DAOs. * @return The recommender graph. * @throws RecommenderConfigurationException if there is an error configuring the recommender. */ public DAGNode<Component,Dependency> buildRecommenderGraph(@Nullable LenskitConfiguration defaults) throws RecommenderConfigurationException { RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); if (defaults != null) { rgb.addConfiguration(defaults); } for (LenskitConfiguration cfg: configurations) { rgb.addConfiguration(cfg); } try { return rgb.buildGraph(); } catch (ResolutionException e) { throw new RecommenderConfigurationException("error configuring recommender", e); } }
private DAGNode<Component, Dependency> createRecommenderGraph(LenskitConfiguration config) throws RecommenderConfigurationException { Preconditions.checkNotNull(config, "extra configuration"); final DAGNode<Component, Dependency> toBuild; RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addBindings(config.getBindings()); DependencySolver solver = rgb.buildDependencySolver(); try { toBuild = solver.rewrite(graph); } catch (ResolutionException ex) { throw new RecommenderConfigurationException("error reconfiguring recommender", ex); } GraphtUtils.checkForPlaceholders(toBuild, logger); return toBuild; }
/** * Build a dependency 'unsolver' from the provided bindings. The resulting solver, when rewriting * a graph, will replace bound targets with placeholders. * @return The dependency solver. */ public DependencySolver buildDependencyUnsolver() { return buildDependencySolverImpl(SolveDirection.UNSOLVE); }