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

📄 capabilities.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   */  public void enable(Capability c) {    if (c == Capability.NOMINAL_ATTRIBUTES) {      enable(Capability.BINARY_ATTRIBUTES);    }    else if (c == Capability.NOMINAL_CLASS) {      enable(Capability.BINARY_CLASS);    }    m_Capabilities.add(c);  }    /**   * enables the dependency flag for the given capability   *   * @param c     the capability to enable the dependency flag for   */  public void enableDependency(Capability c) {    if (c == Capability.NOMINAL_ATTRIBUTES) {      enableDependency(Capability.BINARY_ATTRIBUTES);    }    else if (c == Capability.NOMINAL_CLASS) {      enableDependency(Capability.BINARY_CLASS);    }    m_Dependencies.add(c);  }    /**   * enables all class types   *    * @see #disableAllClasses()   * @see #getClassCapabilities()   */  public void enableAllClasses() {    for (Capability cap: Capability.values()) {      if (cap.isClass())	enable(cap);    }  }    /**   * enables all class type dependencies   *    * @see #disableAllClassDependencies()   * @see #getClassCapabilities()   */  public void enableAllClassDependencies() {    for (Capability cap: Capability.values()) {      if (cap.isClass())	enableDependency(cap);    }  }    /**   * enables all attribute types   *    * @see #disableAllAttributes()   * @see #getAttributeCapabilities()   */  public void enableAllAttributes() {    for (Capability cap: Capability.values()) {      if (cap.isAttribute())	enable(cap);    }  }    /**   * enables all attribute type dependencies   *    * @see #disableAllAttributeDependencies()   * @see #getAttributeCapabilities()   */  public void enableAllAttributeDependencies() {    for (Capability cap: Capability.values()) {      if (cap.isAttribute())	enableDependency(cap);    }  }  /**   * disables the given capability   *   * @param c     the capability to disable   */  public void disable(Capability c) {    if (c == Capability.NOMINAL_ATTRIBUTES) {      disable(Capability.BINARY_ATTRIBUTES);    }    else if (c == Capability.NOMINAL_CLASS) {      disable(Capability.BINARY_CLASS);    }    m_Capabilities.remove(c);  }  /**   * disables the dependency of the given capability   *   * @param c     the capability to disable the dependency flag for   */  public void disableDependency(Capability c) {    if (c == Capability.NOMINAL_ATTRIBUTES) {      disableDependency(Capability.BINARY_ATTRIBUTES);    }    else if (c == Capability.NOMINAL_CLASS) {      disableDependency(Capability.BINARY_CLASS);    }    m_Dependencies.remove(c);  }    /**   * disables all class types   *    * @see #enableAllClasses()   * @see #getClassCapabilities()   */  public void disableAllClasses() {    for (Capability cap: Capability.values()) {      if (cap.isClass())	disable(cap);    }  }    /**   * disables all class type dependencies   *    * @see #enableAllClassDependencies()   * @see #getClassCapabilities()   */  public void disableAllClassDependencies() {    for (Capability cap: Capability.values()) {      if (cap.isClass())	disableDependency(cap);    }  }    /**   * disables all attribute types   *    * @see #enableAllAttributes()   * @see #getAttributeCapabilities()   */  public void disableAllAttributes() {    for (Capability cap: Capability.values()) {      if (cap.isAttribute())	disable(cap);    }  }    /**   * disables all attribute type dependencies   *    * @see #enableAllAttributeDependencies()   * @see #getAttributeCapabilities()   */  public void disableAllAttributeDependencies() {    for (Capability cap: Capability.values()) {      if (cap.isAttribute())	disableDependency(cap);    }  }    /**   * returns all class capabilities   *    * @return		all capabilities regarding the class   * @see #enableAllClasses()   * @see #disableAllClasses()   */  public Capabilities getClassCapabilities() {    Capabilities	result;        result = new Capabilities(getOwner());        for (Capability cap: Capability.values()) {      if (cap.isClassCapability()) {	if (handles(cap))	  result.enable(cap);      }    }        return result;  }    /**   * returns all attribute capabilities   *    * @return		all capabilities regarding attributes   * @see #enableAllAttributes()   * @see #disableAllAttributes()   */  public Capabilities getAttributeCapabilities() {    Capabilities	result;        result = new Capabilities(getOwner());        for (Capability cap: Capability.values()) {      if (cap.isAttributeCapability()) {	if (handles(cap))	  result.enable(cap);      }    }        return result;  }    /**   * returns all other capabilities, besides class and attribute related ones   *    * @return		all other capabilities, besides class and attribute    * 			related ones   */  public Capabilities getOtherCapabilities() {    Capabilities	result;        result = new Capabilities(getOwner());        for (Capability cap: Capability.values()) {      if (cap.isOtherCapability()) {	if (handles(cap))	  result.enable(cap);      }    }        return result;  }  /**   * returns true if the classifier handler has the specified capability   *   * @param c     the capability to test   * @return      true if the classifier handler has the capability   */  public boolean handles(Capability c) {    return m_Capabilities.contains(c);  }  /**   * returns true if the classifier handler has a dependency for the specified    * capability   *   * @param c     the capability to test   * @return      true if the classifier handler has a dependency for the    *               capability   */  public boolean hasDependency(Capability c) {    return m_Dependencies.contains(c);  }    /**   * Checks whether there are any dependencies at all   *    * @return true if there is at least one dependency for a capability   */  public boolean hasDependencies() {    return (m_Dependencies.size() > 0);  }  /**   * Generates the message for, e.g., an exception. Adds the classname before the   * actual message and returns that string.   *    * @param msg       the actual content of the message, e.g., exception   * @return          the new message   */  protected String createMessage(String msg) {    String	result;        result = "";        if (getOwner() != null)      result = getOwner().getClass().getName();    else      result = "<anonymous>";          result += ": " + msg;        return result;  }    /**   * Test the given attribute, whether it can be processed by the handler,   * given its capabilities. The method assumes that the specified attribute   * is not the class attribute.   *    * @param att		the attribute to test   * @return		true if all the tests succeeded   */  public boolean test(Attribute att) {    return test(att, false);  }    /**   * Test the given attribute, whether it can be processed by the handler,   * given its capabilities.   *    * @param att		the attribute to test   * @param isClass	whether this attribute is the class attribute   * @return		true if all the tests succeeded   */  public boolean test(Attribute att, boolean isClass) {    boolean		result;    Capability		cap;    Capability		capBinary;    String		errorStr;        result = true;    // for exception    if (isClass)      errorStr  = "class";    else      errorStr  = "attributes";        switch (att.type()) {      case Attribute.NOMINAL:	if (isClass) {	  cap       = Capability.NOMINAL_CLASS;	  capBinary = Capability.BINARY_CLASS;	}	else {	  cap       = Capability.NOMINAL_ATTRIBUTES;	  capBinary = Capability.BINARY_ATTRIBUTES;	}	        // all types        if (handles(cap))          break;                // none        if (    !handles(cap)              && !handles(capBinary) ) {          m_FailReason = new UnsupportedAttributeTypeException(                              createMessage("Cannot handle nominal " + errorStr + "!"));          result = false;        }                // binary        if (    handles(capBinary)             && !handles(cap)             && (att.numValues() != 2) ) {          m_FailReason = new UnsupportedAttributeTypeException(                              createMessage("Cannot handle non-binary " + errorStr + "!"));          result = false;        }        break;      case Attribute.NUMERIC:	if (isClass)	  cap = Capability.NUMERIC_CLASS;	else	  cap = Capability.NUMERIC_ATTRIBUTES;	        if (!handles(cap)) {          m_FailReason = new UnsupportedAttributeTypeException(                              createMessage("Cannot handle numeric " + errorStr + "!"));          result = false;        }        break;      case Attribute.DATE:	if (isClass)	  cap = Capability.DATE_CLASS;	else	  cap = Capability.DATE_ATTRIBUTES;	        if (!handles(cap)) {          m_FailReason = new UnsupportedAttributeTypeException(                              createMessage("Cannot handle date " + errorStr + "!"));          result = false;        }        break;      case Attribute.STRING:	if (isClass)	  cap = Capability.STRING_CLASS;	else	  cap = Capability.STRING_ATTRIBUTES;	        if (!handles(cap)) {          m_FailReason = new UnsupportedAttributeTypeException(                              createMessage("Cannot handle string " + errorStr + "!"));          result = false;        }        break;      case Attribute.RELATIONAL:	if (isClass)	  cap = Capability.RELATIONAL_CLASS;	else	  cap = Capability.RELATIONAL_ATTRIBUTES;	        if (!handles(cap)) {          m_FailReason = new UnsupportedAttributeTypeException(                              createMessage("Cannot handle relational " + errorStr + "!"));          result = false;        }        // attributes in the relation of this attribute must be tested        // separately with a different Capabilites object        break;      default:        m_FailReason = new UnsupportedAttributeTypeException(                            createMessage("Cannot handle unknown attribute type '"                                         + att.type() + "'!"));        result = false;    }        return result;  }

⌨️ 快捷键说明

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