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

📄 findwithcapabilities.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *    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. *//* * FindWithCapabilities.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand */package weka.core;import weka.core.Capabilities.Capability;import weka.gui.GenericPropertiesCreator;import java.io.BufferedReader;import java.io.FileReader;import java.util.Enumeration;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;/** * Locates all classes with certain capabilities. <p/> *  <!-- options-start --> * Valid options are: <p/> *  * <pre> -num-instances &lt;num&gt; *  The minimum number of instances (default 1).</pre> *  * <pre> -nominal-class *  Must handle nominal classes.</pre> *  * <pre> -binary-class *  Must handle binary classes.</pre> *  * <pre> -numeric-class *  Must handle numeric classes.</pre> *  * <pre> -string-class *  Must handle string classes.</pre> *  * <pre> -date-class *  Must handle date classes.</pre> *  * <pre> -relational-class *  Must handle relational classes.</pre> *  * <pre> -no-class *  Doesn't need a class.</pre> *  * <pre> -nominal-atts *  Must handle nominal attributes.</pre> *  * <pre> -numeric-atts *  Must handle numeric attributes.</pre> *  * <pre> -string-atts *  Must handle string attributes.</pre> *  * <pre> -date-atts *  Must handle date attributes.</pre> *  * <pre> -relational-atts *  Must handle relational attributes.</pre> *  * <pre> -only-multiinstance *  Must handle multi-instance data.</pre> *  * <pre> -W &lt;classname&gt; *  The Capabilities handler to base the handling on. *  The other parameters can be used to override the ones *  determined from the handler. Additional parameters for *  handler can be passed on after the '--'. *  Either '-W' or '-t' can be used.</pre> *  * <pre> -t &lt;file&gt; *  The dataset to base the capabilities on. *  The other parameters can be used to override the ones *  determined from the handler. *  Either '-t' or '-W' can be used.</pre> *  * <pre> -c &lt;num&gt; *  The index of the class attribute, -1 for none. *  'first' and 'last' are also valid. *  Only in conjunction with option '-t'.</pre> *  * <pre> -superclass *  Superclass to look for in the packages. * </pre> *  * <pre> -packages *  Comma-separated list of packages to search in.</pre> *  * <pre> -generic *  Retrieves the package list from the GenericPropertiesCreator *  for the given superclass. (overrides -packages &lt;list&gt;).</pre> *  * <pre> -misses *  Also prints the classname that didn't match the criteria.</pre> *  <!-- options-end --> *  * @author  fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.2 $ * @see Capabilities * @see Capabilities.Capability * @see GenericPropertiesCreator */public class FindWithCapabilities   implements OptionHandler, CapabilitiesHandler {  /** the capabilities to look for */  protected Capabilities m_Capabilities = new Capabilities(this);  /** the packages to search in */  protected Vector m_Packages = new Vector();  /** a capabilities handler to retrieve the capabilities from */  protected CapabilitiesHandler m_Handler = null;  /** a file the capabilities can be based on */  protected String m_Filename = "";    /** the class index, in case the capabilities are based on a file */  protected SingleIndex m_ClassIndex = new SingleIndex();    /** the superclass from the GenericPropertiesCreator to retrieve the packages from */  protected String m_Superclass = "";    /** whether to use the GenericPropertiesCreator with the superclass */  protected boolean m_GenericPropertiesCreator = false;    /** the classes that matched */  protected Vector m_Matches = new Vector();    /** the class that didn't match */  protected Vector m_Misses = new Vector();    /**   * Returns an enumeration describing the available options.   *   * @return an enumeration of all the available options.   */  public Enumeration listOptions() {    Vector result = new Vector();        result.addElement(new Option(        "\tThe minimum number of instances (default 1).",        "num-instances", 1, "-num-instances <num>"));        result.addElement(new Option(        "\tMust handle nominal classes.",        "nominal-class", 0, "-nominal-class"));        result.addElement(new Option(        "\tMust handle binary classes.",        "binary-class", 0, "-binary-class"));        result.addElement(new Option(        "\tMust handle numeric classes.",        "numeric-class", 0, "-numeric-class"));        result.addElement(new Option(        "\tMust handle string classes.",        "string-class", 0, "-string-class"));        result.addElement(new Option(        "\tMust handle date classes.",        "date-class", 0, "-date-class"));        result.addElement(new Option(        "\tMust handle relational classes.",        "relational-class", 0, "-relational-class"));        result.addElement(new Option(        "\tDoesn't need a class.",        "no-class", 0, "-no-class"));    result.addElement(new Option(        "\tMust handle nominal attributes.",        "nominal-atts", 0, "-nominal-atts"));        result.addElement(new Option(        "\tMust handle numeric attributes.",        "numeric-atts", 0, "-numeric-atts"));        result.addElement(new Option(        "\tMust handle string attributes.",        "string-atts", 0, "-string-atts"));        result.addElement(new Option(        "\tMust handle date attributes.",        "date-atts", 0, "-date-atts"));        result.addElement(new Option(        "\tMust handle relational attributes.",        "relational-atts", 0, "-relational-atts"));        result.addElement(new Option(        "\tMust handle multi-instance data.",        "only-multiinstance", 0, "-only-multiinstance"));    result.addElement(new Option(        "\tThe Capabilities handler to base the handling on.\n"	+ "\tThe other parameters can be used to override the ones\n"	+ "\tdetermined from the handler. Additional parameters for\n"	+ "\thandler can be passed on after the '--'.\n"	+ "\tEither '-W' or '-t' can be used.",        "W", 1, "-W <classname>"));        result.addElement(new Option(        "\tThe dataset to base the capabilities on.\n"	+ "\tThe other parameters can be used to override the ones\n"	+ "\tdetermined from the handler.\n"	+ "\tEither '-t' or '-W' can be used.",        "t", 1, "-t <file>"));        result.addElement(new Option(        "\tThe index of the class attribute, -1 for none.\n"	+ "\t'first' and 'last' are also valid.\n"	+ "\tOnly in conjunction with option '-t'.",        "c", 1, "-c <num>"));        result.addElement(new Option(        "\tSuperclass to look for in the packages.\n",        "superclass", 1, "-superclass"));    result.addElement(new Option(        "\tComma-separated list of packages to search in.",        "packages", 1, "-packages"));    result.addElement(new Option(	  "\tRetrieves the package list from the GenericPropertiesCreator\n"	+ "\tfor the given superclass. (overrides -packages <list>).",        "generic", 1, "-generic"));    result.addElement(new Option(        "\tAlso prints the classname that didn't match the criteria.",        "misses", 0, "-misses"));        return result.elements();  }    /**   * Parses a given list of options.    *   * @param options the list of options as an array of strings   * @throws Exception if an option is not supported   */  public void setOptions(String[] options) throws Exception {    String      		tmpStr;    Class			cls;    CapabilitiesHandler		handler;    boolean			initialized;    StringTokenizer		tok;    GenericPropertiesCreator	creator;    Properties			props;    m_Capabilities = new Capabilities(this);    initialized    = false;        tmpStr = Utils.getOption('W', options);    if (tmpStr.length() != 0) {      cls = Class.forName(tmpStr);      if (ClassDiscovery.hasInterface(CapabilitiesHandler.class, cls)) {	initialized = true;	handler = (CapabilitiesHandler) cls.newInstance();	if (handler instanceof OptionHandler)	  ((OptionHandler) handler).setOptions(Utils.partitionOptions(options));	setHandler(handler);      }      else {	throw new IllegalArgumentException("Class '" + tmpStr + "' is not a CapabilitiesHandler!");      }    }    else {      tmpStr = Utils.getOption('c', options);      if (tmpStr.length() != 0)	setClassIndex(tmpStr);      else	setClassIndex("last");      tmpStr = Utils.getOption('t', options);      setFilename(tmpStr);    }    tmpStr = Utils.getOption("num-instances", options);    if (tmpStr.length() != 0)      m_Capabilities.setMinimumNumberInstances(Integer.parseInt(tmpStr));    else if (!initialized)      m_Capabilities.setMinimumNumberInstances(1);        if (Utils.getFlag("no-class", options))      enable(Capability.NO_CLASS);        if (!m_Capabilities.handles(Capability.NO_CLASS)) {      if (Utils.getFlag("nominal-class", options))	 enable(Capability.NOMINAL_CLASS);      if (Utils.getFlag("binary-class", options))	 enable(Capability.BINARY_CLASS);      if (Utils.getFlag("numeric-class", options))	 enable(Capability.NUMERIC_CLASS);      if (Utils.getFlag("string-class", options))	 enable(Capability.STRING_CLASS);      if (Utils.getFlag("date-class", options))	 enable(Capability.DATE_CLASS);      if (Utils.getFlag("relational-class", options))	 enable(Capability.RELATIONAL_CLASS);    }        if (Utils.getFlag("nominal-atts", options))      enable(Capability.NOMINAL_ATTRIBUTES);    if (Utils.getFlag("binary-atts", options))      enable(Capability.BINARY_ATTRIBUTES);    if (Utils.getFlag("numeric-atts", options))      enable(Capability.NUMERIC_ATTRIBUTES);    if (Utils.getFlag("string-atts", options))      enable(Capability.STRING_ATTRIBUTES);    if (Utils.getFlag("date-atts", options))      enable(Capability.DATE_ATTRIBUTES);    if (Utils.getFlag("relational-atts", options))      enable(Capability.RELATIONAL_ATTRIBUTES);        if (Utils.getFlag("only-multiinstance", options))      enable(Capability.ONLY_MULTIINSTANCE);        tmpStr = Utils.getOption("superclass", options);    if (tmpStr.length() != 0)      m_Superclass = tmpStr;    else      throw new IllegalArgumentException("A superclass has to be specified!");        tmpStr = Utils.getOption("packages", options);    if (tmpStr.length() != 0) {      tok        = new StringTokenizer(tmpStr, ",");      m_Packages = new Vector();      while (tok.hasMoreTokens())

⌨️ 快捷键说明

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