public class Capabilities extends Object implements Cloneable, Serializable, RevisionHandler
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); ...
| Modifier and Type | Class and Description |
|---|---|
static class |
Capabilities.Capability
enumeration of all capabilities
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
m_AttributeTest
whether to perform attribute based tests
|
protected HashSet |
m_Capabilities
the hashset for storing the active capabilities
|
protected HashSet |
m_Dependencies
the hashset for storing dependent capabilities, eg for meta-classifiers
|
protected Exception |
m_FailReason
the reason why the test failed, used to throw an exception
|
protected boolean |
m_InstancesTest
whether to perform data based tests
|
protected int |
m_MinimumNumberInstances
the minimum number of instances in a dataset
|
protected boolean |
m_MinimumNumberInstancesTest
whether to test for minimum number of instances
|
protected boolean |
m_MissingClassValuesTest
whether to test for missing class values
|
protected boolean |
m_MissingValuesTest
whether to test for missing values
|
protected CapabilitiesHandler |
m_Owner
the object that owns this capabilities instance
|
protected boolean |
m_Test
whether to perform any tests at all
|
protected static Properties |
PROPERTIES
the actual properties
|
static String |
PROPERTIES_FILE
the properties file for managing the tests
|
| Constructor and Description |
|---|
Capabilities(CapabilitiesHandler owner)
initializes the capabilities for the given owner
|
| Modifier and Type | Method and Description |
|---|---|
void |
and(Capabilities c)
performs an AND conjunction with the capabilities of the given
Capabilities object and updates itself
|
void |
assign(Capabilities c)
retrieves the data from the given Capabilities object
|
Iterator |
capabilities()
Returns an Iterator over the stored capabilities
|
Object |
clone()
Creates and returns a copy of this object.
|
protected String |
createMessage(String msg)
Generates the message for, e.g., an exception.
|
Iterator |
dependencies()
Returns an Iterator over the stored dependencies
|
void |
disable(Capabilities.Capability c)
disables the given capability
Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES,
UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES.
|
void |
disableAll()
disables all attribute and class types (including dependencies)
|
void |
disableAllAttributeDependencies()
disables all attribute type dependencies
|
void |
disableAllAttributes()
disables all attribute types
|
void |
disableAllClassDependencies()
disables all class type dependencies
|
void |
disableAllClasses()
disables all class types
|
void |
disableDependency(Capabilities.Capability c)
disables the dependency of the given capability
Disabling NOMINAL_ATTRIBUTES also disables BINARY_ATTRIBUTES,
UNARY_ATTRIBUTES and EMPTY_NOMINAL_ATTRIBUTES.
|
void |
enable(Capabilities.Capability c)
enables the given capability.
|
void |
enableAll()
enables all attribute and class types (including dependencies)
|
void |
enableAllAttributeDependencies()
enables all attribute type dependencies
|
void |
enableAllAttributes()
enables all attribute types
|
void |
enableAllClassDependencies()
enables all class type dependencies
|
void |
enableAllClasses()
enables all class types
|
void |
enableDependency(Capabilities.Capability c)
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.
|
Capabilities |
getAttributeCapabilities()
returns all attribute capabilities
|
Capabilities |
getClassCapabilities()
returns all class capabilities
|
Exception |
getFailReason()
returns the reason why the tests failed, is null if tests succeeded
|
int |
getMinimumNumberInstances()
returns the minimum number of instances that have to be in the dataset
|
Capabilities |
getOtherCapabilities()
returns all other capabilities, besides class and attribute related ones
|
CapabilitiesHandler |
getOwner()
returns the owner of this capabilities object
|
String |
getRevision()
Returns the revision string.
|
boolean |
handles(Capabilities.Capability c)
returns true if the classifier handler has the specified capability
|
boolean |
hasDependencies()
Checks whether there are any dependencies at all
|
boolean |
hasDependency(Capabilities.Capability c)
returns true if the classifier handler has a dependency for the specified
capability
|
static void |
main(String[] args)
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 itself
|
void |
setMinimumNumberInstances(int value)
sets the minimum number of instances that have to be in the dataset
|
void |
setOwner(CapabilitiesHandler value)
sets the owner of this capabilities object
|
boolean |
supports(Capabilities c)
Returns true if the currently set capabilities support at least all of
the capabiliites of the given Capabilities object (checks only the enum!)
|
boolean |
supportsMaybe(Capabilities c)
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(Attribute att)
Test the given attribute, whether it can be processed by the handler,
given its capabilities.
|
boolean |
test(Attribute att,
boolean isClass)
Test the given attribute, whether it can be processed by the handler,
given its capabilities.
|
boolean |
test(Instances data)
Tests the given data, whether it can be processed by the handler,
given its capabilities.
|
boolean |
test(Instances data,
int fromIndex,
int toIndex)
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.
|
String |
toSource(String objectname)
turns the capabilities object into source code.
|
String |
toSource(String objectname,
int indent)
turns the capabilities object into source code.
|
String |
toString()
returns a string representation of the capabilities
|
public static final String PROPERTIES_FILE
protected static Properties PROPERTIES
protected CapabilitiesHandler m_Owner
protected HashSet m_Capabilities
protected HashSet m_Dependencies
protected Exception m_FailReason
protected int m_MinimumNumberInstances
protected boolean m_Test
protected boolean m_InstancesTest
protected boolean m_AttributeTest
protected boolean m_MissingValuesTest
protected boolean m_MissingClassValuesTest
protected boolean m_MinimumNumberInstancesTest
public Capabilities(CapabilitiesHandler owner)
owner - the object that produced this Capabilities instancepublic Object clone()
public void assign(Capabilities c)
c - the capabilities object to initialize withpublic void and(Capabilities c)
c - the capabilities to AND withpublic void or(Capabilities c)
c - the capabilities to OR withpublic boolean supports(Capabilities c)
c - the capabilities to support at leastpublic boolean supportsMaybe(Capabilities c)
c - the capabilities (or dependencies) to support at leastpublic void setOwner(CapabilitiesHandler value)
value - the new ownerpublic CapabilitiesHandler getOwner()
public void setMinimumNumberInstances(int value)
value - the minimum number of instancespublic int getMinimumNumberInstances()
public Iterator capabilities()
public Iterator dependencies()
public void enable(Capabilities.Capability c)
c - the capability to enablepublic void enableDependency(Capabilities.Capability c)
c - the capability to enable the dependency flag forpublic void enableAllClasses()
disableAllClasses(),
getClassCapabilities()public void enableAllClassDependencies()
public void enableAllAttributes()
disableAllAttributes(),
getAttributeCapabilities()public void enableAllAttributeDependencies()
public void enableAll()
public void disable(Capabilities.Capability c)
c - the capability to disablepublic void disableDependency(Capabilities.Capability c)
c - the capability to disable the dependency flag forpublic void disableAllClasses()
enableAllClasses(),
getClassCapabilities()public void disableAllClassDependencies()
public void disableAllAttributes()
enableAllAttributes(),
getAttributeCapabilities()public void disableAllAttributeDependencies()
public void disableAll()
public Capabilities getClassCapabilities()
enableAllClasses(),
disableAllClasses()public Capabilities getAttributeCapabilities()
enableAllAttributes(),
disableAllAttributes()public Capabilities getOtherCapabilities()
public boolean handles(Capabilities.Capability c)
c - the capability to testpublic boolean hasDependency(Capabilities.Capability c)
c - the capability to testpublic boolean hasDependencies()
public Exception getFailReason()
protected String createMessage(String msg)
msg - the actual content of the message, e.g., exceptionpublic boolean test(Attribute att)
att - the attribute to testtest(Attribute, boolean)public boolean test(Attribute att, boolean isClass)
att - the attribute to testisClass - whether this attribute is the class attributem_AttributeTestpublic boolean test(Instances data)
MultiInstanceCapabilitiesHandler interface are checked
automatically for their multi-instance Capabilities (if no bags, then
only the bag-structure, otherwise only the first bag).data - the data to testtest(Instances, int, int)public boolean test(Instances data, int fromIndex, int toIndex)
MultiInstanceCapabilitiesHandler interface
are checked automatically for their multi-instance Capabilities (if no
bags, then only the bag-structure, otherwise only the first bag).data - the data to testfromIndex - the range of attributes - start (incl.)toIndex - the range of attributes - end (incl.)MultiInstanceCapabilitiesHandler,
m_InstancesTest,
m_MissingValuesTest,
m_MissingClassValuesTest,
m_MinimumNumberInstancesTestpublic void testWithFail(Attribute att) throws Exception
att - the attribute to testException - in case the attribute doesn't pass the teststest(Attribute,boolean)public void testWithFail(Attribute att, boolean isClass) throws Exception
att - the attribute to testisClass - whether this attribute is the class attributeException - in case the attribute doesn't pass the teststest(Attribute,boolean)public void testWithFail(Instances data, int fromIndex, int toIndex) throws Exception
data - the data to testfromIndex - the range of attributes - start (incl.)toIndex - the range of attributes - end (incl.)Exception - in case the data doesn't pass the teststest(Instances,int,int)public void testWithFail(Instances data) throws Exception
data - the data to testException - in case the data doesn't pass the teststest(Instances)public String toString()
public String toSource(String objectname)
objectname - the name of the Capabilities object being instantiatedpublic String toSource(String objectname, int indent)
objectname - the name of the Capabilities object being instantiatedindent - the number of blanks to indentpublic static Capabilities forInstances(Instances data) throws Exception
data - the data to base the capabilities onException - in case an error occurrs, e.g., an unknown attribute
typepublic static Capabilities forInstances(Instances data, boolean multi) throws Exception
data - the data to base the capabilities onmulti - if true then the structure is checked, tooException - in case an error occurrs, e.g., an unknown attribute
typepublic static void main(String[] args) throws Exception
args - the commandline argumentsException - if something goes wrongpublic String getRevision()
getRevision in interface RevisionHandlerCopyright © 2015 University of Waikato, Hamilton, NZ. All rights reserved.