FreeCBR
Class CBR

java.lang.Object
  extended by FreeCBR.CBR
All Implemented Interfaces:
java.io.Serializable

public class CBR
extends java.lang.Object
implements java.io.Serializable

This is a CBR (Case Base Reasoning) API implementation. It finds the closest match among cases in a case set. Each case consists of a predefined set of features. The features are defined by a name and a datatype where the datatype may be any of String, MultiString, Float, Int and Bool.

The closest match is calculated using weighted euclid distance (??) - like Pythagoras theorem in n dimensions.

The returned "hit percentage" is calculated as 100 * (1 - sqrt(case distance/sum(weights))) and receives a value between 0 and 100.

The distance between the search and a case is a floating point number between 0 and 1 and is calculated as:
case distance = weight1 * dist12 + weight2 * dist22 + .. + weightn * distn2
where

disti is the distance between the searched feature and the actual case feature. This value is a float between 0 and 1 where 0 means exact hit and 1 means maximum distance.

weighti is the weight for feature number "i". It is an integer >= 0, default = 5.

This means that the total case distance is >= 0 (0 means exact match) and <= sqrt(sumi=1 to n(weight[i])) where n is the number of features searched for.

The distance between the searched feature and the actual case feature is calculated as:
If case value or searched value is "?" the case feature is disqualified and not included in the result.
If the search is for only "?":s there are no hits

