/** * Returns the name of a DL-Learner component. * @param component the component * @return Name of the component. */ public static String getName(Component component){ return getName(component.getClass()); }
/** * Returns all config options for the given component. * @param component * @return */ public static Map<Field,Class<?>> getConfigOptionTypes(Class<?> component, boolean useSuperTypes){ Map<Field,Class<?>> optionTypes = new TreeMap<>((o1, o2) -> { return AnnComponentManager.getName(o1).compareTo(AnnComponentManager.getName(o2)); }); Field[] fields = component.getDeclaredFields(); if(useSuperTypes) { if(useSuperTypes) { fields = ObjectArrays.concat(fields, component.getSuperclass().getDeclaredFields(), Field.class); } } for(Field f : fields){ if(f.isAnnotationPresent(ConfigOption.class)) { optionTypes.put(f, f.getType()); } } return optionTypes; }
/** * Configures the given component by setting the value for the appropriate config option. * @param component the component to be configured * @param configName the name of the config option * @param configValue the value of the config option */ @Deprecated public static <T> void configure(Component component, String configName, T configValue){ List<Field> fields = getAllFields(component); for(Field f : fields){ if(f.isAnnotationPresent(ConfigOption.class)){ if(AnnComponentManager.getName(f).equals(configName)){ try { PropertyEditor editor = PropertyEditor.class.newInstance(); editor.setAsText(configValue.toString()); Method method = component.getClass().getMethod("set" + Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1), getClassForObject(editor.getValue())); method.invoke(component, editor.getValue()); } catch (IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException | IllegalAccessException | InstantiationException e) { e.printStackTrace(); } } } } }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof Component) { Component c = (Component) bean; String componentName = AnnComponentManager.getName(c); try { logger.info("Initializing component '{}' of type {} ...", beanName, componentName); long startTime = System.currentTimeMillis(); c.init(); long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; logger.info("... initialized component '{}' in {}. Status: OK", new String[]{beanName, Helper.prettyPrintMilliSeconds(elapsedTime)}); } catch (ComponentInitException e) { throw new RuntimeException("Problem initializing the component \"" + componentName + "\" with beanName: " + beanName, e); } catch (Exception e) { /** Catch any exception as an init exception */ logger.warn("Could not initialize component \"" + componentName + "\""); throw new RuntimeException(e); } } return bean; }
private void optionsTable(StringBuffer sb, Class<?> comp) { // generate table for configuration options Map<Field,Class<?>> options = ConfigHelper.getConfigOptionTypes(comp); if(options.isEmpty()) { sb.append("This component does not have configuration options."); } else { sb.append("<div class=\"table-responsive\"><table class=\"hor-minimalist-a table table-hover\"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody>\n"); for(Entry<Field,Class<?>> entry : options.entrySet()) { String optionName = AnnComponentManager.getName(entry.getKey()); ConfigOption option = entry.getKey().getAnnotation(ConfigOption.class); String type = entry.getValue().getSimpleName(); if(entry.getValue().equals(OWLClass.class)) { type = "IRI"; } sb.append("<tr><td>" + optionName + "</td><td>" + option.description() + (option.exampleValue().length() > 0 ? (" <strong>Example:</strong> " + option.exampleValue()) : "") + "</td><td> " + type + "</td><td>" + option.defaultValue() + "</td><td> " + option.required() + "</td></tr>\n"); } sb.append("</tbody></table></div>\n"); } }
String optionName = AnnComponentManager.getName(entry.getKey()); ConfigOption option = entry.getKey().getAnnotation(ConfigOption.class); String type = entry.getValue().getSimpleName();
Class<? extends Component> component = Class.forName(componentClassName).asSubclass(Component.class); components.add(component); componentNames.put(component, getName(component)); componentNamesShort.put(component, getShortName(component)); } catch (ClassNotFoundException e) {
header = "component: " + AnnComponentManager.getName(ccomp) + " (" + klass + ") v" + AnnComponentManager.getVersion(ccomp); description = AnnComponentManager.getDescription(ccomp); catString = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, category.getSimpleName());
hasDoc.add(AnnComponentManager.getName(f.getValue().get(0))); } else if (notConfig) { notConfigSet.add(f.getKey());
String algName = AnnComponentManager.getName(learner); System.out.print("Applying " + algName + " on " + entity + " ... "); long startTime = System.currentTimeMillis();
((AbstractAxiomLearningAlgorithm)learner).setReasoner(reasoner); String algName = AnnComponentManager.getName(learner); System.out.print("Applying " + algName + " on " + entity + " ... "); long startTime = System.currentTimeMillis();
/** * 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; }
&& !((SPARQLReasoner)reasoner).isUseGenericSplitsCode()) { logger.warn("Numeric Facet restrictions are not (yet) implemented for " + AnnComponentManager.getName(reasoner) + ", option ignored"); } else { ValuesSplitter splitter = new DefaultNumericValuesSplitter(reasoner, df, maxNrOfSplits); && !((SPARQLReasoner)reasoner).isUseGenericSplitsCode()) { logger.warn("Time based Facet restrictions are not (yet) implemented for " + AnnComponentManager.getName(reasoner) + ", option ignored"); } else { ValuesSplitter splitter = new DefaultDateTimeValuesSplitter(reasoner, df, maxNrOfSplits);
throw new ComponentInitException("Class " + classToDescribe + " has 0 instances according to \"" + AnnComponentManager.getName(getReasoner().getClass()) + "\". Cannot perform class learning with 0 instances.");
axioms.add(ax); String algorithmName = AnnComponentManager.getName(algorithm); String algorithmID = "http://dl-learner.org#" + algorithmName.replace(" ", "_"); OWLIndividual algorithmInd = f.getOWLNamedIndividual(IRI.create(algorithmID)); ax = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Parameter, paramInd); axioms.add(ax); ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.parameterName, paramInd, AnnComponentManager.getName(entry.getKey())); axioms.add(ax); ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.parameterValue, paramInd, entry.getValue().toString());
/** * Checks whether all components implement the getName() method. While it * cannot be enforced to implement a static method, it should be done (e.g. * to be used as label for the component in GUIs). */ @Test public void nameTest() { AnnComponentManager cm = AnnComponentManager.getInstance(); Collection<Class<? extends Component>> components = cm.getComponents(); for (Class<? extends Component> component : components) { AnnComponentManager.getName(component); } }
if ( !(accuracyMethod instanceof AccMethodPredAcc) && !(accuracyMethod instanceof AccMethodFMeasure) ) { str += ", " + AnnComponentManager.getName(accuracyMethod) + ": " + dfPercent.format(ed.getAccuracy());
AnnComponentManager.getName(getReasoner().getClass()) + "\". Cannot perform class learning with 0 instances.");
throw new ComponentInitException("DIG does not support the inferences needed in the selected learning algorithm component: " + AnnComponentManager.getName(this));