Class SocketFacade

  • All Implemented Interfaces:
    Serializable, Cloneable, weka.classifiers.Classifier, weka.core.BatchPredictor, weka.core.CapabilitiesHandler, weka.core.CapabilitiesIgnorer, weka.core.CommandlineRunnable, weka.core.OptionHandler, weka.core.RevisionHandler

    public class SocketFacade
    extends weka.classifiers.AbstractClassifier
    Uses sockets to communicate with a process for training and making predictions.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Remote

        protected BaseHostname m_Remote
        the address of the remote process.
      • m_Local

        protected BaseHostname m_Local
        the return address for the remote process to use.
      • m_Timeout

        protected int m_Timeout
        the timeout for the socket.
      • m_SkipTrain

        protected boolean m_SkipTrain
        whether to skip training.
      • m_Server

        protected transient ServerSocket m_Server
        the server socket for receiving the replies.
    • Constructor Detail

      • SocketFacade

        public SocketFacade()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this classifier.
        Returns:
        a description of the classifier suitable for displaying in the explorer/experimenter gui
      • listOptions

        public Enumeration listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface weka.core.OptionHandler
        Overrides:
        listOptions in class weka.classifiers.AbstractClassifier
        Returns:
        an enumeration of all the available options.
      • setOptions

        public void setOptions​(String[] options)
                        throws Exception
        Parses a given list of options.
        Specified by:
        setOptions in interface weka.core.OptionHandler
        Overrides:
        setOptions in class weka.classifiers.AbstractClassifier
        Parameters:
        options - the list of options as an array of strings
        Throws:
        Exception - if an option is not supported
      • getOptions

        public String[] getOptions()
        Gets the current settings of the classifier.
        Specified by:
        getOptions in interface weka.core.OptionHandler
        Overrides:
        getOptions in class weka.classifiers.AbstractClassifier
        Returns:
        an array of strings suitable for passing to setOptions
      • getDefaultRemote

        protected BaseHostname getDefaultRemote()
        Returns the default address of the remote process.
        Returns:
        the default
      • setRemote

        public void setRemote​(BaseHostname value)
        Sets address of the remote process.
        Parameters:
        value - the address
      • getRemote

        public BaseHostname getRemote()
        Returns the address of the remote process.
        Returns:
        the address
      • remoteTipText

        public String remoteTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getDefaultLocal

        protected BaseHostname getDefaultLocal()
        Returns the default address of the return address.
        Returns:
        the default
      • setLocal

        public void setLocal​(BaseHostname value)
        Sets the return address for the remote process to use.
        Parameters:
        value - the address
      • getLocal

        public BaseHostname getLocal()
        Returns the return address for the remote process to use.
        Returns:
        the address
      • localTipText

        public String localTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getDefaultTimeout

        protected int getDefaultTimeout()
        The default timeout in milli-second.
        Returns:
        the default
      • setTimeout

        public void setTimeout​(int value)
        Sets the timeout in milli-second to wait for new connections.
        Parameters:
        value - the timeout in msec
      • getTimeout

        public int getTimeout()
        Returns the timeout in milli-second to wait for new connections.
        Returns:
        the timeout in msec
      • timeoutTipText

        public String timeoutTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the gui
      • getDefaultPreparation

        protected AbstractDataPreparation getDefaultPreparation()
        Returns the default data preparation scheme to use.
        Returns:
        the default
      • setPreparation

        public void setPreparation​(AbstractDataPreparation value)
        Sets the data preparation scheme to use.
        Parameters:
        value - the scheme
      • getPreparation

        public AbstractDataPreparation getPreparation()
        Returns the data preparation scheme to use.
        Returns:
        the scheme
      • preparationTipText

        public String preparationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setSkipTrain

        public void setSkipTrain​(boolean value)
        Sets whether to skip training, eg when using a pre-built model.
        Parameters:
        value - true if to skip training
      • getSkipTrain

        public boolean getSkipTrain()
        Returns whether to skip training, eg when using a pre-built model.
        Returns:
        true if to skip training
      • skipTrainTipText

        public String skipTrainTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • initServer

        protected void initServer()
                           throws Exception
        Initializes the server socket if necessary.
        Throws:
        Exception - if initialization fails
      • closeServer

        protected void closeServer()
        Closes the server socket if necessary.
      • getServer

        protected ServerSocket getServer()
                                  throws Exception
        Returns the server socket, instantiates it if necessary.
        Returns:
        the socket
        Throws:
        Exception - if binding of socket fails
      • receive

        protected byte[] receive()
                          throws Exception
        Receives the response data.
        Returns:
        the received data
        Throws:
        Exception - if fails to receive data
      • send

        protected byte[] send​(byte[] data)
                       throws Exception
        Sends the data to the remote host.
        Parameters:
        data - the data to send
        Returns:
        the response data
        Throws:
        Exception - if sending fails
      • getCapabilities

        public weka.core.Capabilities getCapabilities()
        Returns the Capabilities of this classifier.
        Specified by:
        getCapabilities in interface weka.core.CapabilitiesHandler
        Specified by:
        getCapabilities in interface weka.classifiers.Classifier
        Overrides:
        getCapabilities in class weka.classifiers.AbstractClassifier
        Returns:
        the capabilities of this object
      • buildClassifier

        public void buildClassifier​(weka.core.Instances data)
                             throws Exception
        Generates a classifier.
        Parameters:
        data - set of instances serving as training data
        Throws:
        Exception - if the classifier has not been generated successfully
      • classifyInstance

        public double classifyInstance​(weka.core.Instance instance)
                                throws Exception
        Generates a classification for the instance.
        Specified by:
        classifyInstance in interface weka.classifiers.Classifier
        Overrides:
        classifyInstance in class weka.classifiers.AbstractClassifier
        Parameters:
        instance - the instance to classify
        Returns:
        the classification
        Throws:
        Exception - if classification failed
      • distributionForInstance

        public double[] distributionForInstance​(weka.core.Instance instance)
                                         throws Exception
        Generates a class distribution for the instance.
        Specified by:
        distributionForInstance in interface weka.classifiers.Classifier
        Overrides:
        distributionForInstance in class weka.classifiers.AbstractClassifier
        Parameters:
        instance - the instance to get the class distribution for
        Returns:
        the class distribution
        Throws:
        Exception - if class distribution fails
      • toString

        public String toString()
        Just returns the commandline options.
        Overrides:
        toString in class Object
        Returns:
        the commandline options