org.dllearner.core
Class ComponentManager

java.lang.Object
  extended by org.dllearner.core.ComponentManager

public final class ComponentManager
extends Object

Central manager class for DL-Learner. There are currently four types of components in DL-Learner: knowledge sources, reasoners, learning problems, and learning algorithms. For accessing these components you should create instances and configure them using this class. The component manager is implemented as a Singleton and will read the components file (containing a list of all components) at startup. This allows interfaces (command line, graphical, web service) to easily query the available components, set and get their configuration options, and run the algorithm.

Author:
Jens Lehmann

Method Summary
<T> boolean
applyConfigEntry(AbstractComponent component, ConfigEntry<T> entry)
          Applies a config entry to a component.
<T> void
applyConfigEntry(AbstractComponent component, String optionName, T value)
          Convenience method for testing purposes.
 void freeAllComponents()
          Frees all references to components created by ComponentManager.
 void freeComponent(AbstractComponent component)
          The ComponentManager factory methods produce component instances, which can be freed using this method.
 List<Class<? extends AbstractCELA>> getApplicableLearningAlgorithms(Class<? extends AbstractLearningProblem> learningProblem)
          Returns the set of learning algorithms, which support the given learning problem type.
 String getComponentName(Class<? extends AbstractComponent> component)
          Returns the name of a component.
 List<Class<? extends AbstractComponent>> getComponents()
          Returns a list of all available components in this instance of ComponentManager.
 ConfigOption<?> getConfigOption(Class<? extends AbstractComponent> component, String name)
          Returns a ConfigOption object given a component and the option name.
static List<ConfigOption<?>> getConfigOptions(Class<? extends AbstractComponent> componentClass)
          Returns the available options of the specified component.
<T> T
getConfigOptionValue(AbstractComponent component, ConfigOption<T> option)
          Gets the value of a config option of the specified component.
 Object getConfigOptionValue(AbstractComponent component, String optionName)
          Works as getConfigOptionValue(AbstractComponent, ConfigOption), but using the name of the option instead of a ConfigOption object.
static ComponentManager getInstance()
          Gets the singleton instance of ComponentManager.
 List<Class<? extends AbstractKnowledgeSource>> getKnowledgeSources()
          Returns a list of all available knowledge sources in this instance of ComponentManager.
 List<Class<? extends AbstractCELA>> getLearningAlgorithms()
          Returns a list of all available learning algorithms in this instance of ComponentManager.
 List<Class<? extends AbstractLearningProblem>> getLearningProblems()
          Returns a list of all available learning problems in this instance of ComponentManager.
 List<AbstractComponent> getLiveComponents()
          Retuns a list of all instanciated and registered Components
 List<AbstractKnowledgeSource> getLiveKnowledgeSources()
          Retuns a list of all instanciated and registered KnowledgeSource
 List<AbstractCELA> getLiveLearningAlgorithms()
          Retuns a list of all instanciated and registered LearningAlgorithm
 ComponentPool getPool()
           
 List<Class<? extends AbstractReasonerComponent>> getReasonerComponents()
          Returns a list of all available reasoners in this instance of ComponentManager.
<T extends AbstractKnowledgeSource>
T
knowledgeSource(Class<T> source)
          Factory method for creating a knowledge source.
<T extends AbstractCELA>
T
learningAlgorithm(Class<T> laClass, AbstractLearningProblem lp, AbstractReasonerComponent rs)
          Factory method for creating a learning algorithm, which automagically calls the right constructor for the given problem.
<T extends AbstractLearningProblem>
T
learningProblem(Class<T> lpClass, AbstractReasonerComponent reasoner)
          Factory method for creating a learning problem component.
<T extends AbstractReasonerComponent>
T
reasoner(Class<T> reasoner, AbstractKnowledgeSource... sources)
          Factory method for creating a reasoner component from a set of knowledge sources.
<T extends AbstractReasonerComponent>
T
reasoner(Class<T> reasoner, AbstractKnowledgeSource source)
          Factory method for creating a reasoner component from a single knowledge source.
<T extends AbstractReasonerComponent>
T
reasoner(Class<T> reasoner, Set<AbstractKnowledgeSource> sources)
          Factory method for creating a reasoner component from a set of knowledge sources.
static void setComponentClasses(String[] componentClasses)
          Set the classes, which can be used as components.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ComponentManager getInstance()
