Exemple #1
0
  /**
   * Set the clusterer for this wrapper
   *
   * @param c a <code>weka.clusterers.Clusterer</code> value
   */
  public void setClusterer(weka.clusterers.Clusterer c) {
    boolean loadImages = true;
    if (c.getClass().getName().compareTo(m_Clusterer.getClass().getName()) == 0) {
      loadImages = false;
    } else {
      // clusterer has changed so any batch training status is now
      // invalid
      m_trainingSet = null;
    }
    m_Clusterer = c;
    String clustererName = c.getClass().toString();
    clustererName =
        clustererName.substring(clustererName.lastIndexOf('.') + 1, clustererName.length());
    if (loadImages) {
      if (!m_visual.loadIcons(
          BeanVisual.ICON_PATH + clustererName + ".gif",
          BeanVisual.ICON_PATH + clustererName + "_animated.gif")) {
        useDefaultVisual();
      }
    }
    m_visual.setText(clustererName);

    // get global info
    m_globalInfo = KnowledgeFlowApp.getGlobalInfo(m_Clusterer);
  }
 @Override
 public void useDefaultVisual() {
   m_visual.loadIcons(
       BeanVisual.ICON_PATH + "FlowByExpression.png",
       BeanVisual.ICON_PATH + "FlowByExpression.png");
   m_visual.setText("FlowByExpression");
 }
Exemple #3
0
  /** Stop any clusterer action */
  public void stop() {
    // tell all listenees (upstream beans) to stop
    Enumeration en = m_listenees.keys();
    while (en.hasMoreElements()) {
      Object tempO = m_listenees.get(en.nextElement());
      if (tempO instanceof BeanCommon) {
        System.err.println("Listener is BeanCommon");
        ((BeanCommon) tempO).stop();
      }
    }

    // stop the build thread
    if (m_buildThread != null) {
      m_buildThread.interrupt();
      m_buildThread.stop();
      m_buildThread = null;
      m_visual.setStatic();
    }
  }
 @Override
 public String getCustomName() {
   return m_visual.getText();
 }
 @Override
 public void setCustomName(String name) {
   m_visual.setText(name);
 }
 /** Use the default images for a data source */
 public void useDefaultVisual() {
   m_visual.loadIcons(
       BeanVisual.ICON_PATH + "DefaultDataSource.gif",
       BeanVisual.ICON_PATH + "DefaultDataSource_animated.gif");
 }
Exemple #7
0
 /** Use the default visual representation */
 @Override
 public void useDefaultVisual() {
   m_visual.loadIcons(
       BeanVisual.ICON_PATH + "Sorter.gif", BeanVisual.ICON_PATH + "Sorter_animated.gif");
   m_visual.setText("Sorter");
 }
Exemple #8
0
 /** Use the default visual appearance for this bean */
 public void useDefaultVisual() {
   m_visual.loadIcons(
       BeanVisual.ICON_PATH + "DefaultClusterer.gif",
       BeanVisual.ICON_PATH + "DefaultClusterer_animated.gif");
 }
Exemple #9
0
  /**
   * Accepts a training set and builds batch clusterer
   *
   * @param e a <code>TrainingSetEvent</code> value
   */
  public void acceptTrainingSet(final TrainingSetEvent e) {
    if (e.isStructureOnly()) {
      // no need to build a clusterer, instead just generate a dummy
      // BatchClustererEvent in order to pass on instance structure to
      // any listeners
      BatchClustererEvent ce =
          new BatchClustererEvent(
              this,
              m_Clusterer,
              new DataSetEvent(this, e.getTrainingSet()),
              e.getSetNumber(),
              e.getMaxSetNumber(),
              1);

      notifyBatchClustererListeners(ce);
      return;
    }
    if (m_buildThread == null) {
      try {
        if (m_state == IDLE) {
          synchronized (this) {
            m_state = BUILDING_MODEL;
          }
          m_trainingSet = e.getTrainingSet();
          final String oldText = m_visual.getText();
          m_buildThread =
              new Thread() {
                public void run() {
                  try {
                    if (m_trainingSet != null) {
                      m_visual.setAnimated();
                      m_visual.setText("Building clusters...");
                      if (m_log != null) {
                        m_log.statusMessage("Clusterer : building clusters...");
                      }
                      buildClusterer();
                      if (m_batchClustererListeners.size() > 0) {
                        BatchClustererEvent ce =
                            new BatchClustererEvent(
                                this,
                                m_Clusterer,
                                new DataSetEvent(this, e.getTrainingSet()),
                                e.getSetNumber(),
                                e.getMaxSetNumber(),
                                1);
                        notifyBatchClustererListeners(ce);
                      }
                      if (m_Clusterer instanceof weka.core.Drawable
                          && m_graphListeners.size() > 0) {
                        String grphString = ((weka.core.Drawable) m_Clusterer).graph();
                        int grphType = ((weka.core.Drawable) m_Clusterer).graphType();
                        String grphTitle = m_Clusterer.getClass().getName();
                        grphTitle =
                            grphTitle.substring(grphTitle.lastIndexOf('.') + 1, grphTitle.length());
                        grphTitle =
                            "Set "
                                + e.getSetNumber()
                                + " ("
                                + e.getTrainingSet().relationName()
                                + ") "
                                + grphTitle;

                        GraphEvent ge =
                            new GraphEvent(Clusterer.this, grphString, grphTitle, grphType);
                        notifyGraphListeners(ge);
                      }

                      if (m_textListeners.size() > 0) {
                        String modelString = m_Clusterer.toString();
                        String titleString = m_Clusterer.getClass().getName();

                        titleString =
                            titleString.substring(
                                titleString.lastIndexOf('.') + 1, titleString.length());
                        modelString =
                            "=== Clusterer model ===\n\n"
                                + "Scheme:   "
                                + titleString
                                + "\n"
                                + "Relation: "
                                + m_trainingSet.relationName()
                                + ((e.getMaxSetNumber() > 1)
                                    ? "\nTraining Fold: " + e.getSetNumber()
                                    : "")
                                + "\n\n"
                                + modelString;
                        titleString = "Model: " + titleString;

                        TextEvent nt = new TextEvent(Clusterer.this, modelString, titleString);
                        notifyTextListeners(nt);
                      }
                    }
                  } catch (Exception ex) {
                    ex.printStackTrace();
                  } finally {
                    m_visual.setText(oldText);
                    m_visual.setStatic();
                    m_state = IDLE;
                    if (isInterrupted()) {
                      // prevent any clusterer events from being fired
                      m_trainingSet = null;
                      if (m_log != null) {
                        m_log.logMessage("Build clusterer interrupted!");
                        m_log.statusMessage("OK");
                      }
                    } else {
                      // save header
                      m_trainingSet = new Instances(m_trainingSet, 0);
                    }
                    if (m_log != null) {
                      m_log.statusMessage("OK");
                    }
                    block(false);
                  }
                }
              };
          m_buildThread.setPriority(Thread.MIN_PRIORITY);
          m_buildThread.start();
          // make sure the thread is still running before we block
          //	  if (m_buildThread.isAlive()) {
          block(true);
          //	  }
          m_buildThread = null;
          m_state = IDLE;
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }