GATE
Version 3.1-2270

gate.creole.ml.weka
Class Wrapper

java.lang.Object
  extended by gate.creole.ml.weka.Wrapper
All Implemented Interfaces:
AdvancedMLEngine, MLEngine, ActionsPublisher

public class Wrapper
extends Object
implements AdvancedMLEngine, ActionsPublisher

Wrapper class for the WEKA Machine Learning Engine.

See Also:
WEKA homepage

Nested Class Summary
protected  class Wrapper.LoadDatasetFromArffAction
           
protected  class Wrapper.LoadModelAction
           
protected  class Wrapper.SaveDatasetAsArffAction
           
protected  class Wrapper.SaveModelAction
           
 
Field Summary
protected  List actionsList
           
protected  weka.classifiers.Classifier classifier
          The WEKA classifier used by this wrapper
protected  weka.core.Instances dataset
          The dataset used for training
protected  boolean datasetChanged
          Marks whether the dataset was changed since the last time the classifier was built.
protected  DatasetDefintion datasetDefinition
           
protected  File datasetFile
           
protected  boolean onlyAccumulateDataset
          This variable is set when the ML configuration file has neither the classifier nor the output dataset file option.
protected  org.jdom.Element optionsElement
          The JDom element contaning the options fro this wrapper.
protected  ProcessingResource owner
           
protected  StatusListener sListener
           
 
Constructor Summary
Wrapper()
           
 
Method Summary
protected  void addTrainingInstance(weka.core.Instance instance)
           
 void addTrainingInstance(List attributeValues)
          Adds a new training instance to the dataset.
 List batchClassifyInstances(List instances)
          Some wrappers allow batch classification, but this one doesn't, so if it's ever called just inform the user about this by throwing an exception.
protected  weka.core.Instance buildInstance(List attributeValues)
          Constructs an instance valid for the current dataset from a list of attribute values.
 Object classifyInstance(List attributeValues)
          Classifies a new instance.
 void cleanUp()
          No clean up is needed for this wrapper, so this is just added because its in the interface.
protected  Object convertAttributeValue(double value)
           
 List getActions()
          Gets the list of actions that can be performed on this resource.
 DatasetDefintion getDatasetDefinition()
           
 void init()
          Initialises the classifier and prepares for running.
 void load(InputStream is)
          Loads the state of this engine from previously saved data.
 void loadDatasetFromArff(FileReader reader)
           
protected  String[] parseOptions(String optionsString)
           
 void save(OutputStream os)
          Saves the state of the engine for reuse at a later time.
 void saveDatasetAsARFF(FileWriter writer)
           
 void setDatasetDefinition(DatasetDefintion definition)
          Sets the definition for the dataset used.
 void setOptions(org.jdom.Element optionsElem)
          Sets the options from an XML JDom element.
 void setOwnerPR(ProcessingResource pr)
          Registers the PR using the engine with the engine itself.
 boolean supportsBatchMode()
          Returns true if the engine supports BatchMode, returns false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

datasetDefinition

protected DatasetDefintion datasetDefinition

classifier

protected weka.classifiers.Classifier classifier
The WEKA classifier used by this wrapper


dataset

protected weka.core.Instances dataset
The dataset used for training


optionsElement

protected org.jdom.Element optionsElement
The JDom element contaning the options fro this wrapper.


datasetChanged

protected boolean datasetChanged
Marks whether the dataset was changed since the last time the classifier was built.


datasetFile

protected File datasetFile

actionsList

protected List actionsList

owner

protected ProcessingResource owner

sListener

protected StatusListener sListener

onlyAccumulateDataset

protected boolean onlyAccumulateDataset
This variable is set when the ML configuration file has neither the classifier nor the output dataset file option. User is responsible for explicitly saving the dataset using the now uncommented SaveDatasetAsArff function / action.

Constructor Detail

Wrapper

public Wrapper()
Method Detail

cleanUp

public void cleanUp()
No clean up is needed for this wrapper, so this is just added because its in the interface.

Specified by:
cleanUp in interface MLEngine

setOptions

public void setOptions(org.jdom.Element optionsElem)
Description copied from interface: MLEngine
Sets the options from an XML JDom element.

Specified by:
setOptions in interface MLEngine
Parameters:
optionsElem - the JDom element containing the options from the configuration.

batchClassifyInstances

public List batchClassifyInstances(List instances)
                            throws ExecutionException
Some wrappers allow batch classification, but this one doesn't, so if it's ever called just inform the user about this by throwing an exception.

Specified by:
batchClassifyInstances in interface MLEngine
Parameters:
instances - This parameter is not used.
Returns:
Nothing is ever returned - an exception is always thrown.
Throws:
ExecutionException

addTrainingInstance

public void addTrainingInstance(List attributeValues)
                         throws ExecutionException
Description copied from interface: MLEngine
Adds a new training instance to the dataset.

Specified by:
addTrainingInstance in interface MLEngine
Parameters:
attributeValues - the list of attributes describing the instance. The elements in the list are String values that need to be interpreted according to the dataset definition: for nominal attributes the values will used as they are; for numeric attributes the values will be converted to double.
Throws:
ExecutionException

addTrainingInstance

protected void addTrainingInstance(weka.core.Instance instance)
                            throws ExecutionException
Throws:
ExecutionException

buildInstance

protected weka.core.Instance buildInstance(List attributeValues)
                                    throws ExecutionException
Constructs an instance valid for the current dataset from a list of attribute values.

Parameters:
attributeValues - the values for the attributes.
Returns:
an Instance value.
Throws:
ExecutionException

setDatasetDefinition

public void setDatasetDefinition(DatasetDefintion definition)
Description copied from interface: MLEngine
Sets the definition for the dataset used.

Specified by:
setDatasetDefinition in interface MLEngine

classifyInstance

public Object classifyInstance(List attributeValues)
                        throws ExecutionException
Description copied from interface: MLEngine
Classifies a new instance.

Specified by:
classifyInstance in interface MLEngine
Parameters:
attributeValues - the list of attributes describing the instance. The elements in the list are Object values that need to be interpreted according to the dataset definition. The value for the class element will be arbitrary.
Returns:
a String value for nominal and boolean attributes and a Double value for numeric attributes.
Throws:
ExecutionException

convertAttributeValue

protected Object convertAttributeValue(double value)

init

public void init()
          throws GateException
Initialises the classifier and prepares for running.

Specified by:
init in interface MLEngine
Throws:
GateException

parseOptions

protected String[] parseOptions(String optionsString)

load

public void load(InputStream is)
          throws IOException
Loads the state of this engine from previously saved data.

Parameters:
is -
Throws:
IOException

save

public void save(OutputStream os)
          throws IOException
Saves the state of the engine for reuse at a later time.

Parameters:
os -
Throws:
IOException

getActions

public List getActions()
Gets the list of actions that can be performed on this resource.

Specified by:
getActions in interface ActionsPublisher
Returns:
a List of Action objects (or null values)

setOwnerPR

public void setOwnerPR(ProcessingResource pr)
Registers the PR using the engine with the engine itself.

Specified by:
setOwnerPR in interface MLEngine
Parameters:
pr - the processing resource that owns this engine.

getDatasetDefinition

public DatasetDefintion getDatasetDefinition()

saveDatasetAsARFF

public void saveDatasetAsARFF(FileWriter writer)

loadDatasetFromArff

public void loadDatasetFromArff(FileReader reader)
                         throws IOException,
                                ExecutionException,
                                Exception
Throws:
IOException
ExecutionException
Exception

supportsBatchMode

public boolean supportsBatchMode()
Description copied from interface: AdvancedMLEngine
Returns true if the engine supports BatchMode, returns false otherwise.

Specified by:
supportsBatchMode in interface AdvancedMLEngine

GATE
Version 3.1-2270