Gets the singleton instance of ComponentManager.

Returns:
The singleton ComponentManager instance.

setComponentClasses

public static void setComponentClasses(String[] componentClasses)
Set the classes, which can be used as components. By default, this is read from components.ini, but this method can be used to set the components programmatically. This method must be used before the first call to getInstance(), otherwise it has no effect.

Parameters:
componentClasses - A list of class names, e.g. org.dllearner.refinement.ROLearner.

applyConfigEntry

public <T> void applyConfigEntry(AbstractComponent component,
                                 String optionName,
                                 T value)
Convenience method for testing purposes. If you know that the type of the value is correct, it is preferable to create a ConfigEntry object and apply it to the component (no type checking necessary).

Type Parameters:
T - Type of the config option (Integer, String etc.).
Parameters:
component - A component.
optionName - The name of the config option.
value - The value of the config option.

getPool

public ComponentPool getPool()

applyConfigEntry

public <T> boolean applyConfigEntry(AbstractComponent component,
                                    ConfigEntry<T> entry)
Applies a config entry to a component. If the entry is not valid, the method prints an exception and returns false.

Type Parameters:
T - Type of the config option.
Parameters:
component - A component object.
entry - The configuration entry to set.
Returns:
True of the config entry could be applied succesfully, otherwise false.

knowledgeSource

public <T extends AbstractKnowledgeSource> T knowledgeSource(Class<T> source)
Factory method for creating a knowledge source.

Type Parameters:
T - The type of this method is a subclass of knowledge source.
Parameters:
source - A registered knowledge source component.
Returns:
An instance of the given knowledge source class.

reasoner

public <T extends AbstractReasonerComponent> T reasoner(Class<T> reasoner,
                                                        AbstractKnowledgeSource source)
Factory method for creating a reasoner component from a single knowledge source. Example call: reasoner(OWLAPIReasoner.class, ks) where ks is a knowledge source object.

Type Parameters:
T - The type of this method is a subclass of reasoner component.
Parameters:
reasoner - A class object, where the class is subclass of ReasonerComponent.
source - A knowledge source.
Returns:
A reasoner component.
See Also:
reasoner(Class, Set)

reasoner

public <T extends AbstractReasonerComponent> T reasoner(Class<T> reasoner,
                                                        Set<AbstractKnowledgeSource> sources)
Factory method for creating a reasoner component from a set of knowledge sources.

Type Parameters:
T - The type of this method is a subclass of reasoner component.
Parameters:
reasoner - A class object, where the class is subclass of ReasonerComponent.
sources - A set of knowledge sources.
Returns:
A reasoner component.
See Also:
reasoner(Class, AbstractKnowledgeSource)

reasoner

public <T extends AbstractReasonerComponent> T reasoner(Class<T> reasoner,
                                                        AbstractKnowledgeSource... sources)
Factory method for creating a reasoner component from a set of knowledge sources.

Type Parameters:
T - The type of this method is a subclass of reasoner component.
Parameters:
reasoner - A class object, where the class is subclass of ReasonerComponent.
sources - A set of knowledge sources.
Returns:
A reasoner component.
See Also:
reasoner(Class, AbstractKnowledgeSource)

learningProblem

public <T extends AbstractLearningProblem> T learningProblem(Class<T> lpClass,
                                                             AbstractReasonerComponent reasoner)
Factory method for creating a learning problem component.

Type Parameters:
T - The type of this method is a subclass of learning problem.
Parameters:
lpClass - A class object, where the class is a subclass of learning problem.
reasoner - A reasoning service object.
Returns:
A learning problem component.

learningAlgorithm

public <T extends AbstractCELA> T learningAlgorithm(Class<T> laClass,
                                                    AbstractLearningProblem lp,
                                                    AbstractReasonerComponent rs)
                                         throws LearningProblemUnsupportedException
Factory method for creating a learning algorithm, which automagically calls the right constructor for the given problem.

Type Parameters:
T - The type of this method is a subclass of learning algorithm.
Parameters:
laClass - A class object, where the class is subclass of learning algorithm.
lp - A learning problem, which the algorithm should try to solve.
rs - A reasoning service for querying the background knowledge of this learning problem.
Returns:
A learning algorithm component.
Throws:
LearningProblemUnsupportedException - Thrown when the learning problem and the learning algorithm are not compatible.

freeComponent

