logger.info("Adding knowledge source " + component + " with URL parameter " + url + "..."); ClientState state = getState(id); Class<? extends AbstractKnowledgeSource> ksClass = (Class<? extends AbstractKnowledgeSource>) cm.getComponentClass(component); if(ksClass == null) throw new UnknownComponentException(component);
/** * Sets the reasoner to use. * * @param id The session ID. * @param component The name of the component. * @return An identifier for the component. * @throws ClientNotKnownException Thrown if client (session ID) is not known. * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). */ @WebMethod public int setReasoner(int id, String component) throws ClientNotKnownException, UnknownComponentException { logger.info("Setting reasoner " + component + "..."); ClientState state = getState(id); Class<? extends AbstractReasonerComponent> rcClass = (Class<? extends AbstractReasonerComponent>) cm.getComponentClass(component); if(rcClass == null) throw new UnknownComponentException(component); AbstractReasonerComponent rc = null; try { rc = rcClass.getConstructor(Set.class).newInstance(state.getKnowledgeSources()); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } logger.info("...done."); return state.setReasonerComponent(rc); }
/** * Sets the learning problem to use. * * @param id The session ID. * @param component The name of the component. * @return An identifier for the component. * @throws ClientNotKnownException Thrown if client (session ID) is not known. * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). */ @WebMethod public int setLearningProblem(int id, String component) throws ClientNotKnownException, UnknownComponentException { logger.info("Setting learning problem " + component + "..."); ClientState state = getState(id); Class<? extends AbstractClassExpressionLearningProblem> lpClass = (Class<? extends AbstractClassExpressionLearningProblem>) cm.getComponentClass(component); if(lpClass == null) throw new UnknownComponentException(component); AbstractClassExpressionLearningProblem lp = null; try { lp = lpClass.getConstructor(AbstractReasonerComponent.class).newInstance(state.getReasonerComponent()); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } logger.info("...done."); return state.setLearningProblem(lp); }
/** * Sets the learning algorithm to use. * * @param id The session ID. * @param component The name of the component. * @return An identifier for the component. * @throws ClientNotKnownException Thrown if client (session ID) is not known. * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). * @throws LearningProblemUnsupportedException Thrown if the learning problem is not supported by the specified learning algorithm. */ @WebMethod public int setLearningAlgorithm(int id, String component) throws ClientNotKnownException, UnknownComponentException { logger.info("Setting learning algorithm " + component + "..."); ClientState state = getState(id); Class<? extends AbstractCELA> laClass = (Class<? extends AbstractCELA>) cm.getComponentClass(component); if(laClass == null) throw new UnknownComponentException(component); AbstractCELA la = null; try { la = laClass.getConstructor(AbstractClassExpressionLearningProblem.class, AbstractReasonerComponent.class) .newInstance(state.getLearningProblem(), state.getReasonerComponent()); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } logger.info("...done."); return state.setLearningAlgorithm(la); }
/** * Gets the configuration options supported by the component. This allows e.g. to * automatically build user interfaces for configuring components. * @param component Name of the component. * @param allInfo Whether or not complete information is desired (including option description, required, default value, example value). * @return A list of configuration options supported by the component. * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). */ @WebMethod public String[] getConfigOptions(String component, boolean allInfo) { Class<? extends Component> componentClass = cm.getComponentClass(component); Set<Field> options = AnnComponentManager.getConfigOptions(componentClass); String[] optionsString = new String[options.size()]; int i = 0; for(Field f : options) { ConfigOption option = f.getAnnotation(ConfigOption.class); optionsString[i] = AnnComponentManager.getName(f); if(allInfo) { optionsString[i] += "#" + option.description(); optionsString[i] += "#" + option.required(); optionsString[i] += "#" + option.defaultValue(); optionsString[i] += "#" + option.exampleValue(); } i++; } return optionsString; }