public class Capabilities extends java.lang.Object implements java.lang.Cloneable, java.io.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 static boolean |
ATTRIBUTE_TEST
whether to perform attribute based tests
|
protected static boolean |
INSTANCES_TEST
whether to perform data based tests
|
protected static java.util.HashSet<java.lang.Class> |
INTERFACE_DEFINED_CAPABILITIES
Capabilities defined by interfaces
|
protected boolean |
m_AttributeTest
whether to perform attribute based tests
|
protected java.util.HashSet<Capabilities.Capability> |
m_Capabilities
the hashset for storing the active capabilities
|
protected java.util.HashSet<Capabilities.Capability> |
m_Dependencies
the hashset for storing dependent capabilities, eg for meta-classifiers
|
protected java.lang.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 java.util.HashSet<java.lang.Class> |
m_InterfaceDefinedCapabilities
the interface-defined capabilities
|
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 boolean |
MINIMUM_NUMBER_INSTANCES_TEST
whether to test for minimum number of instances
|
protected static boolean |
MISSING_CLASS_VALUES_TEST
whether to test for missing class values
|
protected static boolean |
MISSING_VALUES_TEST
whether to test for missing values
|
protected static java.util.Properties |
PROPERTIES
the actual properties
|
static java.lang.String |
PROPERTIES_FILE
the properties file for managing the tests
|
protected static boolean |
TEST
whether to perform any tests at all
|
| Constructor and Description |
|---|
Capabilities(CapabilitiesHandler owner)
initializes the capabilities for the given owner
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
addCapabilities(java.lang.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 itself
|
void |
assign(Capabilities c)
retrieves the data from the given Capabilities object
|
java.util.Iterator<Capabilities.Capability> |
capabilities()
Returns an Iterator over the stored capabilities
|
java.lang.Object |
clone()
Creates and returns a copy of this object.
|
protected java.lang.String |
createMessage(java.lang.String msg)
Generates the message for, e.g., an exception.
|
java.util.Iterator<Capabilities.Capability> |
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.
|
boolean |
doNotCheckCapabilities()
Does owner implement CapabilitiesIgnorer and does it not
want capability checking to be performed?
|
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
|
protected static java.lang.Class |
getClass(java.lang.String name)
Gets the class for the given name.
|
Capabilities |
getClassCapabilities()
returns all class capabilities
|
java.lang.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
|
java.lang.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
|
java.lang.String |
listCapabilities()
returns a comma-separated list of all the capabilities, excluding interface-based ones.
|
static void |
main(java.lang.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
capabilities 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.
|
java.lang.String |
toSource(java.lang.String objectname)
turns the capabilities object into source code.
|
java.lang.String |
toSource(java.lang.String objectname,
int indent)
turns the capabilities object into source code.
|
java.lang.String |
toString()
returns a string representation of the capabilities
|
public static final java.lang.String PROPERTIES_FILE
protected static java.util.Properties PROPERTIES
protected static java.util.HashSet<java.lang.Class> INTERFACE_DEFINED_CAPABILITIES
protected static boolean TEST
protected static boolean INSTANCES_TEST
protected static boolean ATTRIBUTE_TEST
protected static boolean MISSING_VALUES_TEST
protected static boolean MISSING_CLASS_VALUES_TEST
protected static boolean MINIMUM_NUMBER_INSTANCES_TEST
protected CapabilitiesHandler m_Owner
protected java.util.HashSet<Capabilities.Capability> m_Capabilities
protected java.util.HashSet<Capabilities.Capability> m_Dependencies
protected java.util.HashSet<java.lang.Class> m_InterfaceDefinedCapabilities
protected java.lang.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 boolean doNotCheckCapabilities()
public java.lang.Object clone()
clone in class java.lang.Objectpublic 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 java.util.Iterator<Capabilities.Capability> capabilities()
public java.util.Iterator<Capabilities.Capability> 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 java.lang.Exception getFailReason()
protected java.lang.String createMessage(java.lang.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)protected static java.lang.Class getClass(java.lang.String name)
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 java.lang.Exception
att - the attribute to testjava.lang.Exception - in case the attribute doesn't pass the teststest(Attribute,boolean)public void testWithFail(Attribute att, boolean isClass) throws java.lang.Exception
att - the attribute to testisClass - whether this attribute is the class attributejava.lang.Exception - in case the attribute doesn't pass the teststest(Attribute,boolean)public void testWithFail(Instances data, int fromIndex, int toIndex) throws java.lang.Exception
data - the data to testfromIndex - the range of attributes - start (incl.)toIndex - the range of attributes - end (incl.)java.lang.Exception - in case the data doesn't pass the teststest(Instances,int,int)public void testWithFail(Instances data) throws java.lang.Exception
data - the data to testjava.lang.Exception - in case the data doesn't pass the teststest(Instances)public java.lang.String listCapabilities()
public java.lang.String addCapabilities(java.lang.String title)
title - the title for the capabilitiespublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toSource(java.lang.String objectname)
objectname - the name of the Capabilities object being instantiatedpublic java.lang.String toSource(java.lang.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 java.lang.Exception
data - the data to base the capabilities onjava.lang.Exception - in case an error occurrs, e.g., an unknown attribute typepublic static Capabilities forInstances(Instances data, boolean multi) throws java.lang.Exception
data - the data to base the capabilities onmulti - if true then the structure is checked, toojava.lang.Exception - in case an error occurrs, e.g., an unknown attribute typepublic static void main(java.lang.String[] args)
throws java.lang.Exception
args - the commandline argumentsjava.lang.Exception - if something goes wrongpublic java.lang.String getRevision()
getRevision in interface RevisionHandler