00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 package de.picana.clusterer;
00014
00015 import de.picana.control.*;
00016 import de.picana.logging.*;
00017
00018 import weka.core.*;
00019
00020 import java.io.*;
00021
00022
00034 public abstract class Clusterer extends Task {
00035
00037 protected String infile;
00039 protected String modelfile;
00041 protected String statfile;
00043 protected int num_clusters;
00044
00046 protected Instances training_set;
00047
00049 protected PrintWriter statwriter;
00050
00051
00053 public Clusterer() {
00054 }
00055
00056
00057 public void init(ParameterSet params, Logger logger) {
00058
00059 super.init(params, logger);
00060
00061 infile = (String)params.getParameter("training_set");
00062 modelfile = (String)params.getParameter("model");
00063 statfile = (String)params.getParameter("statistics");
00064
00065 num_clusters = 10;
00066 try {
00067 num_clusters = Integer.parseInt((String)params.getParameter("num_clusters"));
00068 } catch (NumberFormatException nfe) {}
00069 }
00070
00071
00072 public void start() throws TaskException {
00073
00074 try {
00075 logger.info(LOGSRC, "Started.");
00076
00077 statwriter = new PrintWriter(new FileOutputStream(new File(statfile), true));
00078
00079 logger.info(LOGSRC, "Read infile '" + infile + "' ...");
00080 File input = new File(infile);
00081 FileInputStream fis = new FileInputStream(input);
00082 InputStreamReader reader = new InputStreamReader(fis);
00083 training_set = new Instances(reader);
00084 logger.info(LOGSRC, "reading '" + infile + "' done.");
00085 logger.info(LOGSRC, "read in " + training_set.numInstances() + " instances.");
00086
00087 logger.info(LOGSRC, "Cluster instances ...");
00088 buildClusterer(training_set);
00089 logger.info(LOGSRC, "clustering done.");
00090
00091 logger.info(LOGSRC, "Write model to '" + modelfile + "' ...");
00092 saveModel(modelfile);
00093 logger.info(LOGSRC, "written model to '" + modelfile + "'.");
00094
00095 statwriter.close();
00096
00097 logger.info(LOGSRC, "Stopped.");
00098
00099 } catch (Exception e) {
00100 throw new TaskException(e.toString());
00101 }
00102
00103 }
00104
00105 public void stop() {
00106
00107 }
00108
00109 public void pause() {
00110
00111 }
00112
00113 public void resume() {
00114
00115 }
00116
00117 public abstract void buildClusterer(Instances set) throws TaskException ;
00118 public abstract void saveModel(String filename) throws TaskException;
00119 }