⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 associationspanel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    String [] attribNames = new String [m_Instances.numAttributes()];    for (int i = 0; i < attribNames.length; i++) {      String type = "";      switch (m_Instances.attribute(i).type()) {      case Attribute.NOMINAL:	type = "(Nom) ";	break;      case Attribute.NUMERIC:	type = "(Num) ";	break;      case Attribute.STRING:	type = "(Str) ";	break;      case Attribute.DATE:	type = "(Dat) ";	break;      case Attribute.RELATIONAL:	type = "(Rel) ";	break;      default:	type = "(???) ";      }      attribNames[i] = type + m_Instances.attribute(i).name();    }    m_StartBut.setEnabled(m_RunThread == null);    m_StopBut.setEnabled(m_RunThread != null);  }    /**   * Starts running the currently configured associator with the current   * settings. This is run in a separate thread, and will only start if   * there is no associator already running. The associator output is sent   * to the results history panel.   */  protected void startAssociator() {    if (m_RunThread == null) {      m_StartBut.setEnabled(false);      m_StopBut.setEnabled(true);      m_RunThread = new Thread() {	public void run() {	  // Copy the current state of things	  m_Log.statusMessage("Setting up...");	  Instances inst = new Instances(m_Instances);	  Associator associator = (Associator) m_AssociatorEditor.getValue();	  StringBuffer outBuff = new StringBuffer();	  String name = (new SimpleDateFormat("HH:mm:ss - "))	  .format(new Date());	  String cname = associator.getClass().getName();	  if (cname.startsWith("weka.associations.")) {	    name += cname.substring("weka.associations.".length());	  } else {	    name += cname;	  }          String cmd = m_AssociatorEditor.getValue().getClass().getName();          if (m_AssociatorEditor.getValue() instanceof OptionHandler)            cmd += " " + Utils.joinOptions(((OptionHandler) m_AssociatorEditor.getValue()).getOptions());	  try {	    // Output some header information	    m_Log.logMessage("Started " + cname);	    m_Log.logMessage("Command: " + cmd);	    if (m_Log instanceof TaskLogger) {	      ((TaskLogger)m_Log).taskStarted();	    }	    outBuff.append("=== Run information ===\n\n");	    outBuff.append("Scheme:       " + cname);	    if (associator instanceof OptionHandler) {	      String [] o = ((OptionHandler) associator).getOptions();	      outBuff.append(" " + Utils.joinOptions(o));	    }	    outBuff.append("\n");	    outBuff.append("Relation:     " + inst.relationName() + '\n');	    outBuff.append("Instances:    " + inst.numInstances() + '\n');	    outBuff.append("Attributes:   " + inst.numAttributes() + '\n');	    if (inst.numAttributes() < 100) {	      for (int i = 0; i < inst.numAttributes(); i++) {		outBuff.append("              " + inst.attribute(i).name()			       + '\n');	      }	    } else {	      outBuff.append("              [list of attributes omitted]\n");	    }	    m_History.addResult(name, outBuff);	    m_History.setSingle(name);	    	    // Build the model and output it.	    m_Log.statusMessage("Building model on training data...");	    associator.buildAssociations(inst);	    outBuff.append("=== Associator model (full training set) ===\n\n");	    outBuff.append(associator.toString() + '\n');	    m_History.updateResult(name);	    m_Log.logMessage("Finished " + cname);	    m_Log.statusMessage("OK");	  } catch (Exception ex) {	    m_Log.logMessage(ex.getMessage());	    m_Log.statusMessage("See error log");	  } finally {	    if (isInterrupted()) {	      m_Log.logMessage("Interrupted " + cname);	      m_Log.statusMessage("See error log");	    }	    m_RunThread = null;	    m_StartBut.setEnabled(true);	    m_StopBut.setEnabled(false);	    if (m_Log instanceof TaskLogger) {	      ((TaskLogger)m_Log).taskFinished();	    }	  }	}      };      m_RunThread.setPriority(Thread.MIN_PRIORITY);      m_RunThread.start();    }  }    /**   * Stops the currently running Associator (if any).   */  protected void stopAssociator() {    if (m_RunThread != null) {      m_RunThread.interrupt();            // This is deprecated (and theoretically the interrupt should do).      m_RunThread.stop();          }  }  /**   * Save the currently selected associator output to a file.   * @param name the name of the buffer to save   */  protected void saveBuffer(String name) {    StringBuffer sb = m_History.getNamedBuffer(name);    if (sb != null) {      if (m_SaveOut.save(sb)) {	m_Log.logMessage("Save successful.");      }    }  }      /**   * Handles constructing a popup menu with visualization options.   * @param name the name of the result history list entry clicked on by   * the user   * @param x the x coordinate for popping up the menu   * @param y the y coordinate for popping up the menu   */  protected void historyRightClickPopup(String name, int x, int y) {    final String selectedName = name;    JPopupMenu resultListMenu = new JPopupMenu();        JMenuItem visMainBuffer = new JMenuItem("View in main window");    if (selectedName != null) {      visMainBuffer.addActionListener(new ActionListener() {	  public void actionPerformed(ActionEvent e) {	    m_History.setSingle(selectedName);	  }	});    } else {      visMainBuffer.setEnabled(false);    }    resultListMenu.add(visMainBuffer);        JMenuItem visSepBuffer = new JMenuItem("View in separate window");    if (selectedName != null) {      visSepBuffer.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  m_History.openFrame(selectedName);	}      });    } else {      visSepBuffer.setEnabled(false);    }    resultListMenu.add(visSepBuffer);        JMenuItem saveOutput = new JMenuItem("Save result buffer");    if (selectedName != null) {      saveOutput.addActionListener(new ActionListener() {	  public void actionPerformed(ActionEvent e) {	    saveBuffer(selectedName);	  }	});    } else {      saveOutput.setEnabled(false);    }    resultListMenu.add(saveOutput);    JMenuItem deleteOutput = new JMenuItem("Delete result buffer");    if (selectedName != null) {      deleteOutput.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  m_History.removeResult(selectedName);	}      });    } else {      deleteOutput.setEnabled(false);    }    resultListMenu.add(deleteOutput);    resultListMenu.show(m_History.getList(), x, y);  }    /**   * updates the capabilities filter of the GOE   *    * @param filter	the new filter to use   */  protected void updateCapabilitiesFilter(Capabilities filter) {    m_AssociatorEditor.setCapabilitiesFilter(filter);  }    /**   * method gets called in case of a change event   *    * @param e		the associated change event   */  public void capabilitiesFilterChanged(CapabilitiesFilterChangeEvent e) {    updateCapabilitiesFilter((Capabilities) e.getFilter().clone());  }  /**   * Tests out the Associator panel from the command line.   *   * @param args may optionally contain the name of a dataset to load.   */  public static void main(String [] args) {    try {      final javax.swing.JFrame jf =	new javax.swing.JFrame("Weka Explorer: Associator");      jf.getContentPane().setLayout(new BorderLayout());      final AssociationsPanel sp = new AssociationsPanel();      jf.getContentPane().add(sp, BorderLayout.CENTER);      weka.gui.LogPanel lp = new weka.gui.LogPanel();      sp.setLog(lp);      jf.getContentPane().add(lp, BorderLayout.SOUTH);      jf.addWindowListener(new java.awt.event.WindowAdapter() {	public void windowClosing(java.awt.event.WindowEvent e) {	  jf.dispose();	  System.exit(0);	}      });      jf.pack();      jf.setVisible(true);      if (args.length == 1) {	System.err.println("Loading instances from " + args[0]);	java.io.Reader r = new java.io.BufferedReader(			   new java.io.FileReader(args[0]));	Instances i = new Instances(r);	sp.setInstances(i);      }    } catch (Exception ex) {      ex.printStackTrace();      System.err.println(ex.getMessage());    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -