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

📄 findwithcapabilities.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	m_Packages.add(tok.nextToken());    }        if (Utils.getFlag("generic", options)) {      creator    = new GenericPropertiesCreator();      creator.execute(false);      props	 = creator.getInputProperties();      tok        = new StringTokenizer(props.getProperty(m_Superclass), ",");      m_Packages = new Vector();      while (tok.hasMoreTokens())	m_Packages.add(tok.nextToken());    }  }    /**   * Gets the current settings of this object.   *    * @return an array of strings suitable for passing to setOptions   */  public String[] getOptions() {    Vector 	result;    String[]	options;    int		i;    result = new Vector();        result.add("-num-instances");    result.add("" + m_Capabilities.getMinimumNumberInstances());        if (m_Capabilities.handles(Capability.NO_CLASS)) {      result.add("-no-class");    }    else {      if (m_Capabilities.handles(Capability.NOMINAL_CLASS))	result.add("-nominal-class");      if (m_Capabilities.handles(Capability.BINARY_CLASS))	result.add("-binary-class");      if (m_Capabilities.handles(Capability.NUMERIC_CLASS))	result.add("-numeric-class");      if (m_Capabilities.handles(Capability.STRING_CLASS))	result.add("-string-class");      if (m_Capabilities.handles(Capability.DATE_CLASS))	result.add("-date-class");      if (m_Capabilities.handles(Capability.RELATIONAL_CLASS))	result.add("-relational-class");    }        if (m_Capabilities.handles(Capability.NOMINAL_ATTRIBUTES))	result.add("-nominal-atts");    if (m_Capabilities.handles(Capability.BINARY_ATTRIBUTES))	result.add("-binary-atts");    if (m_Capabilities.handles(Capability.NUMERIC_ATTRIBUTES))	result.add("-numeric-atts");    if (m_Capabilities.handles(Capability.STRING_ATTRIBUTES))	result.add("-string-atts");    if (m_Capabilities.handles(Capability.DATE_ATTRIBUTES))	result.add("-date-atts");    if (m_Capabilities.handles(Capability.RELATIONAL_ATTRIBUTES))	result.add("-relational-atts");    if (m_Capabilities.handles(Capability.ONLY_MULTIINSTANCE))      result.add("-only-multiinstance");    if (getHandler() != null) {      result.add("-W");      result.add(getHandler().getClass().getName());      if (getHandler() instanceof OptionHandler) {	result.add("--");	options = ((OptionHandler) getHandler()).getOptions();	for (i = 0; i < options.length; i++)	  result.add(options[i]);      }    }    else if (getFilename().length() != 0) {      result.add("-t");      result.add(getFilename());      result.add("-c");      result.add(m_ClassIndex.getSingleIndex());    }    if (m_Superclass.length() != 0) {      result.add("-superclass");      result.add(m_Superclass);    }    else {      result.add("-packages");      result.add(m_Packages.toString().replaceAll("\\[", "").replaceAll("\\]", ""));    }        return (String[]) result.toArray(new String[result.size()]);  }    /**   * sets the Capabilities handler to generate the data for   */  public void setHandler(CapabilitiesHandler value) {    m_Handler = value;    setCapabilities(m_Handler.getCapabilities());  }    /**   * returns the current set CapabilitiesHandler to generate the dataset   * for, can be null   */  public CapabilitiesHandler getHandler() {    return m_Handler;  }    /**   * Sets the dataset filename to base the capabilities on. It immediately   * loads the dataset and retrieves the capabilities from it.   */  public void setFilename(String value) {    Instances		insts;        m_Filename = value;    if (m_Filename.length() != 0) {      try {        insts  = new Instances(new BufferedReader(new FileReader(m_Filename)));        m_ClassIndex.setUpper(insts.numAttributes());        insts.setClassIndex(Integer.parseInt(getClassIndex()) - 1);                setCapabilities(Capabilities.forInstances(insts));      }      catch (Exception e) {	e.printStackTrace();      }    }  }    /**   * returns the current filename for the dataset to base the capabilities on   */  public String getFilename() {    return m_Filename;  }    /**   * sets the class index, -1 for none, first and last are also valid   */  public void setClassIndex(String value) {    if (value.equals("-1"))      m_ClassIndex = null;    else      m_ClassIndex = new SingleIndex(value);  }    /**   * returns the current current class index, -1 if no class attribute   */  public String getClassIndex() {    if (m_ClassIndex == null)      return "-1";    else      return "" + m_ClassIndex.getIndex();  }  /**   * enables the given capability   *    * @param c		the capability to enable   */  public void enable(Capability c) {    m_Capabilities.enable(c);  }  /**   * disables the given capability   *    * @param c		the capability to disable   */  public void disable(Capability c) {    m_Capabilities.disable(c);  }  /**   * returns true if the given capability can be handled   *    * @param c		the capability to check   * @return		true if the capability can be handled   */  public boolean handles(Capability c) {    return m_Capabilities.handles(c);  }    /**   * The capabilities to search for.   *   * @return            the capabilities to search for   * @see               Capabilities   */  public Capabilities getCapabilities() {    return m_Capabilities;  }    /**   * Uses the given Capabilities for the search.   *    * @param c		the capabilities to use for the search   */  public void setCapabilities(Capabilities c) {    m_Capabilities = (Capabilities) c.clone();  }  /**   * returns the matches from the last find call   *    * @return		the matching classname from the last find run   */  public Vector getMatches() {    return m_Matches;  }  /**   * returns the misses from the last find call   *    * @return		the classnames that didn't match from the last find run   */  public Vector getMisses() {    return m_Misses;  }    /**   * returns a list with all the classnames that fit the criteria   *    * @return		contains all classnames that fit the criteria   */  public Vector find() {    Vector		list;    int			i;    Class		cls;    Object		obj;    CapabilitiesHandler	handler;    boolean		fits;    Capabilities	caps;        m_Matches = new Vector();    m_Misses  = new Vector();    list = ClassDiscovery.find(m_Superclass, (String[]) m_Packages.toArray(new String[m_Packages.size()]));    for (i = 0; i < list.size(); i++) {      try {	cls = Class.forName((String) list.get(i));	obj = cls.newInstance();		// exclude itself	if (cls == this.getClass())	  continue;		// really a CapabilitiesHandler?	if (!(obj instanceof CapabilitiesHandler))	  continue;	// check capabilities enumeration	handler = (CapabilitiesHandler) obj;	caps    = handler.getCapabilities();	fits    = true;	for (Capability cap: Capability.values()) {	  if (m_Capabilities.handles(cap)) {	    if (!(caps.handles(cap))) {	      fits = false;	      break;	    }	  }	}	if (!fits) {	  m_Misses.add(list.get(i));	  continue;	}		// other stuff	if (caps.getMinimumNumberInstances() > m_Capabilities.getMinimumNumberInstances()) {	  m_Misses.add(list.get(i));	  continue;	}		// matches all criteria!	m_Matches.add(list.get(i));      }      catch (Exception e) {	// ignore      }    }        return m_Matches;  }  /**   * Executes the location of classes with parameters from the commandline.   *    * @param args	the commandline parameters   */  public static void main(String[] args) {    FindWithCapabilities 	find;    Vector 			list;    String			result;    int				i;    boolean			printMisses;        printMisses = false;        try {      find = new FindWithCapabilities();            try {	printMisses = Utils.getFlag("misses", args);        find.setOptions(args);        Utils.checkForRemainingOptions(args);      }       catch (Exception ex) {        result = ex.getMessage() + "\n\n" + find.getClass().getName().replaceAll(".*\\.", "") + " Options:\n\n";        Enumeration enm = find.listOptions();        while (enm.hasMoreElements()) {          Option option = (Option) enm.nextElement();          result += option.synopsis() + "\n" + option.description() + "\n";        }        throw new Exception(result);      }            System.out.println("\nSearching for the following Capabilities:\n\n" + find.getCapabilities());            find.find();      // matches      list = find.getMatches();      if (list.size() == 1)	System.out.println("\nFound " + list.size() + " class that matched the criteria:\n");      else	System.out.println("\nFound " + list.size() + " classes that matched the criteria:\n");      for (i = 0; i < list.size(); i++)	System.out.println(list.get(i));            // misses      if (printMisses) {        list = find.getMisses();        if (list.size() == 1)  	System.out.println("\nFound " + list.size() + " class that didn't match the criteria:\n");        else  	System.out.println("\nFound " + list.size() + " classes that didn't match the criteria:\n");        for (i = 0; i < list.size(); i++)  	System.out.println(list.get(i));      }    }     catch (Exception ex) {      System.err.println(ex.getMessage());    }  }}

⌨️ 快捷键说明

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