/** * Returns a list of all available components in this instance * of <code>ComponentManager</code>. * @return the components A list of component classes available in this * instance of <code>ComponentManager</code>. */ public SortedSet<String> getComponentStrings() { SortedSet<String> result = getComponents().stream() .map(AnnComponentManager::getShortName) .collect(Collectors.toCollection(TreeSet::new)); return result; }
/** * Get registered components which are of the specified type. * * @param type The super type. * @return All sub classes of type. */ public SortedSet<String> getComponentStringsOfType(Class type) { SortedSet<String> result = getComponentsOfType(type).stream() .map(AnnComponentManager::getShortName) .collect(Collectors.toCollection(TreeSet::new)); return result; }
/** * 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()); }
header = "component: " + AnnComponentManager.getName(ccomp) + " (" + klass + ") v" + AnnComponentManager.getVersion(ccomp); description = AnnComponentManager.getDescription(ccomp); catString = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, category.getSimpleName()); ComponentAnn catAnn = category.getAnnotation(ComponentAnn.class); usage = "conf file usage: " + catString + ".type = \"" + AnnComponentManager.getShortName(ccomp) + "\"\n";
/** * 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); } }
public void writeConfigDocumentation(File file) { componentNames.putAll(cm.getComponentsNamed()); componentNames.put(CLI.class, "Command Line Interface"); componentNames.put(GlobalDoc.class, "GLOBAL OPTIONS"); Class<? extends Component> ccomp = (Class<? extends Component>) comp; sb.append("<dl class=\"dl-horizontal\"><dt>short name</dt><dd>" + AnnComponentManager.getShortName(ccomp) + "</dd>"); sb.append("<dt>version</dt><dd>" + AnnComponentManager.getVersion(ccomp) + "</dd>"); sb.append("<dt>implements</dt><dd><ul class=\"list-inline\"><li>" + getCoreTypes(comp).replace(" ", "</li><li>") + "</li></ul></dd>"); String description = AnnComponentManager.getDescription(ccomp); if(description.length() > 0) { sb.append("<dt>description</dt><dd>" + AnnComponentManager.getDescription(ccomp) + "</dd>");
+ Strings.repeat("*", name.length() + 4) + "\n\n"); for(Class<? extends Component> comp : cm.getComponentsOfType(cats)) { if (componentsDone.contains(comp)) continue; sc.append(getComponentConfigString(comp, cats)); for (Class<?> comp : cm.getComponents()) { StringBuilder sc = new StringBuilder(); if (!componentsDone.contains(comp)) {
public static void main(String[] args) { ClassPool cp = ClassPool.getDefault(); for (Class<? extends Component> c : cm.getComponents()) { startClass(c); Map<String, List<Field>> fields = new TreeMap<>(); hasDoc.add(AnnComponentManager.getName(f.getValue().get(0))); } else if (notConfig) { notConfigSet.add(f.getKey());
/** * 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; }
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) { e.printStackTrace();
@Test public void testGetComponentsOfType() { Collection<Class<? extends Component>> components = AnnComponentManager.getInstance().getComponentsOfType(ReasonerComponent.class); // System.out.println(components); // currently: [class org.dllearner.reasoning.OWLAPIReasoner, class org.dllearner.reasoning.FastInstanceChecker] Assert.assertTrue(components.size() >= 1); } }
BidiMap<Class<? extends Component>, String> componentsNamed = AnnComponentManager.getInstance().getComponentsNamed(); for(Entry<Class<? extends Component>, String> entry : componentsNamed.entrySet()) { if(entry.getValue().equalsIgnoreCase(value)) { BidiMap<Class<? extends Component>, String> componentsNamedShort = AnnComponentManager.getInstance().getComponentsNamedShort(); for(Entry<Class<? extends Component>, String> entry : componentsNamedShort.entrySet()) { if(entry.getValue().equalsIgnoreCase(value)) {
public DocumentationHTMLGenerator() { cm = AnnComponentManager.getInstance(); }
/** * Returns the short name of a DL-Learner component. * @param component the component * @return Short name of the component. */ public static String getShortName(Component component){ return getShortName(component.getClass()); }
/** * Returns the description of a DL-Learner component. * @param component the component * @return OWLClassExpression of the component. */ public static String getDescription(Component component){ return getDescription(component.getClass()); }
/** * Returns the version of a DL-Learner component. * @param component the component * @return Version of the component. */ public static double getVersion(Component component){ return getVersion(component.getClass()); }
/** * Gets the singleton instance of <code>ComponentManager</code>. * @return The singleton <code>ComponentManager</code> instance. */ public static AnnComponentManager getInstance() { if(cm == null) { cm = new AnnComponentManager(); } return cm; }
boolean try_inv = applyConfigEntry(cc, optionName, value); if (try_inv) { return true;
/** * 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(); } } } } }