Fido Alpha 3.2

fido.grammar
Class GrammarStack

java.lang.Object
  |
  +--fido.grammar.GrammarStack

public class GrammarStack
extends java.lang.Object

Each SentenceThread contains a GrammarStack that is used to push and pop StackElements. Each StackElement represents a grammar expression. Grammar will push a new open link as a new StackElement onto the GrammarStack. Each close link will attempt to find the next matching link on the GrammarStack.

Internally, the Grammar stack has a StackElement for the head of the stack and a hold element. The hold element will be the next element to push onto the stack. If the element is immediately pushed onto the stack, it is possible the Grammar module will match a close link with an open link in the same word.

See Also:
StackElement, Grammar

Constructor Summary
GrammarStack()
          Creates a new empty GrammarStack instance.
 
Method Summary
 GrammarStack cloneGrammarStack()
          Makes a deep copy of the GrammarStack.
 java.util.Iterator elementIterator()
          Returns an iterator over the StackElements in this stack.
 StackElement getHeadElement()
          Returns the element at the top of the stack.
 void holdExpression(NodeExpression exp, WordSense sense)
          Stores an open link on the stack in the hold area.
 boolean isEmpty()
          Tests the stack to be empty.
 void push()
          Puts the hold element onto the top of the stack.
 WordSense traverseStack(java.lang.String str)
          Starts with the top of the stack and looks for an open link element matching the parameter string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrammarStack

public GrammarStack()
Creates a new empty GrammarStack instance.

Method Detail

push

public void push()
Puts the hold element onto the top of the stack.


traverseStack

public WordSense traverseStack(java.lang.String str)
Starts with the top of the stack and looks for an open link element matching the parameter string. The element matches if the head element contains a string that matches the parameter. If the head element does not match, the head node may be a multi-match node. If the multi-node has already been used, it is legal to remove the node from the stack and continue to look for a match.

If the node matches, and it is a multi-node, the node is set to being used at least once. If it is not a multi-node, it is removed from the stack.

Parameters:
str - String value of the open link to look for on the stack
Returns:
The WordSense for the element that matches the close link string in the parameter.
See Also:
NodeExpression.setMultiNodeUsed()

holdExpression

public void holdExpression(NodeExpression exp,
                           WordSense sense)
Stores an open link on the stack in the hold area. Links in the hold area cannot be used to match close links. This prevents an open link to match a close link within the same word.

Parameters:
exp - Expression to hold.
sense - WordSense to store along with the expression

isEmpty

public boolean isEmpty()
Tests the stack to be empty. Empty is defined as either:

Returns:
True if the stack is empty. False otherwise.
See Also:
StackElement.allExpressionsUsed()

getHeadElement

public StackElement getHeadElement()
Returns the element at the top of the stack. This will not return the hold element.

Returns:
StackElement at the top of the stack.

elementIterator

public java.util.Iterator elementIterator()
Returns an iterator over the StackElements in this stack.

Returns:
Iterator for the StackElements

cloneGrammarStack

public GrammarStack cloneGrammarStack()
Makes a deep copy of the GrammarStack. This needs to be a deep copy because elements of the stack are modified during processing. Creating a new object separates the data between SentenceThreads.

Returns:
A new copy of the GrammarStack.

Fido Alpha 3.2