Fido Alpha 3.2

fido.db
Class WordClassificationTable

java.lang.Object
  |
  +--fido.db.WordClassificationTable

public class WordClassificationTable
extends java.lang.Object

This class maintains a list of word classifications, which are patterns used to classify words based on the characters that compise it. The list of classifications are stored in an ordered table, so that the order of the patterns are maintained. Also, moveRowUp() and moveRowDown() can change the priority of a classification. The order is importantant, as more generic patterns near the end match a larger group of words.

Patterns:

CharacterDescription
N a number 0 to 9 repeating one to many times
A alpha character a to z and A to Z repeating one to many times
E Either number or alpha repeating one to many times. In practice, these are usually hostnames, variables, or some computer identifier. Therefore, this class will require the first character to be an alpha.
C Any character, exception forward slash and back slash, repeating one to many times. This type is used in Unix and Dos path names.
[] All chars listed optionally appearing once
{} Any char listed optionally appearing once
() All chars listend repeating at least once, possibly many times

The following table contains sample patterns of word classes:
(Note: Order in the patterns is significant. Therefore, more general patterns should appear at the bottom of the list)

PatternClass TypeNotes
$N[.N] Money value The '$' (dollar sign) is not a special character, therefore must be matched explicitly. The pattern reads: A word starting with a dollar sign, zero to many numbers, and optionally, a decimal point and more numbers.
N/N/N Date The slashes in this pattern must match explicitly.
(C/)C Unix path This pattern looks for any character besides a slash, as specified by the 'C'. Then matches a slash. This pattern can be repeated as many times as necessary. The final 'C' accepts any characters following the final slash. Since the letter classes, such as 'C', can match zero characters, the word can start or end in a slash.
[A:](C\)C Dos path Similar to the Unix path pattern, this pattern accepts an alpha character followed by a colon for Dos drive letters.
N:N Time Two numbers separated by a colon. Note the pattern does not require the first number to be in the range of 0 to 23. Nor does it limit the first number to be only two digits.
N.N.N.N IP Address As in the Time pattern, the individual components do not have to be valid ip numbers. This is one example where order in the table is important, because this pattern will catch four numbers separated by periods. The next pattern will catch four groups of characters if this pattern does not match.
E(.E) Internet hostname Matches a string of alpha and numeric characters, followed by at least one period, then more alpha and numeric chars. Matches internet hostnames such as www.yahoo.com
{+-}N[.N] Number The first part of this pattern allows either a plus or minus to precede the number, but does not require one.
E Default This is a catch all pattern if any of the above patterns fail to match.


Constructor Summary
WordClassificationTable()
          Creates a new WordClassificationTable instance.
 
Method Summary
 void add(java.lang.String pattern, java.lang.String grammarString, int objectId, java.lang.String description)
          Adds a new classification to the end of the list.
 WordSense classify(java.lang.String str)
          Attempts to match the list of patterns in the WordClassifications to the user string parameter.
 void delete(int row)
          Removes the new classification at the row specified in the row paramter.
 int hashCode(java.lang.String rank)
          Creates a hash value for a given row.
 java.util.Collection list()
          Returns a array of Strings containing all Word Classifications.
 void modify(int row, java.lang.String pattern, java.lang.String grammarString, int objectId, java.lang.String description)
          Replaces the new classification at the row specified in the row paramter with a row containing the parameter information.
 void moveRowDown(int row)
          Moves the row specified by row down in priority.
 void moveRowUp(int row)
          Moves the row specified by row up in priority.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WordClassificationTable

public WordClassificationTable()
Creates a new WordClassificationTable instance.

Method Detail

list

public java.util.Collection list()
                          throws FidoDatabaseException
Returns a array of Strings containing all Word Classifications. A row will contain the unique identifier, the pattern to match, and the word sense values: a grammar string and the link to the object in the ObjectList.

Returns:
list of all classifications fit to be displayed in a table
FidoDatabaseException

moveRowUp

public void moveRowUp(int row)
               throws FidoDatabaseException
Moves the row specified by row up in priority. The String row must be a number.

Throws:
java.sql.SQLException - Input / Output error saving WordClassifications object to database
FidoDatabaseException

moveRowDown

public void moveRowDown(int row)
                 throws FidoDatabaseException
Moves the row specified by row down in priority. The String row must be a number.

Throws:
FidoIOException - Input / Output error saving WordClassifications object to database
FidoDatabaseException

add

public void add(java.lang.String pattern,
                java.lang.String grammarString,
                int objectId,
                java.lang.String description)
         throws FidoDatabaseException,
                ObjectNotFoundException,
                GrammarParseException,
                GrammarLinkNotFoundException
Adds a new classification to the end of the list. Since the pattern is at the end, this will be the last pattern the word will be compared to. if any pattern above this one matches, this pattern will not be used.

Parameters:
pattern - Regular expression type string for matching word characters
Throws:
FidoIOException - Input / Output error saving WordClassifications object to database
FidoDatabaseException
ObjectNotFoundException
GrammarParseException
GrammarLinkNotFoundException

modify

public void modify(int row,
                   java.lang.String pattern,
                   java.lang.String grammarString,
                   int objectId,
                   java.lang.String description)
            throws FidoDatabaseException,
                   ObjectNotFoundException,
                   GrammarParseException,
                   GrammarLinkNotFoundException
Replaces the new classification at the row specified in the row paramter with a row containing the parameter information.

Parameters:
row - integer row value to replace
pattern - Regular expression type string for matching word characters
Throws:
FidoIOException - Input / Output error saving WordClassifications object to database
FidoDatabaseException
ObjectNotFoundException
GrammarParseException
GrammarLinkNotFoundException

delete

public void delete(int row)
            throws FidoDatabaseException
Removes the new classification at the row specified in the row paramter.

Parameters:
row - integer row value to replace
Throws:
FidoIOException - Input / Output error saving WordClassifications object to database
FidoDatabaseException

classify

public WordSense classify(java.lang.String str)
                   throws FidoDatabaseException,
                          GrammarParseException,
                          GrammarLinkNotFoundException
Attempts to match the list of patterns in the WordClassifications to the user string parameter. The first match that is found, a WordSense object is returned that contains a GrammarString to be used to insert the word into the sentence grammar, and a pointer to the object in the ObjectHierarchy that is used to represent the word in processing.

Returns:
A WordSense for this word pattern, null if no pattern matches
FidoDatabaseException
GrammarParseException
GrammarLinkNotFoundException

hashCode

public int hashCode(java.lang.String rank)
             throws FidoDatabaseException,
                    ClassificationNotFoundException
Creates a hash value for a given row. This is a unique integer value that represents all of the columns for that row. This is used by data entry servlets to ensure the row was not updated between the time the row data was downloaded, and the time the user sent the update.

Returns:
A unique integer representing the data for the row.
Throws:
FidoDatabaseException - Thrown if the database had an error.
ClassificationNotFoundException - Thrown if the parameters did not specify a row in the table.

Fido Alpha 3.2