Package adams.flow.core
Class AbstractModelLoader<T>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.flow.core.AbstractModelLoader<T>
-
- Type Parameters:
T
- the type of model
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,ModelFileHandler
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,FlowContextHandler
,Serializable
- Direct Known Subclasses:
WekaClassifierModelLoader
,WekaClustererModelLoader
,WekaFilterModelLoader
public abstract class AbstractModelLoader<T> extends AbstractOptionHandler implements FlowContextHandler, ModelFileHandler
Ancestor for model loaders.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractModelLoader.ModelLoadingType
The enumeration for the loading type.
-
Field Summary
Fields Modifier and Type Field Description protected Actor
m_FlowContext
the flow context.protected CallableActorHelper
m_Helper
for locating callable actors.protected T
m_Model
the model.protected CallableActorReference
m_ModelActor
the model actor.protected PlaceholderFile
m_ModelFile
the mode file.protected AbstractModelLoader.ModelLoadingType
m_ModelLoadingType
the loading type.protected StorageName
m_ModelStorage
the model storage.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractModelLoader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
automaticOrderInfo()
Returns information how the model is loaded in case ofAbstractModelLoader.ModelLoadingType.AUTO
.void
defineOptions()
Adds options to the internal list of options.protected Object
deserializeFile(MessageCollection errors)
Deserializes the model file.Actor
getFlowContext()
Returns the flow context, if any.T
getModel(MessageCollection errors)
Obtains the model, loads it if necessary.CallableActorReference
getModelActor()
Returns the callable actor to obtain the model from.PlaceholderFile
getModelFile()
Returns the file to load the model from.protected abstract T
getModelFromContainer(AbstractContainer cont, MessageCollection errors)
Retrieves the model from the container.AbstractModelLoader.ModelLoadingType
getModelLoadingType()
Returns the loading type.StorageName
getModelStorage()
Returns the storage item name to get the model from.protected void
initialize()
Initializes the members.protected T
loadAutomatically(MessageCollection errors)
Loads the model automatically from file/callable actor/storage.protected T
loadFromCallableActor(MessageCollection errors)
Loads the model from the callable actor.protected T
loadFromFile(MessageCollection errors)
Loads the model from the specified file.protected T
loadFromStorage(MessageCollection errors)
Loads the model from the storage item.String
modelActorTipText()
Returns the tip text for this property.String
modelFileTipText()
Returns the tip text for this property.String
modelLoadingTypeTipText()
Returns the tip text for this property.String
modelStorageTipText()
Returns the tip text for this property.void
reset()
Resets the scheme.void
setFlowContext(Actor value)
Sets the flow context.void
setModelActor(CallableActorReference value)
Sets the callable actor to obtain the model from.void
setModelFile(PlaceholderFile value)
Sets the file to load the model from.void
setModelLoadingType(AbstractModelLoader.ModelLoadingType value)
Sets the loading type.void
setModelStorage(StorageName value)
Sets the storage item name to get the model from.protected void
unhandledContainer(AbstractContainer cont, MessageCollection errors)
Adds an "unhandled container type" error message.protected T
unwrapModel(Object obj, MessageCollection errors)
Unwraps the model if necessary.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_FlowContext
protected Actor m_FlowContext
the flow context.
-
m_ModelLoadingType
protected AbstractModelLoader.ModelLoadingType m_ModelLoadingType
the loading type.
-
m_ModelFile
protected PlaceholderFile m_ModelFile
the mode file.
-
m_ModelActor
protected CallableActorReference m_ModelActor
the model actor.
-
m_ModelStorage
protected StorageName m_ModelStorage
the model storage.
-
m_Model
protected T m_Model
the model.
-
m_Helper
protected CallableActorHelper m_Helper
for locating callable actors.
-
-
Method Detail
-
automaticOrderInfo
public String automaticOrderInfo()
Returns information how the model is loaded in case ofAbstractModelLoader.ModelLoadingType.AUTO
.- Returns:
- the description
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionHandler
-
reset
public void reset()
Resets the scheme.- Overrides:
reset
in classAbstractOptionHandler
-
setFlowContext
public void setFlowContext(Actor value)
Sets the flow context.- Specified by:
setFlowContext
in interfaceFlowContextHandler
- Parameters:
value
- the actor
-
getFlowContext
public Actor getFlowContext()
Returns the flow context, if any.- Specified by:
getFlowContext
in interfaceFlowContextHandler
- Returns:
- the actor, null if none available
-
setModelLoadingType
public void setModelLoadingType(AbstractModelLoader.ModelLoadingType value)
Sets the loading type. In case ofAbstractModelLoader.ModelLoadingType.AUTO
, first file, then callable actor, then storage.- Parameters:
value
- the type
-
getModelLoadingType
public AbstractModelLoader.ModelLoadingType getModelLoadingType()
Returns the loading type. In case ofAbstractModelLoader.ModelLoadingType.AUTO
, first file, then callable actor, then storage.- Returns:
- the type
-
modelLoadingTypeTipText
public String modelLoadingTypeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setModelFile
public void setModelFile(PlaceholderFile value)
Sets the file to load the model from.- Specified by:
setModelFile
in interfaceModelFileHandler
- Parameters:
value
- the model file
-
getModelFile
public PlaceholderFile getModelFile()
Returns the file to load the model from.- Specified by:
getModelFile
in interfaceModelFileHandler
- Returns:
- the model file
-
modelFileTipText
public String modelFileTipText()
Returns the tip text for this property.- Specified by:
modelFileTipText
in interfaceModelFileHandler
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setModelActor
public void setModelActor(CallableActorReference value)
Sets the callable actor to obtain the model from.- Parameters:
value
- the actor reference
-
getModelActor
public CallableActorReference getModelActor()
Returns the callable actor to obtain the model from.- Returns:
- the actor reference
-
modelActorTipText
public String modelActorTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setModelStorage
public void setModelStorage(StorageName value)
Sets the storage item name to get the model from.- Parameters:
value
- the storage name
-
getModelStorage
public StorageName getModelStorage()
Returns the storage item name to get the model from.- Returns:
- the storage name
-
modelStorageTipText
public String modelStorageTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
unhandledContainer
protected void unhandledContainer(AbstractContainer cont, MessageCollection errors)
Adds an "unhandled container type" error message.- Parameters:
cont
- the unhandled container typeerrors
- the errors to update
-
getModelFromContainer
protected abstract T getModelFromContainer(AbstractContainer cont, MessageCollection errors)
Retrieves the model from the container.- Parameters:
cont
- the container to get the model fromerrors
- for collecting errors- Returns:
- the model, null if not in container
-
unwrapModel
protected T unwrapModel(Object obj, MessageCollection errors)
Unwraps the model if necessary.- Parameters:
obj
- the model to processerrors
- for collecting errors- Returns:
- the unwrapped model, null if failed or input was null
-
deserializeFile
protected Object deserializeFile(MessageCollection errors)
Deserializes the model file.- Parameters:
errors
- for collecting errors- Returns:
- the object read from the file, null if failed
-
loadFromFile
protected T loadFromFile(MessageCollection errors)
Loads the model from the specified file.- Parameters:
errors
- for collecting errors- Returns:
- the model, null if failed to load
-
loadFromCallableActor
protected T loadFromCallableActor(MessageCollection errors)
Loads the model from the callable actor.- Parameters:
errors
- for collecting errors- Returns:
- the model, null if failed to load
-
loadFromStorage
protected T loadFromStorage(MessageCollection errors)
Loads the model from the storage item.- Parameters:
errors
- for collecting errors- Returns:
- the model, null if failed to load
-
loadAutomatically
protected T loadAutomatically(MessageCollection errors)
Loads the model automatically from file/callable actor/storage.- Parameters:
errors
- for collecting errors- Returns:
- the model, null if failed
-
getModel
public T getModel(MessageCollection errors)
Obtains the model, loads it if necessary.- Parameters:
errors
- for collecting errors- Returns:
- the model, null if failed to load
-
-