Package weka.core
Class Capabilities
java.lang.Object
weka.core.Capabilities
- All Implemented Interfaces:
Serializable
,Cloneable
,RevisionHandler
A class that describes the capabilites (e.g., handling certain types of
attributes, missing values, types of classes, etc.) of a specific classifier.
By default, the classifier is capable of nothing. This ensures that new
features have to be enabled explicitly.
A common code fragment for making use of the capabilities in a classifier
would be this:
public void buildClassifier(Instances instances) throws Exception { // can the classifier handle the data? getCapabilities().testWithFail(instances); ... // possible deletion of instances with missing class labels, etc.For only testing a single attribute, use this:
... Attribute att = instances.attribute(0); getCapabilities().testWithFail(att); ...Or for testing the class attribute (uses the capabilities that are especially for the class):
... Attribute att = instances.classAttribute(); getCapabilities().testWithFail(att, true); ...
- Version:
- $Revision: 14512 $
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
enumeration of all capabilities -
Field Summary
-
Constructor Summary
ConstructorDescriptionCapabilities
(CapabilitiesHandler owner) initializes the capabilities for the given owner -
Method Summary
Modifier and TypeMethodDescriptionaddCapabilities
(String title) generates a string from the capabilities, suitable to add to the help text.void
and
(Capabilities c) performs an AND conjunction with the capabilities of the given Capabilities object and updates itselfvoid
retrieves the data from the given Capabilities objectReturns an Iterator over the stored capabilitiesclone()
Creates and returns a copy of this object.Returns an Iterator over the stored dependenciesvoid
disables the given capability Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES.void
disables all attribute and class types (including dependencies)void
disables all attribute type dependenciesvoid
disables all attribute typesvoid
disables all class type dependenciesvoid
disables all class typesvoid
disables the dependency of the given capability Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES.boolean
Does owner implement CapabilitiesIgnorer and does it not want capability checking to be performed?void
enables the given capability.void
enables all attribute and class types (including dependencies)void
enables all attribute type dependenciesvoid
enables all attribute typesvoid
enables all class type dependenciesvoid
enables all class typesvoid
enables the dependency flag for the given capability Enabling NOMINAL_ATTRIBUTES also enables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES.static Capabilities
forInstances
(Instances data) returns a Capabilities object specific for this data.static Capabilities
forInstances
(Instances data, boolean multi) returns a Capabilities object specific for this data.returns all attribute capabilitiesreturns all class capabilitiesreturns the reason why the tests failed, is null if tests succeededint
returns the minimum number of instances that have to be in the datasetreturns all other capabilities, besides class and attribute related onesgetOwner()
returns the owner of this capabilities objectReturns the revision string.boolean
returns true if the classifier handler has the specified capabilityboolean
Checks whether there are any dependencies at allboolean
returns true if the classifier handler has a dependency for the specified capabilityreturns a comma-separated list of all the capabilities, excluding interface-based ones.static void
loads the given dataset and prints the Capabilities necessary to process it.void
or
(Capabilities c) performs an OR conjunction with the capabilities of the given Capabilities object and updates itselfvoid
setMinimumNumberInstances
(int value) sets the minimum number of instances that have to be in the datasetvoid
setOwner
(CapabilitiesHandler value) sets the owner of this capabilities objectboolean
Returns true if the currently set capabilities support at least all of the capabilities of the given Capabilities object (checks only the enum!)boolean
Returns true if the currently set capabilities support (or have a dependency) at least all of the capabilities of the given Capabilities object (checks only the enum!)boolean
Test the given attribute, whether it can be processed by the handler, given its capabilities.boolean
Test the given attribute, whether it can be processed by the handler, given its capabilities.boolean
Tests the given data, whether it can be processed by the handler, given its capabilities.boolean
Tests a certain range of attributes of the given data, whether it can be processed by the handler, given its capabilities.void
testWithFail
(Attribute att) tests the given attribute by calling the test(Attribute,boolean) method and throws an exception if the test fails.void
testWithFail
(Attribute att, boolean isClass) tests the given attribute by calling the test(Attribute,boolean) method and throws an exception if the test fails.void
testWithFail
(Instances data) tests the given data by calling the test(Instances) method and throws an exception if the test fails.void
testWithFail
(Instances data, int fromIndex, int toIndex) tests the given data by calling the test(Instances,int,int) method and throws an exception if the test fails.turns the capabilities object into source code.turns the capabilities object into source code.toString()
returns a string representation of the capabilities
-
Field Details
-
PROPERTIES_FILE
the properties file for managing the tests- See Also:
-
-
Constructor Details
-
Capabilities
initializes the capabilities for the given owner- Parameters:
owner
- the object that produced this Capabilities instance
-
-
Method Details
-
doNotCheckCapabilities
public boolean doNotCheckCapabilities()Does owner implement CapabilitiesIgnorer and does it not want capability checking to be performed? -
clone
Creates and returns a copy of this object.- Returns:
- a clone of this object
-
assign
retrieves the data from the given Capabilities object- Parameters:
c
- the capabilities object to initialize with
-
and
performs an AND conjunction with the capabilities of the given Capabilities object and updates itself- Parameters:
c
- the capabilities to AND with
-
or
performs an OR conjunction with the capabilities of the given Capabilities object and updates itself- Parameters:
c
- the capabilities to OR with
-
supports
Returns true if the currently set capabilities support at least all of the capabilities of the given Capabilities object (checks only the enum!)- Parameters:
c
- the capabilities to support at least- Returns:
- true if all the requested capabilities are supported
-
supportsMaybe
Returns true if the currently set capabilities support (or have a dependency) at least all of the capabilities of the given Capabilities object (checks only the enum!)- Parameters:
c
- the capabilities (or dependencies) to support at least- Returns:
- true if all the requested capabilities are supported (or at least have a dependency)
-
setOwner
sets the owner of this capabilities object- Parameters:
value
- the new owner
-
getOwner
returns the owner of this capabilities object- Returns:
- the current owner of this capabilites object
-
setMinimumNumberInstances
public void setMinimumNumberInstances(int value) sets the minimum number of instances that have to be in the dataset- Parameters:
value
- the minimum number of instances
-
getMinimumNumberInstances
public int getMinimumNumberInstances()returns the minimum number of instances that have to be in the dataset- Returns:
- the minimum number of instances
-
capabilities
Returns an Iterator over the stored capabilities- Returns:
- iterator over the current capabilities
-
dependencies
Returns an Iterator over the stored dependencies- Returns:
- iterator over the current dependencies
-
enable
enables the given capability. Enabling NOMINAL_ATTRIBUTES also enables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling BINARY_ATTRIBUTES also enables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling UNARY_ATTRIBUTES also enables EMPTY_NOMINAL_ATTRIBUTES. But NOMINAL_CLASS only enables BINARY_CLASS, since normal schemes in Weka don't work with datasets that have only 1 class label (or none).- Parameters:
c
- the capability to enable
-
enableDependency
enables the dependency flag for the given capability Enabling NOMINAL_ATTRIBUTES also enables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling BINARY_ATTRIBUTES also enables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Enabling UNARY_ATTRIBUTES also enables EMPTY_NOMINAL_ATTRIBUTES. But NOMINAL_CLASS only enables BINARY_CLASS, since normal schemes in Weka don't work with datasets that have only 1 class label (or none).- Parameters:
c
- the capability to enable the dependency flag for
-
enableAllClasses
public void enableAllClasses()enables all class types- See Also:
-
enableAllClassDependencies
public void enableAllClassDependencies()enables all class type dependencies -
enableAllAttributes
public void enableAllAttributes()enables all attribute types -
enableAllAttributeDependencies
public void enableAllAttributeDependencies()enables all attribute type dependencies -
enableAll
public void enableAll()enables all attribute and class types (including dependencies) -
disable
disables the given capability Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling BINARY_ATTRIBUTES also disables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling UNARY_ATTRIBUTES also disables EMPTY_NOMINAL_ATTRIBUTES. The same hierarchy applies to the class capabilities.- Parameters:
c
- the capability to disable
-
disableDependency
disables the dependency of the given capability Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES, UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling BINARY_ATTRIBUTES also disables UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES. Disabling UNARY_ATTRIBUTES also disables EMPTY_NOMINAL_ATTRIBUTES. The same hierarchy applies to the class capabilities.- Parameters:
c
- the capability to disable the dependency flag for
-
disableAllClasses
public void disableAllClasses()disables all class types- See Also:
-
disableAllClassDependencies
public void disableAllClassDependencies()disables all class type dependencies -
disableAllAttributes
public void disableAllAttributes()disables all attribute types -
disableAllAttributeDependencies
public void disableAllAttributeDependencies()disables all attribute type dependencies -
disableAll
public void disableAll()disables all attribute and class types (including dependencies) -
getClassCapabilities
returns all class capabilities- Returns:
- all capabilities regarding the class
- See Also:
-
getAttributeCapabilities
returns all attribute capabilities- Returns:
- all capabilities regarding attributes
- See Also:
-
getOtherCapabilities
returns all other capabilities, besides class and attribute related ones- Returns:
- all other capabilities, besides class and attribute related ones
-
handles
returns true if the classifier handler has the specified capability- Parameters:
c
- the capability to test- Returns:
- true if the classifier handler has the capability
-
hasDependency
returns true if the classifier handler has a dependency for the specified capability- Parameters:
c
- the capability to test- Returns:
- true if the classifier handler has a dependency for the capability
-
hasDependencies
public boolean hasDependencies()Checks whether there are any dependencies at all- Returns:
- true if there is at least one dependency for a capability
-
getFailReason
returns the reason why the tests failed, is null if tests succeeded- Returns:
- the reason why the tests failed
-
test
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.- Parameters:
att
- the attribute to test- Returns:
- true if all the tests succeeded
- See Also:
-
test
Test the given attribute, whether it can be processed by the handler, given its capabilities.- Parameters:
att
- the attribute to testisClass
- whether this attribute is the class attribute- Returns:
- true if all the tests succeeded
- See Also:
-
m_AttributeTest
-
test
Tests the given data, whether it can be processed by the handler, given its capabilities. Classifiers implementing theMultiInstanceCapabilitiesHandler
interface are checked automatically for their multi-instance Capabilities (if no bags, then only the bag-structure, otherwise only the first bag).- Parameters:
data
- the data to test- Returns:
- true if all the tests succeeded
- See Also:
-
test
Tests a certain range of attributes of the given data, whether it can be processed by the handler, given its capabilities. Classifiers implementing theMultiInstanceCapabilitiesHandler
interface are checked automatically for their multi-instance Capabilities (if no bags, then only the bag-structure, otherwise only the first bag).- Parameters:
data
- the data to testfromIndex
- the range of attributes - start (incl.)toIndex
- the range of attributes - end (incl.)- Returns:
- true if all the tests succeeded
- See Also:
-
MultiInstanceCapabilitiesHandler
m_InstancesTest
m_MissingValuesTest
m_MissingClassValuesTest
m_MinimumNumberInstancesTest
-
testWithFail
tests the given attribute by calling the test(Attribute,boolean) method and throws an exception if the test fails. The method assumes that the specified attribute is not the class attribute.- Parameters:
att
- the attribute to test- Throws:
Exception
- in case the attribute doesn't pass the tests- See Also:
-
testWithFail
tests the given attribute by calling the test(Attribute,boolean) method and throws an exception if the test fails.- Parameters:
att
- the attribute to testisClass
- whether this attribute is the class attribute- Throws:
Exception
- in case the attribute doesn't pass the tests- See Also:
-
testWithFail
tests the given data by calling the test(Instances,int,int) method and throws an exception if the test fails.- Parameters:
data
- the data to testfromIndex
- the range of attributes - start (incl.)toIndex
- the range of attributes - end (incl.)- Throws:
Exception
- in case the data doesn't pass the tests- See Also:
-
testWithFail
tests the given data by calling the test(Instances) method and throws an exception if the test fails.- Parameters:
data
- the data to test- Throws:
Exception
- in case the data doesn't pass the tests- See Also:
-
listCapabilities
returns a comma-separated list of all the capabilities, excluding interface-based ones.- Returns:
- the string describing the capabilities
-
addCapabilities
generates a string from the capabilities, suitable to add to the help text.- Parameters:
title
- the title for the capabilities- Returns:
- a string describing the capabilities
-
toString
returns a string representation of the capabilities -
toSource
turns the capabilities object into source code. The returned source code is a block that creates a Capabilities object named 'objectname' and enables all the capabilities of this Capabilities object.- Parameters:
objectname
- the name of the Capabilities object being instantiated- Returns:
- the generated source code
-
toSource
turns the capabilities object into source code. The returned source code is a block that creates a Capabilities object named 'objectname' and enables all the capabilities of this Capabilities object.- Parameters:
objectname
- the name of the Capabilities object being instantiatedindent
- the number of blanks to indent- Returns:
- the generated source code
-
forInstances
returns a Capabilities object specific for this data. The multi-instance capability is not checked as well as the minimum number of instances is not set.- Parameters:
data
- the data to base the capabilities on- Returns:
- a data-specific capabilities object
- Throws:
Exception
- in case an error occurrs, e.g., an unknown attribute type
-
forInstances
returns a Capabilities object specific for this data. The minimum number of instances is not set, the check for multi-instance data is optional.- Parameters:
data
- the data to base the capabilities onmulti
- if true then the structure is checked, too- Returns:
- a data-specific capabilities object
- Throws:
Exception
- in case an error occurrs, e.g., an unknown attribute type
-
main
loads the given dataset and prints the Capabilities necessary to process it. Valid parameters: -file filename
the file to load -c index the explicit index of the class attribute (default: none)- Parameters:
args
- the commandline arguments- Throws:
Exception
- if something goes wrong
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-