Class Rule

java.lang.Object
  |
  +--Rule
All Implemented Interfaces:
java.util.Enumeration

public class Rule
extends java.lang.Object
implements java.util.Enumeration

The rule class describes a grammatical rule. It iterates through itself, successively returning the tokens of the rule in sequence.


Constructor Summary
Rule(Rule rule)
          Make a rule from a rule.
Rule(Rule rule, int offset)
          Make a rule from a rule, but add some amount to the index.
Rule(Rule rule, int offset, java.lang.String addInterp)
          Make a rule from a rule, but add some amount to the index and a string to the interpretation.
Rule(java.lang.String grammarLine)
          Creates a rule based on a string.
 
Method Summary
 java.lang.String consistencyCode()
          Get the consistencyCode of this rule.
 java.lang.String getBindings(java.util.LinkedList valuesList, java.lang.String initialString)
          Return a version of this rule's consistencyCode with all the variables bound.
 java.lang.String getBindings(java.util.LinkedList valuesList, java.lang.String initialString, boolean moreTags)
          Return a version of this rule's consistencyCode with all the variables bound.
static java.util.LinkedList getRules(java.lang.String fileName)
          Read the grammar rules file and return a linked list of rules.
 boolean hasMoreElements()
          Check if there are more elements in the list.
 java.lang.String interpretation()
          Get the interpretation of this rule.
 java.lang.Object nextElement()
          Get the next token of this rule.
 java.lang.Object peekElement()
          Peek at the next token of this rule.
 java.lang.String syntax()
          Get the syntactic role of this rule.
 java.lang.String toString()
          Print the rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rule

public Rule(java.lang.String grammarLine)
Creates a rule based on a string.

Parameters:
grammarLine - a string from the grammar. See the latest grammar file for format.
Throws:
java.lang.RuntimeException - for format problems.

Rule

public Rule(Rule rule)
Make a rule from a rule.

Parameters:
rule - the rule to copy.

Rule

public Rule(Rule rule,
            int offset)
Make a rule from a rule, but add some amount to the index.

Parameters:
rule - the rule to copy.
offset - amount to add to index.

Rule

public Rule(Rule rule,
            int offset,
            java.lang.String addInterp)
Make a rule from a rule, but add some amount to the index and a string to the interpretation.

Parameters:
rule - the rule to copy.
offset - amount to add to index.
addInterp - the string to add to the interpretation.
Method Detail

hasMoreElements

public boolean hasMoreElements()
Check if there are more elements in the list.

Specified by:
hasMoreElements in interface java.util.Enumeration
Returns:
true if there are more elements.

nextElement

public java.lang.Object nextElement()
Get the next token of this rule.

Specified by:
nextElement in interface java.util.Enumeration
Returns:
the next token of the rule.
Throws:
java.util.NoSuchElementException - if out.

peekElement

public java.lang.Object peekElement()
Peek at the next token of this rule.

Returns:
the next token of the rule.
Throws:
java.util.NoSuchElementException - if out.

consistencyCode

public java.lang.String consistencyCode()
Get the consistencyCode of this rule.

Returns:
the consistencyCode.

interpretation

public java.lang.String interpretation()
Get the interpretation of this rule.

Returns:
the interpretation.

syntax

public java.lang.String syntax()
Get the syntactic role of this rule.

Returns:
the syntactic role as defined in the grammar.

toString

public java.lang.String toString()
Print the rule.

Overrides:
toString in class java.lang.Object
Returns:
a string of the rule.

getBindings

public java.lang.String getBindings(java.util.LinkedList valuesList,
                                    java.lang.String initialString)
Return a version of this rule's consistencyCode with all the variables bound. The variables are stored in nameTokens, and their bindings are passed in. Note that it is an (undetected) error if two tokens have the same names, and this will bind the first value for that name to everything. Note also that variable names should not occur inside values, as this will bind unpredictably.

Parameters:
valuesList - the values to bind.
initialString - the string to bind on.
Returns:
the string with all variables bound.
Throws:
java.lang.RuntimeException - if the values list is too short to bind all the variables, or too long.

getBindings

public java.lang.String getBindings(java.util.LinkedList valuesList,
                                    java.lang.String initialString,
                                    boolean moreTags)
Return a version of this rule's consistencyCode with all the variables bound. The variables are stored in nameTokens, and their bindings are passed in. Note that it is an (undetected) error if two tokens have the same names, and this will bind the first value for that name to everything. Note also that variable names should not occur inside values, as this will bind unpredictably.

Parameters:
valuesList - the values to bind.
initialString - the string to bind on.
Returns:
the string with all variables bound.
Throws:
java.lang.RuntimeException - if the values list is too short to bind all the variables, or too long.

getRules

public static java.util.LinkedList getRules(java.lang.String fileName)
Read the grammar rules file and return a linked list of rules. See speech/domain/grammar for example lines.

Returns:
the rules derived from the line.