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

📄 generator.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *    Generator.java
 *    Copyright (C) 2000 Gabi Schmidberger
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package weka.datagenerators;

import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Enumeration;

import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.Utils;

/** 
 * Abstract class for data generators.
 *
 * ------------------------------------------------------------------- <p>
 *
 * General options are: <p>
 *
 * -r string <br>
 * Name of the relation of the generated dataset. <br>
 * (default = name built using name of used generator and options) <p>
 *
 * -a num <br>
 * Number of attributes. (default = 10) <p>
 *
 * -c num <br>
 * Number of classes. (default = 2) <p>
 *
 * -n num <br>
 * Number of examples. (default = 100) <p>
 *
 * -o filename<br>
 * writes the generated dataset to the given file using ARFF-Format.
 * (default = stdout).
 * 
 * ------------------------------------------------------------------- <p>
 *
 * Example usage as the main of a datagenerator called RandomGenerator:
 * <code> <pre>
 * public static void main(String [] args) {
 *   try {
 *     DataGenerator.makeData(new RandomGenerator(), argv);
 *   } catch (Exception e) {
 *     System.err.println(e.getMessage());
 *   }
 * }
 * </pre> </code> 
 * <p>
 *
 * ------------------------------------------------------------------ <p>
 *
 *
 * @author Gabi Schmidberger (gabi@cs.waikato.ac.nz)
 * @version $Revision$
 */
public abstract class Generator implements Serializable {

  /** @serial Debugging mode */
  private boolean m_Debug = false;

  /** @serial The format for the generated dataset */
  private Instances m_Format = null;

  /** @serial Relation name the dataset should have */
  private String m_RelationName = "";

  /** @serial Number of attribute the dataset should have */
  private int m_NumAttributes = 10;

  /** @serial Number of Classes the dataset should have */
  private int m_NumClasses = 2;

  /** @serial Number of instances*/
  private int m_NumExamples = 100;

  /** @serial Number of instances that should be produced into the dataset 
    * this number is by default m_NumExamples,
    * but can be reset by the generator 
    */
   private int m_NumExamplesAct = 0;

  /** @serial PrintWriter */
  private PrintWriter m_Output = null;


  /**
   * Initializes the format for the dataset produced. 
   * Must be called before the generateExample or generateExamples
   * methods are used.
   *
   * @return the format for the dataset 
   * @exception Exception if the generating of the format failed
   */

  abstract Instances defineDataFormat() throws Exception; 

  /**
   * Generates one example of the dataset. 
   *
   * @return the generated example
   * @exception Exception if the format of the dataset is not yet defined
   * @exception Exception if the generator only works with generateExamples
   * which means in non single mode
   */

  abstract Instance generateExample() throws Exception;

  /**
   * Generates all examples of the dataset. 
   *
   * @return the generated dataset
   * @exception Exception if the format of the dataset is not yet defined
   * @exception Exception if the generator only works with generateExample,
   * which means in single mode
   */

  abstract Instances generateExamples() throws Exception;

  /**
   * Generates a comment string that documentats the data generator.
   * By default this string is added at the end of theproduces output
   * as ARFF file type.
   * 
   * @return string contains info about the generated rules
   * @exception Exception if the generating of the documentaion fails
   */
  abstract String generateFinished () throws Exception;


  /**
   * Return if single mode is set for the given data generator
   * mode depends on option setting and or generator type.
   * 
   * @return single mode flag
   * @exception Exception if mode is not set yet
   */
  abstract boolean getSingleModeFlag () throws Exception;


  /**
   * Sets the debug flag.
   * @param debug the new debug flag
   */
  public void setDebug(boolean debug) { 
    m_Debug = debug;
  }

  /**
   * Gets the debug flag.
   * @return the debug flag 
   */
  public boolean getDebug() { return m_Debug; }

  /**
   * Sets the relation name the dataset should have.
   * @param relationName the new relation name
   */
  public void setRelationName(String relationName) {
    if (relationName.length() == 0) {
      // build relationname 
      StringBuffer name = new StringBuffer(this.getClass().getName());
      String [] options = getGenericOptions();
      for (int i = 0; i < options.length; i++) {
	name = name.append(options[i].trim());
      }

      if (this instanceof OptionHandler) {
        options = ((OptionHandler)this).getOptions();
        for (int i = 0; i < options.length; i++) {
	  name = name.append(options[i].trim());
        }
      }
      m_RelationName = name.toString();
    } 
    else
      m_RelationName = relationName;
  }

  /**
   * Gets the relation name the dataset should have.
   * @return the relation name the dataset should have
   */
  public String getRelationName() { return m_RelationName; }

  /**
   * Sets the number of classes the dataset should have.
   * @param numClasses the new number of classes
   */
  public void setNumClasses(int numClasses) { m_NumClasses = numClasses; }

  /**
   * Gets the number of classes the dataset should have.
   * @return the number of classes the dataset should have
   */
  public int getNumClasses() { return m_NumClasses; }

  /**
   * Sets the number of examples, given by option.
   * @param numExamples the new number of examples
   */
  public void setNumExamples(int numExamples) { m_NumExamples = numExamples; }

  /**
   * Gets the number of examples, given by option.
   * @return the number of examples, given by option 
   */
  public int getNumExamples() { return m_NumExamples; }

  /**
   * Sets the number of attributes the dataset should have.
   * @param numAttributes the new number of attributes
   */
  public void setNumAttributes(int numAttributes) {
    m_NumAttributes = numAttributes;
  }

  /**
   * Gets the number of attributes that should be produced.
   * @return the number of attributes that should be produced
   */
  public int getNumAttributes() { return m_NumAttributes; }

  /**
   * Sets the number of examples the dataset should have.
   * @param numExamplesAct the new number of examples
   */
  public void setNumExamplesAct(int numExamplesAct) { 
    m_NumExamplesAct = numExamplesAct;
  }

  /**
   * Gets the number of examples the dataset should have.
   * @return the number of examples the dataset should have

⌨️ 快捷键说明

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