weka.classifiers.scripting
Class GroovyClassifier

java.lang.Object
  extended by weka.classifiers.AbstractClassifier
      extended by weka.classifiers.scripting.GroovyClassifier
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Classifier, CapabilitiesHandler, OptionHandler, RevisionHandler

public class GroovyClassifier
extends AbstractClassifier

A wrapper class for Groovy code. Even though the classifier is serializable, the trained classifier cannot be stored persistently. I.e., one cannot store a model file and re-load it at a later point in time again to make predictions.

Valid options are:

 -G <filename>
  The Groovy module to load (full path)
  Options after '--' will be passed on to the Groovy module.
 -D
  If set, classifier is run in debug mode and
  may output additional info to the console
Options after "--" will be passed on to the Groovy module.

In order to use Groovy, the jar containing all the classes must be present in the CLASSPATH. This jar is normally found in the embeddable sub-directory of the Groovy installation.

Tested with Groovy 1.5.7.

Version:
$Revision: 8109 $
Author:
FracPete (fracpete at waikato dot ac dot nz)
See Also:
Groovy, Serialized Form

Constructor Summary
GroovyClassifier()
          default constructor.
 
Method Summary
 void buildClassifier(Instances instances)
          Generates the classifier.
 double classifyInstance(Instance instance)
          Classifies a given instance.
 double[] distributionForInstance(Instance instance)
          Calculates the class membership probabilities for the given test instance.
 Capabilities getCapabilities()
          Returns default capabilities of the classifier.
 java.io.File getGroovyModule()
          Gets the Groovy module.
 java.lang.String getGroovyOptions()
          Gets the Groovy module options.
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 java.lang.String getRevision()
          Returns the revision string.
 java.lang.String globalInfo()
          Returns a string describing classifier.
 java.lang.String GroovyModuleTipText()
          Returns the tip text for this property.
 java.lang.String GroovyOptionsTipText()
          Returns the tip text for this property.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] args)
          Main method for testing this class.
 void setGroovyModule(java.io.File value)
          Sets the Groovy module.
 void setGroovyOptions(java.lang.String value)
          Sets the Groovy module options.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 java.lang.String toString()
          Returns a description of the classifier.
 
Methods inherited from class weka.classifiers.AbstractClassifier
debugTipText, forName, getDebug, makeCopies, makeCopy, runClassifier, setDebug
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GroovyClassifier

public GroovyClassifier()
default constructor.

Method Detail

globalInfo

public java.lang.String globalInfo()
Returns a string describing classifier.

Returns:
a description suitable for displaying in the explorer/experimenter gui

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class AbstractClassifier
Returns:
an enumeration of all the available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options.

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class AbstractClassifier
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the Classifier.

Specified by:
getOptions in interface OptionHandler
Overrides:
getOptions in class AbstractClassifier
Returns:
an array of strings suitable for passing to setOptions

GroovyModuleTipText

public java.lang.String GroovyModuleTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setGroovyModule

public void setGroovyModule(java.io.File value)
Sets the Groovy module.

Parameters:
value - the Groovy module

getGroovyModule

public java.io.File getGroovyModule()
Gets the Groovy module.

Returns:
the Groovy module

GroovyOptionsTipText

public java.lang.String GroovyOptionsTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

setGroovyOptions

public void setGroovyOptions(java.lang.String value)
Sets the Groovy module options.

Parameters:
value - the options

getGroovyOptions

public java.lang.String getGroovyOptions()
Gets the Groovy module options.

Returns:
the options

getCapabilities

public Capabilities getCapabilities()
Returns default capabilities of the classifier.

Specified by:
getCapabilities in interface Classifier
Specified by:
getCapabilities in interface CapabilitiesHandler
Overrides:
getCapabilities in class AbstractClassifier
Returns:
the capabilities of this classifier

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Generates the classifier.

Parameters:
instances - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Classifies a given instance.

Specified by:
classifyInstance in interface Classifier
Overrides:
classifyInstance in class AbstractClassifier
Parameters:
instance - the instance to be classified
Returns:
index of the predicted class
Throws:
java.lang.Exception - if an error occurred during the prediction

distributionForInstance

public double[] distributionForInstance(Instance instance)
                                 throws java.lang.Exception
Calculates the class membership probabilities for the given test instance.

Specified by:
distributionForInstance in interface Classifier
Overrides:
distributionForInstance in class AbstractClassifier
Parameters:
instance - the instance to be classified
Returns:
predicted class probability distribution
Throws:
java.lang.Exception - if class is numeric

toString

public java.lang.String toString()
Returns a description of the classifier.

Overrides:
toString in class java.lang.Object
Returns:
a description of the classifier as a string.

getRevision

public java.lang.String getRevision()
Returns the revision string.

Specified by:
getRevision in interface RevisionHandler
Overrides:
getRevision in class AbstractClassifier
Returns:
the revision

main

public static void main(java.lang.String[] args)
Main method for testing this class.

Parameters:
args - the options