public void freeComponent(AbstractComponent component)
The ComponentManager factory methods produce component instances, which can be freed using this method. Calling the factory methods without freeing components when they are not used anymore can (in theory) cause memory problems.

Parameters:
component - The component to free.

freeAllComponents

public void freeAllComponents()
Frees all references to components created by ComponentManager.

See Also:
freeComponent(AbstractComponent)

getConfigOptionValue

public <T> T getConfigOptionValue(AbstractComponent component,
                                  ConfigOption<T> option)
Gets the value of a config option of the specified component. This is done by first checking, which value the given option was set to using applyConfigEntry(AbstractComponent, ConfigEntry). If the value has not been changed, the default value for this option is returned. Note, that this method will not work properly if the component options are changed internally surpassing the component manager (which is discouraged).

Type Parameters:
T - The type of the config option, e.g. String, boolean, integer.
Parameters:
component - The component, which has the specified option.
option - The option for which we want to know its value.
Returns:
The value of the specified option in the specified component.

getConfigOptionValue

public Object getConfigOptionValue(AbstractComponent component,
                                   String optionName)
Works as getConfigOptionValue(AbstractComponent, ConfigOption), but using the name of the option instead of a ConfigOption object.

Parameters:
component - A component.
optionName - A valid option name for this component.
Returns:
The value of the specified option in the specified component.
See Also:
getConfigOptionValue(AbstractComponent, ConfigOption)

getConfigOptions

public static List<ConfigOption<?>> getConfigOptions(Class<? extends AbstractComponent> componentClass)
Returns the available options of the specified component.

Parameters:
componentClass - The class object of a component.
Returns:
A list of available configuration options of the specified component.

getConfigOption

public ConfigOption<?> getConfigOption(Class<? extends AbstractComponent> component,
                                       String name)
Returns a ConfigOption object given a component and the option name.

Parameters:
component - A component class object.
name - A valid configuration option name for the component.
Returns:
A ConfigOption object for the specified component class and option name.

getComponentName

public String getComponentName(Class<? extends AbstractComponent> component)
Returns the name of a component.

Parameters:
component - A component class object.
Returns:
The name of the component.

getComponents

public List<Class<? extends AbstractComponent>> getComponents()
Returns a list of all available components in this instance of ComponentManager.

Returns:
the components A list of component classes available in this instance of ComponentManager.

getKnowledgeSources

public List<Class<? extends AbstractKnowledgeSource>> getKnowledgeSources()
Returns a list of all available knowledge sources in this instance of ComponentManager.

Returns:
the components A list of knowledge source component classes available in this instance of ComponentManager.

getReasonerComponents

public List<Class<? extends AbstractReasonerComponent>> getReasonerComponents()
Returns a list of all available reasoners in this instance of ComponentManager.

Returns:
the components A list of reasoner component classes available in this instance of ComponentManager.

getLearningProblems

public List<Class<? extends AbstractLearningProblem>> getLearningProblems()
Returns a list of all available learning problems in this instance of ComponentManager.

Returns:
the components A list of learning problem classes available in this instance of ComponentManager.

getApplicableLearningAlgorithms

public List<Class<? extends AbstractCELA>> getApplicableLearningAlgorithms(Class<? extends AbstractLearningProblem> learningProblem)
Returns the set of learning algorithms, which support the given learning problem type.

Parameters:
learningProblem - A learning problem type.
Returns:
The set of learning algorithms applicable for this learning problem.

getLearningAlgorithms

public List<Class<? extends AbstractCELA>> getLearningAlgorithms()
Returns a list of all available learning algorithms in this instance of ComponentManager.

Returns:
the components A list of learning algorithm classes available in this instance of ComponentManager.

getLiveComponents

public List<AbstractComponent> getLiveComponents()
Retuns a list of all instanciated and registered Components

Returns:
Currently active components.

getLiveLearningAlgorithms

public List<AbstractCELA> getLiveLearningAlgorithms()
Retuns a list of all instanciated and registered LearningAlgorithm

Returns:
Currently active learning algorithms.

getLiveKnowledgeSources

public List<AbstractKnowledgeSource> getLiveKnowledgeSources()
Retuns a list of all instanciated and registered KnowledgeSource

Returns:
Currently active knowledge sources.


SourceForge.net Logo DL-Learner is licenced under the terms of the GNU General Public License.
Copyright © 2007-2011 Jens Lehmann