package weka.clusterers; import java.util.Enumeration; import java.util.Vector; import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List; import weka.core.Instance; import weka.core.Instances; import weka.core.Option; import weka.core.OptionHandler; import weka.core.Utils; public class EcjBasedClusterer extends AbstractClusterer implements OptionHandler { private static final long serialVersionUID = -5129098585519877366L; private String parameterFilePath = ""; private String checkpointFilePath = ""; private int numCluster = 1; /** * Generates a clusterer. Has to initialize all fields of the clusterer that * are not being set via options. * * @param data * set of instances serving as training data * @exception Exception * if the clusterer has not been generated successfully */ @Override public void buildClusterer(Instances data) throws Exception { numCluster = 1; } /** * Returns the number of clusters. * * @return the number of clusters generated for a training dataset. * @exception Exception * if number of clusters could not be returned successfully */ @Override public int numberOfClusters() throws Exception { return numCluster; } /** * Classifies a given instance. Either this or distributionForInstance() * needs to be implemented by subclasses. * * @param instance * the instance to be assigned to a cluster * @return the number of the assigned cluster as an integer * @exception Exception * if instance could not be clustered successfully */ public int clusterInstance(Instance instance) throws Exception { return 0; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector newVector = new Vector(); newVector .addElement(new Option( "\tSpecify the path of the properties file to load ecj parameters\n", "F", 1, "-F ")); newVector.addElement(new Option( "\tSpecify the path of the checkpoint file to load ecj algorithm from." + "If specified, it overrides the -F option.\n", "C", 1, "-C ")); return newVector.elements(); } /** * Parses a given list of options. Valid options are: *
     * -F "FilePath"
     * Set the path to the ecj parameters file.
     * 
     * -C "FilePath"
     * Set the path to the ecj checkpoint file, overrides the -F option.
     * 
     * 
     * @param options
     *            the list of options as an array of strings
     * @exception Exception
     *                if an option is not supported
     */
    public void setOptions(String[] options) throws Exception {

        String optionString = Utils.getOption('F', options);
        if (optionString.length() != 0) {
            parameterFilePath = optionString;
        }
        optionString = Utils.getOption('C', options);
        if (optionString.length() != 0) {
            checkpointFilePath = optionString;
        }
    }

    /**
     * Gets the current settings of the Classifier.
     * 
     * @return an array of strings suitable for passing to setOptions
     */
    public String[] getOptions() {
        if (checkpointFilePath != null && checkpointFilePath.length() != 0) {
            String[] options = new String[2];
            options[0] = "-C";
            options[1] = checkpointFilePath;
            return options;
        }
        
        if (parameterFilePath != null && parameterFilePath.length() != 0) {
            String[] options = new String[2];
            options[0] = "-F";
            options[1] = parameterFilePath;
            return options;
        } else {
            String[] opt = new String[1];
            opt[0] = "";
            return opt;
        }
    }
    
    public String parameterFilePathTipText() {
        return "The parameters file from which loading the agorithm.";
    }
    
    public String checkpointFilePathTipText() {
        return "The checkpoint file from which resuming the algorithm. Override the " +
                "parameters file.";
    }
    
//    public void setParameterFilePath(String newPath) {
//        this.parameterFilePath = newPath;
//    }
//    
//    public void setCheckpointFilePath(String newPath) {
//        this.checkpointFilePath = newPath;
//    }
    
    public String getParameterFilePath() {
        return this.parameterFilePath;
    }
    
    public String getCheckpointFilePath() {
        return this.checkpointFilePath;
    }
    
}