/** * Factory method for creating a reasoner component from a set of knowledge sources. * * @see #reasoner(Class, AbstractKnowledgeSource) * @param <T> The type of this method is a subclass of reasoner component. * @param reasoner A class object, where the class is subclass of ReasonerComponent. * @param sources A set of knowledge sources. * @return A reasoner component. */ public <T extends AbstractReasonerComponent> T reasoner( Class<T> reasoner, Set<AbstractKnowledgeSource> sources) { if (!reasonerComponents.contains(reasoner)) { System.err.println( "Warning: reasoner component " + reasoner + " is not a registered reasoner component."); } T rc = invokeConstructor(reasoner, new Class[] {Set.class}, new Object[] {sources}); pool.registerComponent(rc); return rc; }
/** * Factory method for creating a knowledge source. * * @param <T> The type of this method is a subclass of knowledge source. * @param source A registered knowledge source component. * @return An instance of the given knowledge source class. */ public <T extends AbstractKnowledgeSource> T knowledgeSource(Class<T> source) { if (!knowledgeSources.contains(source)) { logger.warn( "Warning: knowledge source " + source + " is not a registered knowledge source component."); } T ks = invokeConstructor(source, new Class[] {}, new Object[] {}); pool.registerComponent(ks); return ks; }
/** * Factory method for creating a learning problem component. * * @param <T> The type of this method is a subclass of learning problem. * @param lpClass A class object, where the class is a subclass of learning problem. * @param reasoner A reasoning service object. * @return A learning problem component. */ public <T extends AbstractLearningProblem> T learningProblem( Class<T> lpClass, AbstractReasonerComponent reasoner) { if (!learningProblems.contains(lpClass)) { System.err.println( "Warning: learning problem " + lpClass + " is not a registered learning problem component."); } T lp = invokeConstructor( lpClass, new Class[] {AbstractReasonerComponent.class}, new Object[] {reasoner}); pool.registerComponent(lp); return lp; }
/** * Factory method for creating a learning algorithm, which automagically calls the right * constructor for the given problem. * * @param <T> The type of this method is a subclass of learning algorithm. * @param laClass A class object, where the class is subclass of learning algorithm. * @param lp A learning problem, which the algorithm should try to solve. * @param rs A reasoning service for querying the background knowledge of this learning problem. * @return A learning algorithm component. * @throws LearningProblemUnsupportedException Thrown when the learning problem and the learning * algorithm are not compatible. */ public <T extends AbstractCELA> T learningAlgorithm( Class<T> laClass, AbstractLearningProblem lp, AbstractReasonerComponent rs) throws LearningProblemUnsupportedException { if (!learningAlgorithms.contains(laClass)) { System.err.println( "Warning: learning algorithm " + laClass + " is not a registered learning algorithm component."); } // find the right constructor: use the one that is registered and // has the class of the learning problem as a subclass Class<? extends AbstractLearningProblem> constructorArgument = null; for (Class<? extends AbstractLearningProblem> problemClass : algorithmProblemsMapping.get(laClass)) { if (problemClass.isAssignableFrom(lp.getClass())) { constructorArgument = problemClass; } } if (constructorArgument == null) { throw new LearningProblemUnsupportedException( lp.getClass(), laClass, algorithmProblemsMapping.get(laClass)); // System.err.println("Warning: No suitable constructor registered for algorithm " // + laClass.toStringID() + " and problem " + lp.getClass().toStringID() // + ". Registered constructors for " + laClass.toStringID() + ": " // + algorithmProblemsMapping.get(laClass) + "."); // return null; } T la = invokeConstructor( laClass, new Class[] {constructorArgument, AbstractReasonerComponent.class}, new Object[] {lp, rs}); pool.registerComponent(la); return la; }