The "normal" algorithm (let's call it the NormalDistance algorithm) is
distance = min(1, diff(searchedvalue, casevalue)/((maxvalue - minvalue) * infinity_constant))
or in other words
if diff(searchedvalue, casevalue) > (maxvalue - minvalue) * infinity_constant then distance = 1, else distance = diff(searchedvalue, casevalue)/((maxvalue - minvalue) * infinity_constant)
where "infinity_constant" is a constant that defines what distance is regarded as infinity

The "logarithmic" algorithm (let's call it the LogarithmicDistance algorithm) is
ln(NormalDistance * (e-1) + 1)

If the search is done for:

"=" and fuzzy linear: if exact match then distance = 0 else use the NormalDistance algorithm
"=" and fuzzy logarithmic: if exact match then distance = 0 use the LogarithmicDistance algorithm
"=" and strict: if exact match then distance = 0 otherwise the entire case is disqualified and not included in the result
"=" and flat: if exact match then distance = 0 otherwise distance = 1

"!=" and fuzzy linear: if exact match then distance = 1 else use the NormalDistance algorithm inverted
"!=" and fuzzy logarithmic: if exact match then distance = 1 use the LogarithmicDistance algorithm inverted
"!=" and strict: if exact match then the entire case is disqualified and not included in the result, otherwise distance = 0
"!=" and flat: if exact match then distance = 1 otherwise distance = 0

">=" and fuzzy linear: if searched value >= case value then 0 otherwise use the NormalDistance algorithm
">=" and fuzzy logarithmic: if searched value >= case value then 0 otherwise use the LogarithmicDistance algorithm
">=" and strict: if searched value >= case value then 0 otherwise the entire case is disqualified and not included in the result
">=" and flat: if searched value >= case value then 0 otherwise 1

">" and fuzzy linear: if searched value > case value then 0 otherwise use the NormalDistance algorithm
">" and fuzzy logarithmic: if searched value > case value then 0 otherwise use the LogarithmicDistance algorithm
">" and strict: if searched value > case value then 0 otherwise the entire case is disqualified and not included in the result
">" and flat: if searched value > case value then 0 otherwise 1

"<=" and fuzzy linear: if searched value <= case value then 0 otherwise use the NormalDistance algorithm
"<=" and fuzzy logarithmic: if searched value <= case value then 0 otherwise use the LogarithmicDistance algorithm
"<=" and strict: if searched value <= case value then 0 otherwise the entire case is disqualified and not included in the result
"<=" and flat: if searched value <= case value then 0 otherwise 1

"<" and fuzzy linear: if searched value < case value then 0 otherwise use the NormalDistance algorithm
"<" and fuzzy logarithmic: if searched value < case value then 0 otherwise use the LogarithmicDistance algorithm
"<" and strict: if searched value < case value then 0 otherwise the entire case is disqualified and not included in the result
"<" and flat: if searched value < case value then 0 otherwise 1

"max" and fuzzy linear: the NormalDistance algorithm between current case value and the max case vale
"max" and fuzzy logarithmic: the LogarithmicDistance algorithm between current case value and the max case vale
"max" and strict: if searched value is the max case value then 0, otherwise the entire case is disqualified and not included in the result
"max" and flat: if searched value is the max case value then 0, otherwise 1

"min" and fuzzy linear: the NormalDistance algorithm between current case value and the min case vale
"min" and fuzzy logarithmic: the LogarithmicDistance algorithm between current case value and the min case vale
"min" and strict: if searched value is the min case value then 0, otherwise the entire case is disqualified and not included in the result
"min" and flat: if searched value is the min case value then 0, otherwise 1

Since:
1.0
Author:
Lars Johanson
See Also:
Serialized Form

Field Summary
static int DEFAULT_WEIGHT
          Default weight
protected  int INFINITY_CONSTANT
          Values further away than this are considered infinity
static int SEARCH_OPTION_INVERTED
          Should the search result be inverted?
static short SEARCH_SCALE_FLAT
          Search with a "flat" scale - if the hit is not exact it is treated as maximum distance
static short SEARCH_SCALE_FUZZY_LINEAR
          Search with a linear scale.
static short SEARCH_SCALE_FUZZY_LOGARITHMIC
          Search with a logarithmic scale
static short SEARCH_SCALE_STRICT
          Search "strict" - if the hit is not exact the case is not included in the result at all
static short SEARCH_TERM_EQUAL
          Search for closest value.
static short SEARCH_TERM_GREATER
          Search for greater values.
static short SEARCH_TERM_GREATER_OR_EQUAL
          Search for greater or equal values.
static short SEARCH_TERM_LESS
          Search for smaller values.
static short SEARCH_TERM_LESS_OR_EQUAL
          Search for smaller or equal values.
static short SEARCH_TERM_MAX
          Search for maximum values, the higher the better.
static short SEARCH_TERM_MIN
          Search for minimum, the lower the better.
static short SEARCH_TERM_NOT_EQUAL
          Search for non-equal values.
 
Constructor Summary
CBR()
          Constructor that initiates the CBR with no data.
CBR(java.lang.String logfile, boolean verbose, boolean silent)
          Constructor that initiates the CBR with no data
CBR(java.lang.String datafile, java.lang.String logfile, boolean verbose, boolean silent)
          Constructor that initiates the CBR with data
 
Method Summary
 void addCase(Feature[] features)
          Adds a case to the set
 void addCase(java.lang.String caseString)
          Adds a case to the set
 void addFeature(java.lang.String name, short type)
          Adds a feature (column) to the set.
 Feature[] editCase(int caseNum, Feature[] features)
          Replaces specified case with another
 Feature[] getCase(int caseNum)
          Returns the case at the specified position
 java.lang.String getDatafile()
          Returns the name of the data file currently in use
 java.lang.String getFeatureName(int featureNum)
          Returns the name of the specified feature
 int getFeatureNum(java.lang.String featureName)
          Returns the number of the feature that carries the specified name
 short getFeatureType(int featureNum)
          Returns the datatype of the specified feature
 Feature getFeatureValue(int caseNum, int featureNum)
          Returns the specified feature of the specified case
 java.lang.String getFeatureValueAX(int caseNum, int featureNum)
          Returns the specified feature of the specified case.
 int getINFINITY_CONSTANT()
          Returns the current infinity constant
 java.lang.String getLogfile()
          Returns the name of the current log file
 double getMaxFloatValue(int featureNum)
          Returns the maximum floating point value of all cases for the specified feature
 long getMaxIntValue(int featureNum)
          Returns the maximum integer value of all cases for the specified feature
 double getMinFloatValue(int featureNum)
          Returns the minimum floating point value of all cases for the specified feature
 long getMinIntValue(int featureNum)
          Returns the minimum integer value of all cases for the specified feature
 int getNumCases()
          Returns the number of cases in current set
 int getNumFeatures()
          Returns the number of features that each case has.
 boolean getSilent()
          Returns the silence state
 java.lang.String[] getUsedStringValues(int featureNum)
          Returns all of the string values used at specified feature, works for String and MultiString features
 java.lang.String getUsedStringValuesAX(int featureNum, java.lang.String separator)
          Returns all of the string values used at specified feature, works for String and MultiString features.
 boolean getVerbose()
          Returns the verbose state
 void initialize(java.lang.String datafile, java.lang.String logfile)
          Initializes the CBR if not already done.
 void loadSet(java.lang.String filename)
          Loads a case set to memory
 void newSet(java.lang.String[] featureNames, java.lang.String[] featureTypeNames)
          Empties the memory - deletes the current set from memory and creates a new empty set with the specified feature names and feature data types
 void readData()
          Reads the data from the datafile.
 Feature[] removeCase(int caseNum)
          Removes the specified case from the set
 void removeFeature(int featureNumber)
          Deletes a feature (column) from the set.
 void saveSet(java.lang.String filename, boolean setDefault)
          Saves the entire case set
 CBRResult[] search(int[] searchFeatureNumbers, Feature[] searchValues, int[] searchWeights, int[] searchTerms, int[] searchScales, int[] searchOptions)
          Performs a search for the best match.
 WebResult search(java.lang.Object req)
          Performs a search for the best match in a "web" way.
 CBRResult[] search(java.lang.String[] searchFeatureNames, java.lang.String[] searchValues, int[] searchWeights, int[] searchTerms, int[] searchScales, int[] searchOptions)
          Performs a search for the best match.
 java.lang.String searchAX(java.lang.Object[] searchFeatureNames, java.lang.Object[] searchValues, java.lang.Object[] searchWeights, java.lang.Object[] searchTerms, java.lang.Object[] searchScales, java.lang.Object[] searchOptions, java.lang.String resultSeparator, java.lang.String caseSeparator)
          Performs a search for the best match, used primarily by ActiveX components.
 void setDatafile(java.lang.String datafile)
          Sets the data file.
 void setFeatureName(int featureNum, java.lang.String newName)
          Sets the name of the specified feature to the specified value
 void setFeatureType(int featureNum, short newType)
          Sets the datatype of the specified feature
 void setFeatureValue(int caseNum, int featureNum, java.lang.String value)
          Sets the specified feature of the specified case to the specified value
 void setINFINITY_CONSTANT(int infinity)
          Sets the infinity constant
 void setLogfile(java.lang.String logfile)
          Sets the log file to the specified path
 void setSilent(boolean silent)
          Sets the silence state
 void setVerbose(boolean verbose)
          Sets the verbose state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITY_CONSTANT

protected int INFINITY_CONSTANT
Values further away than this are considered infinity

Since:
1.0

DEFAULT_WEIGHT

public static final int DEFAULT_WEIGHT
Default weight

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_EQUAL

public static final short SEARCH_TERM_EQUAL
Search for closest value. Default. Valid for all data types.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_NOT_EQUAL

public static final short SEARCH_TERM_NOT_EQUAL
Search for non-equal values. Valid for all data types.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_GREATER_OR_EQUAL

public static final short SEARCH_TERM_GREATER_OR_EQUAL
Search for greater or equal values. Valid for Int and float.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_GREATER

public static final short SEARCH_TERM_GREATER
Search for greater values. Valid for Int and float.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_LESS_OR_EQUAL

public static final short SEARCH_TERM_LESS_OR_EQUAL
Search for smaller or equal values. Valid for Int and float.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_LESS

public static final short SEARCH_TERM_LESS
Search for smaller values. Valid for Int and float.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_MAX

public static final short SEARCH_TERM_MAX
Search for maximum values, the higher the better. Valid for Int and float.

Since:
1.0
See Also:
Constant Field Values

SEARCH_TERM_MIN

public static final short SEARCH_TERM_MIN
Search for minimum, the lower the better. Valid for Int and float.

Since:
1.0
See Also:
Constant Field Values

SEARCH_SCALE_FUZZY_LINEAR

public static final short SEARCH_SCALE_FUZZY_LINEAR
Search with a linear scale. Default.

Since:
1.0
See Also:
Constant Field Values

SEARCH_SCALE_FUZZY_LOGARITHMIC

public static final short SEARCH_SCALE_FUZZY_LOGARITHMIC
Search with a logarithmic scale

Since:
1.0
See Also:
Constant Field Values

SEARCH_SCALE_FLAT

public static final short SEARCH_SCALE_FLAT
Search with a "flat" scale - if the hit is not exact it is treated as maximum distance

Since:
1.0
See Also:
Constant Field Values

SEARCH_SCALE_STRICT

public static final short SEARCH_SCALE_STRICT
Search "strict" - if the hit is not exact the case is not included in the result at all

Since:
1.0
See Also:
Constant Field Values

SEARCH_OPTION_INVERTED

public static final int SEARCH_OPTION_INVERTED
Should the search result be inverted?

Since:
1.0
See Also:
Constant Field Values
Constructor Detail

CBR

public CBR()
Constructor that initiates the CBR with no data.

Since:
1.0

CBR

public CBR(java.lang.String logfile,
           boolean verbose,
           boolean silent)
Constructor that initiates the CBR with no data

Parameters:
logfile - path to the file to write log information to. May be set to "null" which means no logging.
verbose - if true then extra verbose information is added to the logfile
silent - if true then no information is output to standard error
Since:
1.0

CBR

public CBR(java.lang.String datafile,
           java.lang.String logfile,
           boolean verbose,
           boolean silent)
    throws java.io.IOException
Constructor that initiates the CBR with data

Parameters:
datafile - path to the datafile
logfile - path to the file to write log information to. May be set to "null" which means no logging.
verbose - if true then extra verbose information is added to the logfile
silent - if true then no information is output to standard error
Throws:
java.io.IOException - if unable to read file
Since:
1.0
Method Detail

getVerbose

public boolean getVerbose()
Returns the verbose state

Returns:
the verbose state (true/false)
Since:
1.0

setVerbose

public void setVerbose(boolean verbose)
Sets the verbose state

Parameters:
verbose - the verbose state to assume
Since:
1.0

getSilent

public boolean getSilent()
Returns the silence state

Returns:
the silence state (true/false)
Since:
1.0

setSilent

public void setSilent(boolean silent)
Sets the silence state

Parameters:
silent - the silence state to assume
Since:
1.0

getLogfile

public java.lang.String getLogfile()
Returns the name of the current log file

Returns:
the current log file name
Since:
1.0

setLogfile

public void setLogfile(java.lang.String logfile)
Sets the log file to the specified path

Parameters:
logfile - file to use as log file
Since:
1.0

getDatafile

public java.lang.String getDatafile()
Returns the name of the data file currently in use

Returns:
the current data file
Since:
1.0

setDatafile

public void setDatafile(java.lang.String datafile)
Sets the data file. To activate the change, call readData() after the data file is set. You might also consider the method initialize()

Parameters:
datafile - file to use as input data file
Since:
1.0
See Also:
readData(), initialize(String, String)

readData

public void readData()
              throws java.io.IOException,
                     FreeCBR.NoDataException
Reads the data from the datafile. If you want to read a new data file, first call setDatafile() and then readData().
It is also possible to use the method initialize() instead.

Throws:
java.io.IOException - if unable to read from the current data file
NoDataException - if no fileHandler previously specified
Since:
1.0
See Also:
setDatafile(String), initialize(String, String)

initialize

public void initialize(java.lang.String datafile,
                       java.lang.String logfile)
                throws java.io.IOException
Initializes the CBR if not already done. Same as setLogfile() and setDatafile() followed by readData(). It is safe to call this method several times, if the arguments are the same nothing happens and the data file is NOT reread

Parameters:
datafile - file to use as input data file. If null then a new empty case set is created. If the datafile already was specified with the same value nothing happens
logfile - file to use for logging. If null or the log file already was specified with the same value nothing happens.
Throws:
java.io.IOException - if an error occurs when reading the data file
Since:
1.0
See Also:
setLogfile(String), setDatafile(String), readData()

getINFINITY_CONSTANT

public int getINFINITY_CONSTANT()
Returns the current infinity constant

Returns:
the current infinity constant
Since:
1.0
See Also:
INFINITY_CONSTANT

setINFINITY_CONSTANT

public void setINFINITY_CONSTANT(int infinity)
Sets the infinity constant

Parameters:
infinity - integer to use as infinity
Since:
1.0
See Also:
INFINITY_CONSTANT

getNumCases

public int getNumCases()
Returns the number of cases in current set

Returns:
the number of cases in current set
Since:
1.0

getNumFeatures

public int getNumFeatures()
Returns the number of features that each case has. All cases always have the same number of features.

Returns:
the number of features of the cases
Since:
1.0

addCase

public void addCase(java.lang.String caseString)
Adds a case to the set

Parameters:
caseString - a string describing the case to add. Tab separated string with the feature values in correct order. MultiString values are separated by semicolons. An example might be "HP[tab]1000.5[tab]CD-RW;DVD;Scanner"
Since:
1.0

addCase

public void addCase(Feature[] features)
Adds a case to the set

Parameters:
features - an array of features for the case to add
Since:
1.0
See Also:
Feature

getCase

public Feature[] getCase(int caseNum)
                  throws FreeCBR.NoDataException
Returns the case at the specified position

Parameters:
caseNum - the number of the case to retrieve (0-based)
Returns:
the specified case
Throws:
NoDataException - when no data is in case base
Since:
1.0

editCase

public Feature[] editCase(int caseNum,
                          Feature[] features)
Replaces specified case with another

Parameters:
caseNum - the number of the case to replace
features - the features of the new case
Returns:
the replaced case, null on error
Since:
1.0

removeCase

public Feature[] removeCase(int caseNum)
Removes the specified case from the set

Parameters:
caseNum - the number of the case to delete
Returns:
the deleted case
Since:
1.0

addFeature

public void addFeature(java.lang.String name,
                       short type)
Adds a feature (column) to the set. Pretty "expensive" - takes a few clock cycles..

Parameters:
name - the name of the new feature
type - the type of the new feature
Since:
1.0

getFeatureValue

public Feature getFeatureValue(int caseNum,
                               int featureNum)
                        throws FreeCBR.NoDataException
Returns the specified feature of the specified case

Parameters:
caseNum - the number of the case to retrieve
featureNum - the number of the feature to retrieve
Returns:
the specified feature
Throws:
NoDataException - when no data is read
Since:
1.0

getFeatureValueAX

public java.lang.String getFeatureValueAX(int caseNum,
                                          int featureNum)
                                   throws FreeCBR.NoDataException
Returns the specified feature of the specified case. Primarily used when ActiveX component.

Parameters:
caseNum - the number of the case to retrieve
featureNum - the number of the feature to retrieve
Returns:
the specified feature
Throws:
NoDataException - when no data is read
Since:
1.0

setFeatureValue

public void setFeatureValue(int caseNum,
                            int featureNum,
                            java.lang.String value)
                     throws FreeCBR.NoDataException
Sets the specified feature of the specified case to the specified value

Parameters:
caseNum - the number of the case to change
featureNum - the number of the feature to change
value - new value to use
Throws:
NoDataException - when no data is read
Since:
1.0

getFeatureName

public java.lang.String getFeatureName(int featureNum)
                                throws FreeCBR.NoDataException
Returns the name of the specified feature

Parameters:
featureNum - the number of the feature which name to retrieve
Returns:
the name of the feature
Throws:
NoDataException - when no data is read
Since:
1.0

setFeatureName

public void setFeatureName(int featureNum,
                           java.lang.String newName)
                    throws FreeCBR.NoDataException
Sets the name of the specified feature to the specified value

Parameters:
featureNum - the number of the feature which name to change
newName - the new feature name to use
Throws:
NoDataException - when no data is read
Since:
1.0

getFeatureNum

public int getFeatureNum(java.lang.String featureName)
                  throws FreeCBR.NoDataException
Returns the number of the feature that carries the specified name

Parameters:
featureName - the name of the feature
Returns:
the number of the feature, -1 if the feature is not found
Throws:
NoDataException - when no data is read
Since:
1.0

getFeatureType

public short getFeatureType(int featureNum)
                     throws FreeCBR.NoDataException
Returns the datatype of the specified feature

Parameters:
featureNum - the number of the feature which type to retrieve
Returns:
the feature type
Throws:
NoDataException - when no data is read
Since:
1.0
See Also:
Feature

setFeatureType

public void setFeatureType(int featureNum,
                           short newType)
                    throws FreeCBR.NoDataException
Sets the datatype of the specified feature

Parameters:
featureNum - the number of the feature which type to change
newType - the feature type
Throws:
NoDataException - when no data is read
Since:
1.0
See Also:
Feature

removeFeature

public void removeFeature(int featureNumber)
Deletes a feature (column) from the set. Pretty "expensive".

Parameters:
featureNumber - the number of the feature to delete
Since:
1.0

getUsedStringValues

public java.lang.String[] getUsedStringValues(int featureNum)
                                       throws FreeCBR.IllegalTypeException,
                                              FreeCBR.NoDataException
Returns all of the string values used at specified feature, works for String and MultiString features

Parameters:
featureNum - the number of the feature which string values to retrieve
Returns:
all string values in use, null if there are no strings
Throws:
NoDataException - when no data is read
IllegalTypeException - if the feature type is not String or MultiString
Since:
1.0

getUsedStringValuesAX

public java.lang.String getUsedStringValuesAX(int featureNum,
                                              java.lang.String separator)
                                       throws FreeCBR.IllegalTypeException,
                                              FreeCBR.NoDataException
Returns all of the string values used at specified feature, works for String and MultiString features. Used when ActiveX component

Parameters:
featureNum - the number of the feature which string values to retrieve
separator - the separator to use
Returns:
all string values in use, separated by the separator, null if there are no strings
Throws:
NoDataException - when no data is read
IllegalTypeException - if the feature type is not String or MultiString
Since:
1.0

getMinIntValue

public long getMinIntValue(int featureNum)
                    throws FreeCBR.IllegalTypeException,
                           FreeCBR.NoDataException
Returns the minimum integer value of all cases for the specified feature

Parameters:
featureNum - the number of the feature which minimum value is to retrieve
Returns:
the minimum value
Throws:
IllegalTypeException - if feature not of type Int
NoDataException - when no data is read
Since:
1.0

getMaxIntValue

public long getMaxIntValue(int featureNum)
                    throws FreeCBR.IllegalTypeException,
                           FreeCBR.NoDataException
Returns the maximum integer value of all cases for the specified feature

Parameters:
featureNum - the number of the feature which maximum value is to retrieve
Returns:
the maximum value
Throws:
IllegalTypeException - if feature not of type Int
NoDataException - when no data is read
Since:
1.0

getMinFloatValue

public double getMinFloatValue(int featureNum)
                        throws FreeCBR.IllegalTypeException,
                               FreeCBR.NoDataException
Returns the minimum floating point value of all cases for the specified feature

Parameters:
featureNum - the number of the feature which minimum value is to retrieve
Returns:
the minimum value
Throws:
IllegalTypeException - if feature not of type Float
NoDataException - when no data is read
Since:
1.0

getMaxFloatValue

public double getMaxFloatValue(int featureNum)
                        throws FreeCBR.IllegalTypeException,
                               FreeCBR.NoDataException
Returns the maximum floating point value of all cases for the specified feature

Parameters:
featureNum - the number of the feature which maximum value is to retrieve
Returns:
the minimum value
Throws:
IllegalTypeException - if feature not of type Float
NoDataException - when no data is read
Since:
1.0

saveSet

public void saveSet(java.lang.String filename,
                    boolean setDefault)
             throws java.io.IOException
Saves the entire case set

Parameters:
filename - name of the file to save as. If null then save to current file.
setDefault - sets the specified filename to default if true. Otherwise saves as the specified file name this time only.
Throws:
java.io.IOException - if an error occurs when saving the set
Since:
1.0

loadSet

public void loadSet(java.lang.String filename)
             throws java.lang.Exception
Loads a case set to memory

Parameters:
filename - name of the file to use.
Throws:
java.lang.Exception - if an error occurs when loading the set
Since:
1.0

newSet

public void newSet(java.lang.String[] featureNames,
                   java.lang.String[] featureTypeNames)
Empties the memory - deletes the current set from memory and creates a new empty set with the specified feature names and feature data types

Parameters:
featureNames - an array of feature names to use
featureTypeNames - an array of data type names to use (such as "String", "Float" and so on)
Since:
1.0
See Also:
Feature

search

public WebResult search(java.lang.Object req)
                 throws FreeCBR.NoDataException,
                        java.lang.Exception
Performs a search for the best match in a "web" way. Takes the servlet request part of an URL and tries to make the best of it.
The search parameters must be named featX, weightX, termX, scaleX and optionX where X is the number of the feature corresponding to this value An example could be
CBRBean.search(req) where req.getQueryString() might look like feat0=Compaq&scale0=0&feat3=1000&weight3=10

Parameters:
req - the servlet (or jsp) request. Must be javax.servlet.http.HttpServletRequest
Returns:
WebResult specifying both the result and what was actually searched for
Throws:
NoDataException - when not enough data is present
java.lang.Exception
Since:
1.0

searchAX

public java.lang.String searchAX(java.lang.Object[] searchFeatureNames,
                                 java.lang.Object[] searchValues,
                                 java.lang.Object[] searchWeights,
                                 java.lang.Object[] searchTerms,
                                 java.lang.Object[] searchScales,
                                 java.lang.Object[] searchOptions,
                                 java.lang.String resultSeparator,
                                 java.lang.String caseSeparator)
                          throws FreeCBR.NoDataException
Performs a search for the best match, used primarily by ActiveX components. Principle example:
search( {"Manufacurer", "Speed", "HDD", "CD"}, {"Compaq", "1000", "1.3", "?"}, {4, 6, 6, 5}, null, {0, 0, 0, 0}, {0, 0, 0, 0}, ":", ";")

Parameters:
searchFeatureNames - array of names of the features. Must be an array of Strings.
searchValues - array of strings describing the features to search for. Must be an array of Strings.
searchWeights - array of weights for the search, valid values are >0 where 0 means don't care. May be set to null which means alla features are equally important. Must be Null or an array of Integers.
searchTerms - array of terms of the search. May be any of
CBR.SEARCH_TERM_EQUAL, CBR.SEARCH_TERM_GREATER, CBR.SEARCH_TERM_GREATER_OR_EQUAL, CBR.SEARCH_TERM_LESS, CBR.SEARCH_TERM_LESS_OR_EQUAL, CBR.SEARCH_TERM_MAX, CBR.SEARCH_TERM_MIN and CBR.SEARCH_TERM_NOT_EQUAL. Default (when set to 0 or null) is CBR.SEARCH_TYPE_EQUAL. Must be Null or an array of Integers.
searchScales - array of the scale to use. May be any of CBR.SEARCH_SCALE_FUZZY_LINEAR, CBR.SEARCH_SCALE_FUZZY_LOGARITHMIC, CBR.SEARCH_SCALE_FLAT and CBR.SEARCH_SCALE_STRICT. Default (when set to 0 or null) is CBR.SEARCH_SCALE_FUZZY_LINEAR. Must be Null or an array of Integers.
searchOptions - array of options on how to perform the search. Default is no options. Must be Null or an array of Integers.
resultSeparator - string to use to separate the case number and the match percentage in the result
caseSeparator - string to use to separate the cases in the result
Returns:
string containing the result. If the resultSeparator is ":" and the caseSeparator is ";" the result might look like: "3:33.3;0:25;2:12.5;1:12.5;4:0" which would mean that the best match is case number 3 with a search hit of 33.3%, case number 0 has a hit rate of 25% and case number 1 and 2 have a hit rate of 12.5% each. Case number 4 has the lowest hit rate, 0%. The cases are always returned in decreasing hit order.
Throws:
NoDataException - when not enough data is present
Since:
1.0

search

public CBRResult[] search(java.lang.String[] searchFeatureNames,
                          java.lang.String[] searchValues,
                          int[] searchWeights,
                          int[] searchTerms,
                          int[] searchScales,
                          int[] searchOptions)
                   throws FreeCBR.NoDataException
Performs a search for the best match. Principle example:
search( {"Manufacurer", "Speed", "HDD", "CD"}, {"Compaq", "1000", "1.3", "?"}, {4, 6, 6, 5}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0})

Parameters:
searchFeatureNames - array of names of the features
searchValues - array of strings describing the features to search for
searchWeights - array of weights for the search, valid values are >0 where 0 means don't care. May be set to null which means alla features are equally important.
searchTerms - array of terms of the search. May be any of
CBR.SEARCH_TERM_EQUAL, CBR.SEARCH_TERM_GREATER, CBR.SEARCH_TERM_GREATER_OR_EQUAL, CBR.SEARCH_TERM_LESS, CBR.SEARCH_TERM_LESS_OR_EQUAL, CBR.SEARCH_TERM_MAX, CBR.SEARCH_TERM_MIN and CBR.SEARCH_TERM_NOT_EQUAL. Default (when set to 0 or null) is CBR.SEARCH_TYPE_EQUAL
searchScales - array of the scale to use. May be any of CBR.SEARCH_SCALE_FUZZY_LINEAR, CBR.SEARCH_SCALE_FUZZY_LOGARITHMIC, CBR.SEARCH_SCALE_FLAT and CBR.SEARCH_SCALE_STRICT. Default (when set to 0 or null) is CBR.SEARCH_SCALE_FUZZY_LINEAR.
searchOptions - array of options on how to perform the search. Default is no options.
Returns:
array of result, ordered by match
Throws:
NoDataException - when not enough data is present
Since:
1.0

search

public CBRResult[] search(int[] searchFeatureNumbers,
                          Feature[] searchValues,
                          int[] searchWeights,
                          int[] searchTerms,
                          int[] searchScales,
                          int[] searchOptions)
Performs a search for the best match.

Parameters:
searchFeatureNumbers - array of types of the features
searchValues - array of features to search for
searchWeights - array of weights for the search, valid values are 0 to 10 where 0 means don't care and 10 means "must match". May be set to null which means alla features are equally important.
searchTerms - array of terms of the search. May be any of
CBR.SEARCH_TERM_EQUAL, CBR.SEARCH_TERM_GREATER, CBR.SEARCH_TERM_GREATER_OR_EQUAL, CBR.SEARCH_TERM_LESS, CBR.SEARCH_TERM_LESS_OR_EQUAL, CBR.SEARCH_TERM_MAX, CBR.SEARCH_TERM_MIN and CBR.SEARCH_TERM_NOT_EQUAL. Default (when set to 0 or null) is CBR.SEARCH_TYPE_EQUAL
searchScales - array of the scale to use. May be any of CBR.SEARCH_SCALE_FUZZY_LINEAR, CBR.SEARCH_SCALE_FUZZY_LOGARITHMIC, CBR.SEARCH_SCALE_FLAT and CBR.SEARCH_SCALE_STRICT. Default (when set to 0 or null) is CBR.SEARCH_SCALE_FUZZY_LINEAR.
searchOptions - array of options on how to perform the search. Default is no options.
Returns:
array of result, ordered by match
Since:
1.0
See Also:
search(String[], String[], int[], int[], int[], int[])


Public Domain