public class RulesContainer
extends java.lang.Object
Rule.getType
method for details) may be:Rule.CERTAIN
,Rule.POSSIBLE
orRule.APPROXIMATE
.Rule.getCharacteristicDecisionClassUsageTip
method for details)
may be:Rule.AT_LEAST
,Rule.AT_MOST
orRule.EQUAL
,Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
dataFileDirectoryParameterName |
Name of the file directory parameter
|
static java.lang.String |
dataFileNameParameterName |
Name of the file name parameter
|
static java.lang.String |
defaultComment |
Default comment for this rules' container, written to *.rules file.
|
static boolean |
writeDurationToFile |
Tells if 'Duration' tag should be present in *.rules file to which this container is saved.
|
Constructor | Description |
---|---|
RulesContainer(java.lang.String rulesFormat,
double consistencyLevel,
Field[] classes,
Attribute[] learningAttributes) |
Constructor for
RulesContainer class, creating rules' container for given rules' format,
array with all possible values of decision attribute (can be null if unknown, but cannot be empty),
level of consistency and array with attributes from learning memory container. |
RulesContainer(MemoryContainer learningMemoryContainer,
double consistencyLevel) |
Constructor for
RulesContainer class, creating rules' container for given learning memory container
and level of consistency.Calculates format of the rules ( rulesFormat field) on the basis of the description of
given learning memory container (namely on the basis of learning memory container's type and evaluation space),
stored in MemoryContainersDescriptions class. |
Modifier and Type | Method | Description |
---|---|---|
java.lang.Object |
clone() |
Clones this rules' container
|
boolean |
containerIsEmpty() |
Checks if there is at least one decision rule stored in this rules' container
|
boolean |
containsRules(int type,
int characteristicDecisionClassUsageTip) |
Checks if this container stores decision rules for given combination of type and characteristic decision class usage tip
|
void |
deleteAllRules() |
Deletes all rules stored in this container, for any combination of type and characteristic decision class usage tip
(sets references to
null ). |
void |
deleteRules(int type,
int characteristicDecisionClassUsageTip) |
Deletes all decision rules stored for given combination of type and characteristic decision class usage tip
(sets reference to
null ). |
Field[] |
getClasses() |
Gets list of all possible values of decision attribute collected from learning memory container
for which this rules' container has been created.
|
double |
getConsistencyLevel() |
Gets level of consistency used to calculate approximations or boundaries which were basis for induction of rules
stored in this container
|
java.util.ArrayList<Rule> |
getCoveringRules(Example example,
int type,
int characteristicDecisionClassUsageTip) |
Gets list of all rules (of given type, for given characteristic decision class usage tip) covering given example
|
java.lang.String |
getDuration() |
Gets total duration (in miliseconds) of rule induction process for all rules stored within this container
Gets value of "Duration" parameter from
FileInfo object stored in this rules' container. |
FileInfo |
getFileInfo() |
Gets information about this rules' container, written to *.rules file.
|
Attribute[] |
getLearningAttributes() |
Gets attributes from learning memory container for which rules present in this rules' container have been induced.
Because of efficiency field of this class is returned. |
int |
getNumberOfUsedActiveDecisionAttribute() |
Returns number of active decision attribute for which all rules stored in this rules' container are defined
or -1 if this rules' container is empty
|
int |
getQuantityOfRules(int type,
int characteristicDecisionClassUsageTip) |
Gets quantity of decision rules stored for given combination of type and characteristic decision class usage tip.
|
java.util.ArrayList<Rule> |
getRules(int type,
int characteristicDecisionClassUsageTip) |
Gets decision rules stored for given combination of type and characteristic decision class usage tip.
|
java.lang.String |
getRulesFormat() |
Gets format of the rules in this rules' container
|
boolean |
increaseDuration(long duration) |
Increases total duration (in miliseconds) of rule induction process for all rules stored within this container.
|
static RulesContainer |
loadRules(java.lang.String fileName) |
Loads to this container all rules stored in file with given name (path).
|
static RulesContainer |
loadRules(java.lang.String fileName,
ParseLog log) |
Loads to this container all rules stored in file with given name (path).
|
void |
setClasses(Field[] classes) |
Sets list of all possible values of decision attribute collected from learning memory container
for which this rules' container has been created.
Given array is directly stored in this class. |
void |
setConsistencyLevel(double consistencyLevel) |
Sets level of consistency used to calculate approximations or boundaries which were basis for induction of rules
stored in this container
|
void |
setDuration(java.lang.String duration) |
Sets total duration (in miliseconds) of rule induction process for all rules stored within this container.
|
void |
setFileInfo(FileInfo fileInfo) |
Sets information about this rules' container, written to *.rules file.
|
void |
setRulesFormat(java.lang.String rulesFormat) |
Sets format of the rules in this rules' container
|
void |
storeRule(Rule rule) |
Adds given rule to the end of appropriate list of rules stored in this class.
|
void |
writeRules(java.lang.String fileName,
boolean writeRulesStatistics,
boolean writeLearningPositiveAndNeutralExamples) |
Writes all rules stored in this container to file with given name (path), in *.rules (RLF-like) format.
If classes field is not null and there is more than one active decision attribute
in the array of learning attributes, then deactivates all not used active decision attributes first, then writes
this container to given *.rules file and finally reactivates all decision attributes deactivated in the first step. |
void |
writeRulesJAMM(java.lang.String fileName,
boolean writeRulesStatistics) |
Writes all rules stored in this container to file with given name (path), in JAMM rls format.
|
void |
writeRulesXML(java.lang.String fileName,
boolean writeRulesStatistics,
boolean writeLearningPositiveExamples) |
Writes all rules stored in this container to file with given name (path), in XML format.
|
public static boolean writeDurationToFile
true
.public static java.lang.String defaultComment
public static final java.lang.String dataFileDirectoryParameterName
public static final java.lang.String dataFileNameParameterName
public RulesContainer(java.lang.String rulesFormat, double consistencyLevel, Field[] classes, Attribute[] learningAttributes)
RulesContainer
class, creating rules' container for given rules' format,
array with all possible values of decision attribute (can be null
if unknown, but cannot be empty),
level of consistency and array with attributes from learning memory container.
Fields of this rules' container which are not set here receive default value
and may be set later by means of setters defined for this class.rulesFormat
- format of rules in this rules' containerconsistencyLevel
- level of consistency used to calculate approximations or boundaries which were basis
for induction of rules stored in this containerclasses
- array with all possible values of used decision attribute,
i.e. attribute for which rules that are going to be stored in this container were induced.
If decision attribute has preference type assigned (gain or cost) then these values should be ordered
from the worst to the best (i.e. the greater the index, the greater the preference of the DM).
Can be null
if unknown (for example - if not given in the *.rules file), but cannot be empty.learningAttributes
- attributes from learning memory container, for which rules' conditions are definedjava.lang.NullPointerException
- when rules' format is null
or when learning attributes are not set (equal to null
)InvalidValueException
- when rules' format does not contain exactly two strings concatenated by means of "_" string
or when container type (first string) or evaluation space (second string) is incorrect,
when array with values of decision attribute from learning memory container is empty (is not null
, but has zero length),
when consistency level is not in [0, 1] range,
when array with learning attributes is empty (has zero length)
or when there is no active decision attribute among given learning attributesInvalidTypeException
- when classes != null
and list of decision classes is incorrect -
not all classes are instances of the same subtype of Field
,
when there is only one active decision attribute among given learning attributes and type of decision classes from given list
is different than type of initial value of the only active decision attribute
or when there is more than one active decision attribute among given learning attributes and
type of decision classes from given list is different than type of initial value of any active decision attributepublic RulesContainer(MemoryContainer learningMemoryContainer, double consistencyLevel)
RulesContainer
class, creating rules' container for given learning memory container
and level of consistency.rulesFormat
field) on the basis of the description of
given learning memory container (namely on the basis of learning memory container's type and evaluation space),
stored in MemoryContainersDescriptions
class.
If description of given learning memory container is not stored in MemoryContainersDescriptions
class (see MemoryContainersDescriptions.containsDescription(MemoryContainer
method),
then it is checked if learning memory container is PCT (see PCTDetector.isPCT(MemoryContainer)
method),
similarity table (see SimilarityTableDetector.isSimilarityTable(MemoryContainer)
method)
or simple decision table.
In the first case, MemoryContainerDescription.PCT_STRING + "_" + MemoryContainerDescription.PARETO_STRING
format is taken as default.
In the second case, MemoryContainerDescription.SIMILARITY_TABLE_STRING + "_" + MemoryContainerDescription.PARETO_STRING
format is taken as default.
In the last case, MemoryContainerDescription.INFORMATION_TABLE_STRING + "_" + MemoryContainerDescription.PARETO_STRING
format is assumed.learningMemoryContainer
- reference to learning memory container for which this rules' container is createdconsistencyLevel
- level of consistency used to calculate approximations or boundaries which are basis
for induction of rules stored in this containerjava.lang.NullPointerException
- when learning memory container is null
InvalidValueException
- when learning memory container contains no attributes or no examples,
when consistency level is not in [0, 1] range
or when there is no active decision attribute in given learning memory containerpublic void storeRule(Rule rule)
Rule.getType
and rule.getCharacteristicDecisionClassUsageTip
methods).
If considered list of rules is null
, then it is first created and then given rule is appended to it.rule
- rule to add to this containerjava.lang.NullPointerException
- when rule is null
InvalidValueException
- when rule has no decision
or when decision part of given rule is defined for other attribute than decision parts of other rules already stored in this rules' containerpublic java.util.ArrayList<Rule> getRules(int type, int characteristicDecisionClassUsageTip)
null
.type
- Type of stored rules. Can be Rule.CERTAIN
, Rule.POSSIBLE
or Rule.APPROXIMATE
characteristicDecisionClassUsageTip
- Tip for usage of characteristic decision classes of stored rules.
Can be Rule.AT_LEAST
, Rule.AT_MOST
or Rule.EQUAL
.InvalidValueException
- when type is none of Rule.CERTAIN
, Rule.POSSIBLE
and Rule.APPROXIMATE
or when tip for usage of characteristic decision class is none of Rule.AT_LEAST
, Rule.AT_MOST
and Rule.EQUAL
public void deleteRules(int type, int characteristicDecisionClassUsageTip)
null
).type
- Type of stored rules. Can be Rule.CERTAIN
, Rule.POSSIBLE
or Rule.APPROXIMATE
characteristicDecisionClassUsageTip
- Tip for usage of characteristic decision classes of stored rules.
Can be Rule.AT_LEAST
, Rule.AT_MOST
or Rule.EQUAL
.InvalidValueException
- when type is none of Rule.CERTAIN
, Rule.POSSIBLE
and Rule.APPROXIMATE
or when tip for usage of characteristic decision class is none of Rule.AT_LEAST
, Rule.AT_MOST
and Rule.EQUAL
public void deleteAllRules()
null
).public int getQuantityOfRules(int type, int characteristicDecisionClassUsageTip)
0
.type
- Type of stored rules. Can be Rule.CERTAIN
, Rule.POSSIBLE
or Rule.APPROXIMATE
characteristicDecisionClassUsageTip
- Tip for usage of characteristic decision classes of stored rules.
Can be Rule.AT_LEAST
, Rule.AT_MOST
or Rule.EQUAL
.InvalidValueException
- when type is none of Rule.CERTAIN
, Rule.POSSIBLE
and Rule.APPROXIMATE
or when tip for usage of characteristic decision class is none of Rule.AT_LEAST
, Rule.AT_MOST
and Rule.EQUAL
public boolean containsRules(int type, int characteristicDecisionClassUsageTip)
type
- Type of stored rules. Can be Rule.CERTAIN
, Rule.POSSIBLE
or Rule.APPROXIMATE
characteristicDecisionClassUsageTip
- Tip for usage of characteristic decision classes of stored rules.
Can be Rule.AT_LEAST
, Rule.AT_MOST
or Rule.EQUAL
.true
if this container stores rules for given combination of type and characteristic decision class usage tip,
false
otherwiseInvalidValueException
- when type is none of Rule.CERTAIN
, Rule.POSSIBLE
and Rule.APPROXIMATE
or when tip for usage of characteristic decision class is none of Rule.AT_LEAST
, Rule.AT_MOST
and Rule.EQUAL
public java.util.ArrayList<Rule> getCoveringRules(Example example, int type, int characteristicDecisionClassUsageTip)
example
- considered exampletype
- Type of stored rules. Can be Rule.CERTAIN
, Rule.POSSIBLE
or Rule.APPROXIMATE
characteristicDecisionClassUsageTip
- Tip for usage of characteristic decision classes of stored rules.
Can be Rule.AT_LEAST
, Rule.AT_MOST
or Rule.EQUAL
.public void writeRules(java.lang.String fileName, boolean writeRulesStatistics, boolean writeLearningPositiveAndNeutralExamples) throws java.io.IOException
classes
field is not null
and there is more than one active decision attribute
in the array of learning attributes, then deactivates all not used active decision attributes first, then writes
this container to given *.rules file and finally reactivates all decision attributes deactivated in the first step.fileName
- name (path) of the file in which all rules should be savedwriteRulesStatistics
- Switch used to trigger write of rules' statistics. If true
then
statistics of each rule stored in this container will be saved to file, otherwise only rules will be saved.writeLearningPositiveAndNeutralExamples
- tells if LearningPositiveExamples
and LearningNeutralExamples
tags should be present in each rule's statistics,
if statistics are saved to filejava.io.IOException
- when file with given name (path) can't be opened for writepublic void writeRulesJAMM(java.lang.String fileName, boolean writeRulesStatistics) throws java.io.IOException
fileName
- name of the file in which all rules should be savedwriteRulesStatistics
- Switch used to trigger write of rules' statistics. If true
then
statistics of each rule stored in this container will be saved to file, otherwise only rules will be saved.java.io.IOException
- when file with given name (path) can't be opened for writepublic void writeRulesXML(java.lang.String fileName, boolean writeRulesStatistics, boolean writeLearningPositiveExamples) throws java.io.IOException
fileName
- name of the file in which all rules should be savedwriteRulesStatistics
- Switch used to trigger write of rules' statistics. If true
then
statistics of each rules stored in this container will be saved to file, otherwise only rules will be saved.writeLearningPositiveExamples
- tells if list of learning positive examples should be present in each rule's statistics,
if statistics are saved to filejava.io.IOException
- when file with given name (path) can't be opened for writepublic static RulesContainer loadRules(java.lang.String fileName, ParseLog log) throws java.io.FileNotFoundException
fileName
- name (path) of the file from which all rules should be loadedlog
- object of ParseLog
subclass, responsible for logging parser warnings, errors, and fatal errorsnull
if loading failedjava.io.FileNotFoundException
- if file with given name (path) can't be opened for writepublic static RulesContainer loadRules(java.lang.String fileName) throws java.io.FileNotFoundException
fileName
- name (path) of the file from which all rules should be loadednull
if loading failedjava.io.FileNotFoundException
- if file with given name (path) can't be opened for writepublic java.lang.String getRulesFormat()
public void setRulesFormat(java.lang.String rulesFormat)
rulesFormat
- format of the rules in this rules' containerjava.lang.NullPointerException
- when rules' format is null
InvalidValueException
- if rules' format does not contain exactly two strings concatenated by means of "_" string
or when container type (first string) or evaluation space (second string) is incorrectpublic double getConsistencyLevel()
public void setConsistencyLevel(double consistencyLevel)
consistencyLevel
- level of consistency used to calculate approximations or boundaries which were basis for induction of rules
stored in this containerInvalidValueException
- when consistency level is not in [0, 1] rangepublic Field[] getClasses()
Field.compareTo
).
If any two decision attribute values are incomparable, then their respective order may be arbitrary.null
if the list of all possible values of decision attribute is unknownpublic void setClasses(Field[] classes)
classes
- list of all possible values of decision attribute collected from learning memory container
for which this rules' container has been created or null
if the list of all possible values of decision attribute is unknownInvalidValueException
- when array with values of decision attribute from learning memory container
is empty (is not null
, but has zero length)InvalidTypeException
- when classes != null
and list of decision classes is incorrect -
not all classes are instances of the same subtype of Field
,
when there is only one active decision attribute among learning attributes and type of decision classes from given list
is different than type of initial value of the only active decision attribute
or when there is more than one active decision attribute among learning attributes and
type of decision classes from given list is different than type of initial value of any active decision attributepublic boolean containerIsEmpty()
true
if this rules' container contains at least one decision rulepublic java.lang.String getDuration()
FileInfo
object stored in this rules' container.public void setDuration(java.lang.String duration)
FileInfo
object stored in this rules' container.duration
- total duration (in miliseconds) of rule induction process for all rules stored within this containerpublic boolean increaseDuration(long duration)
FileInfo
object stored in this rules' container.duration
- duration (in miliseconds) of rule induction process (e.g. for particular combination of type and
characteristic decision class usage tip)true
if duration stored in FileInfo
object from this rules' container
was successfully increased by given value (stored duration is correct), false
otherwisepublic FileInfo getFileInfo()
FileInfo
object.public void setFileInfo(FileInfo fileInfo)
fileInfo
- information about this rules' container, written to *.rules filepublic Attribute[] getLearningAttributes()
public int getNumberOfUsedActiveDecisionAttribute()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- when clone is not supported