asd
Class ASDDecider

java.lang.Object
  extended by asd.ASDDecider
All Implemented Interfaces:
ASDSemantics

public class ASDDecider
extends java.lang.Object
implements ASDSemantics

Instances are decision network searchers that can load an ASDGrammar from a specified file and use it as a decision network.on an input string of decision tokens treated as an unordered set.

Author:
James A. Mason

Field Summary
 java.lang.String ANYTHING
          The string used to match anything at all in a given phrase or decision structure.
 java.lang.String CLOSEQUOTE
          The lexical token which is to be recognized as ending a quoted string.
 java.lang.String DUMMYWORD
          The string recognized as representing a dummy node/instance in a grammar.
 java.lang.String NO
          Abbreviation for NOADVANCE
 java.lang.String NOADVANCE
          A possible value returned by the advance() method.
 java.lang.String NUMBER
          The string used to stand in for numeric values in a grammar lexicon.
 java.lang.String OPENQUOTE
          The lexical token which is to be recognized as beginning a quoted string.
 java.lang.String QUIT
          A possible value returned by the advance() method.
 java.lang.String SPACECHARS
          Whitespace characters which are to be recognized as delimiters for lexical tokens but not as lexical tokens themselves.
 java.lang.String SPECIALCHARS
          Characters which are to be recognized as individual lexical tokens by the segment method.
 java.lang.String STRING
          The string used to stand in for quoted strings in a grammar lexicon.
 java.lang.String SUCCEED
          A possible value returned by the advance() method.
static java.lang.String UNKNOWN
          The string used to stand in for lexical tokens which are not found in a given grammar lexicon.
 
Constructor Summary
ASDDecider()
          Initializes an ASDDecider with no semantics or application.
ASDDecider(java.lang.Object app)
          Initializes an instance with the ASDDecider itself to interpret semantic actions and semantic values in the grammar, and with application-specific messages to be sent to the specified application, if desired.
ASDDecider(java.lang.Object app, ASDSemantics semanticsInstance)
          Initializes an ASDDecider instance with a reference to a given application to which application-specific messages are to be sent, and a given instance of a class that implements the ASDSemantics interface.
 
Method Summary
 java.lang.String advance()
          Attempts to advance the search state one step.
 boolean backup()
          Attempts to backtrack the search state to the most recent place where a local ambiguity occurred -- that is, where there was more than one choice for advancing.
 java.lang.String bracketPhrase()
          Returns a string showing the current utterance string with parentheses around each subphrase of more than one non-dummy word.
 java.lang.String bracketPhrase(ASDPhraseNode p)
          Returns a string with parentheses around each subphrase of p with length > 1.
 java.util.HashSet<java.lang.String> createDecisionSet(java.lang.String aString)
          Creates a decision set of tokens from the given String.
 ASDPhraseNode currentNode()
          Returns the current Node at the top level in the decision structure.
 ASDPhraseNode decisionStructure()
          Returns the header node of the current decision structure.
 boolean done()
          Tests whether or not a search has been completed successfully.
 java.util.ArrayList<java.lang.String> expectedTypes()
          Returns the decider's current list of expected phrase types for the top level of a search.
 java.util.HashMap<java.lang.String,java.lang.Object> features()
          Returns the feature-value pairs for the current top level of the decision structure.
 java.lang.Object get(java.lang.String featureName)
          Returns the value of 'feature' with specified name.
 void initialize(java.lang.String aString, java.util.ArrayList<java.lang.String> expected)
          Initialize the ASDDecider instance for searching a given string of decision values as one of a list of expected decision types.
 ASDGrammar lexicon()
          Returns the ASDGrammar (decision network) which is currently being used by the decider.
 boolean parse()
          Attempts to find next search of current decision structure.
 int parse(int maxSteps)
          Attempts to find next search of current decision structure in a specified maximum number of advance steps.
 int parseStepNumber()
          Returns the number of the current step in a search.
 void raiseFeatures()
          Copies the feature-value pairs from the current node value (which must be a Map) to the current top level of the phrase structure being searched.
 java.lang.String raiseFeaturesChecking()
          Copies the feature-value pairs from the current node value (which must be a Map) to the current top level of the phrase structure being searched, provided they are compatible with feature values already assigned.
 java.lang.String semanticAction(java.lang.String action)
          Evaluates a string from a "semantic action" field in an ASDGrammar, by invoking the corresponding method of the application object.
 java.lang.Object semanticValue(java.lang.String value)
          Evaluates a string from a "semantic value" field in an ASDGrammar, as a long integer number, a quoted string, or by invoking the method of the application object which is named by the semantic value field.
 void set(java.lang.String featureName, java.lang.Object value)
          Sets contents of a 'feature' with the specified name to the specified value.
 void setANYTHING(java.lang.String newValue)
          Resets the string which is used to match anything at all in a given phrase or decision structure.
 void setCLOSEQUOTE(java.lang.String newValue)
          Resets the lexical token which is to be recognized as ending a quoted string.
 void setDUMMYWORD(java.lang.String newValue)
          Resets the string which is recognized by the ASDDecider as representing a "dummy" word in the grammar -- used in the labels on dummy nodes.
 void setNOADVANCE(java.lang.String newValue)
          Sets the NOADVANCE (== NO) value which may be returned by the advance method to a new value preferred by the client.
 void setNUMBER(java.lang.String newValue)
          Resets the string used to stand in for numeric values in a grammar lexicon.
 void setOPENQUOTE(java.lang.String newValue)
          Resets the lexical token which is to be recognized as beginning a quoted string.
 void setQUIT(java.lang.String newValue)
          Sets the QUIT value which may be returned by the advance method to a new value preferred by the client.
 void setSPACECHARS(java.lang.String newValue)
          Resets the string of characters which are to be recognized as delimiters for lexical tokens but not as lexical tokens themselves.
 void setSPECIALCHARS(java.lang.String newValue)
          Resets the string of characters which are to be recognized as individual lexical tokens by the segment method.
 void setSTRING(java.lang.String newValue)
          Resets the string used to stand in for quoted strings in a grammar lexicon.
 void setSUCCEED(java.lang.String newValue)
          Sets the SUCCEED value which may be returned by the advance method to a new value preferred by the client.
 void setUNKNOWN(java.lang.String newValue)
          Resets the string used to stand in for words which are not found in a given grammar lexicon.
 void showTree()
          Displays the current parse tree to the console, with a -> pointer to the current node at the top level
 void stepParse(int maxSteps)
          Attempts to find next search of current decision structure in a specified maximum number of advance steps; displays the decision structure to System.out after each step.
 boolean useNetwork(ASDGrammar network)
          Sets the ASDDecider instance to use a given decision network, in the form of an ASDGrammar.
 boolean useNetwork(java.lang.String fileName)
          Sets the ASDDecider instance to use an ASDGrammar loaded from a specified file.
 java.lang.Object valueOf(java.lang.String featureName)
          Returns the value of 'feature' with specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANYTHING

public java.lang.String ANYTHING
The string used to match anything at all in a given phrase or decision structure. By default it is equal to "ANYTHING".


CLOSEQUOTE

public java.lang.String CLOSEQUOTE
The lexical token which is to be recognized as ending a quoted string. The default is ".


DUMMYWORD

public java.lang.String DUMMYWORD
The string recognized as representing a dummy node/instance in a grammar. By default it is equal to ASDGrammar.DUMMYWORD.


NOADVANCE

public java.lang.String NOADVANCE
A possible value returned by the advance() method. It indicates that an attempt to advance the parse one step has failed, and backup should be performed if possible.


NO

public java.lang.String NO
Abbreviation for NOADVANCE


NUMBER

public java.lang.String NUMBER
The string used to stand in for numeric values in a grammar lexicon. By default it is equal to "NUMBER".


OPENQUOTE

public java.lang.String OPENQUOTE
The lexical token which is to be recognized as beginning a quoted string. The default is ".


QUIT

public java.lang.String QUIT
A possible value returned by the advance() method. It indicates that the parse cannot succeed and should be terminated with failure.


SPACECHARS

public java.lang.String SPACECHARS
Whitespace characters which are to be recognized as delimiters for lexical tokens but not as lexical tokens themselves. Note: Other Unicode whitespace characters are NOT recognized as delimiters but ARE trimmed from the beginnings and ends of lexical tokens, if present.


SPECIALCHARS

public java.lang.String SPECIALCHARS
Characters which are to be recognized as individual lexical tokens by the segment method. The default value is ",.;:?!$@#%&*()[]{}+=<>/~\\".


STRING

public java.lang.String STRING
The string used to stand in for quoted strings in a grammar lexicon. By default it is equal to "STRING".


SUCCEED

public java.lang.String SUCCEED
A possible value returned by the advance() method. It indicates that an attempt to advance the parse one step has been successful.


UNKNOWN

public static java.lang.String UNKNOWN
The string used to stand in for lexical tokens which are not found in a given grammar lexicon. By default it is equal to "UNKNOWN".

Constructor Detail

ASDDecider

public ASDDecider()
Initializes an ASDDecider with no semantics or application.


ASDDecider

public ASDDecider(java.lang.Object app)
Initializes an instance with the ASDDecider itself to interpret semantic actions and semantic values in the grammar, and with application-specific messages to be sent to the specified application, if desired.

Parameters:
app - the target for application-specific messages

ASDDecider

public ASDDecider(java.lang.Object app,
                  ASDSemantics semanticsInstance)
Initializes an ASDDecider instance with a reference to a given application to which application-specific messages are to be sent, and a given instance of a class that implements the ASDSemantics interface.

Parameters:
app - the target for application-specific messages
semanticsInstance - instance of a class that implements ASDSemantics (null if none)
Method Detail

currentNode

public ASDPhraseNode currentNode()
Returns the current Node at the top level in the decision structure.


expectedTypes

public java.util.ArrayList<java.lang.String> expectedTypes()
Returns the decider's current list of expected phrase types for the top level of a search.


features

public java.util.HashMap<java.lang.String,java.lang.Object> features()
Returns the feature-value pairs for the current top level of the decision structure.


get

public java.lang.Object get(java.lang.String featureName)
Returns the value of 'feature' with specified name. Same as the valueOf method.

Parameters:
featureName - the feature whose value is to be obtained
Returns:
the value of the feature; null if none

lexicon

public ASDGrammar lexicon()
Returns the ASDGrammar (decision network) which is currently being used by the decider.


decisionStructure

public ASDPhraseNode decisionStructure()
Returns the header node of the current decision structure.


parseStepNumber

public int parseStepNumber()
Returns the number of the current step in a search.


set

public void set(java.lang.String featureName,
                java.lang.Object value)
Sets contents of a 'feature' with the specified name to the specified value.

Parameters:
featureName - the feature whose value is to be set
value - the value to be assigned to featureName

valueOf

public java.lang.Object valueOf(java.lang.String featureName)
Returns the value of 'feature' with specified name. Same as the get method.

Parameters:
featureName - the feature whose value is to be obtained
Returns:
the value of the feature; null if none

initialize

public void initialize(java.lang.String aString,
                       java.util.ArrayList<java.lang.String> expected)
Initialize the ASDDecider instance for searching a given string of decision values as one of a list of expected decision types.

Parameters:
aString - the string to be searched
expected - an ArrayList of strings, each the name of one of the expected decision types.

advance

public java.lang.String advance()
Attempts to advance the search state one step.

Returns:
SUCCEED if successful, NOADVANCE if unsuccessful but search should continue after backup, QUIT if search should quit.

backup

public boolean backup()
Attempts to backtrack the search state to the most recent place where a local ambiguity occurred -- that is, where there was more than one choice for advancing.

Returns:
true if backtrack is successful, false if there was no step in the search to which to backtrack

bracketPhrase

public java.lang.String bracketPhrase()
Returns a string showing the current utterance string with parentheses around each subphrase of more than one non-dummy word.


bracketPhrase

public java.lang.String bracketPhrase(ASDPhraseNode p)
Returns a string with parentheses around each subphrase of p with length > 1.

Parameters:
p - an ASDPhraseNode in a decision structure

createDecisionSet

public java.util.HashSet<java.lang.String> createDecisionSet(java.lang.String aString)
Creates a decision set of tokens from the given String.

Parameters:
aString - a string to be searched
Returns:
the resulting set

done

public boolean done()
Tests whether or not a search has been completed successfully.

Returns:
true if successful, false if not.

parse

public boolean parse()
Attempts to find next search of current decision structure.

Returns:
true if successful, false if unsuccessful

parse

public int parse(int maxSteps)
Attempts to find next search of current decision structure in a specified maximum number of advance steps.

Parameters:
maxSteps - the maximum number of steps permitted
Returns:
positive number of steps required if successful, negative number of steps performed if unsuccessful

raiseFeatures

public void raiseFeatures()
Copies the feature-value pairs from the current node value (which must be a Map) to the current top level of the phrase structure being searched.


raiseFeaturesChecking

public java.lang.String raiseFeaturesChecking()
Copies the feature-value pairs from the current node value (which must be a Map) to the current top level of the phrase structure being searched, provided they are compatible with feature values already assigned. Return SUCCEED if they are, NOADVANCE if they are not compatible. Return QUIT if the current node value is not a Map.


semanticAction

public java.lang.String semanticAction(java.lang.String action)
Evaluates a string from a "semantic action" field in an ASDGrammar, by invoking the corresponding method of the application object.

Specified by:
semanticAction in interface ASDSemantics
Parameters:
action - the semantic action string to be evaluated; the name of a public method in the application class, one with no parameters that returns a String.
Returns:
the String returned by the method invoked in the application class; possibly the NOADVANCE or QUIT string.

semanticValue

public java.lang.Object semanticValue(java.lang.String value)
Evaluates a string from a "semantic value" field in an ASDGrammar, as a long integer number, a quoted string, or by invoking the method of the application object which is named by the semantic value field.

Specified by:
semanticValue in interface ASDSemantics
Parameters:
value - the semantic value string to be evaluated, an integer, a string surrounded by double quotes, or the name of a public method in the application class, one with no parameters that returns a String.
Returns:
the Object returned by the method invoked in the application class; possibly the NOADVANCE or QUIT string.

setANYTHING

public void setANYTHING(java.lang.String newValue)
Resets the string which is used to match anything at all in a given phrase or decision structure.


setCLOSEQUOTE

public void setCLOSEQUOTE(java.lang.String newValue)
Resets the lexical token which is to be recognized as ending a quoted string.


setNOADVANCE

public void setNOADVANCE(java.lang.String newValue)
Sets the NOADVANCE (== NO) value which may be returned by the advance method to a new value preferred by the client.


setDUMMYWORD

public void setDUMMYWORD(java.lang.String newValue)
Resets the string which is recognized by the ASDDecider as representing a "dummy" word in the grammar -- used in the labels on dummy nodes.


setNUMBER

public void setNUMBER(java.lang.String newValue)
Resets the string used to stand in for numeric values in a grammar lexicon.


setOPENQUOTE

public void setOPENQUOTE(java.lang.String newValue)
Resets the lexical token which is to be recognized as beginning a quoted string.


setQUIT

public void setQUIT(java.lang.String newValue)
Sets the QUIT value which may be returned by the advance method to a new value preferred by the client.


setSPACECHARS

public void setSPACECHARS(java.lang.String newValue)
Resets the string of characters which are to be recognized as delimiters for lexical tokens but not as lexical tokens themselves. For the initialize method to work properly, these should all be Unicode whitespace characters.


setSPECIALCHARS

public void setSPECIALCHARS(java.lang.String newValue)
Resets the string of characters which are to be recognized as individual lexical tokens by the segment method.


setSTRING

public void setSTRING(java.lang.String newValue)
Resets the string used to stand in for quoted strings in a grammar lexicon.


setSUCCEED

public void setSUCCEED(java.lang.String newValue)
Sets the SUCCEED value which may be returned by the advance method to a new value preferred by the client.


setUNKNOWN

public void setUNKNOWN(java.lang.String newValue)
Resets the string used to stand in for words which are not found in a given grammar lexicon.


showTree

public void showTree()
Displays the current parse tree to the console, with a -> pointer to the current node at the top level


stepParse

public void stepParse(int maxSteps)
Attempts to find next search of current decision structure in a specified maximum number of advance steps; displays the decision structure to System.out after each step.

Parameters:
maxSteps - the maximum number of steps permitted negative number of steps performed if unsuccessful

useNetwork

public boolean useNetwork(ASDGrammar network)
Sets the ASDDecider instance to use a given decision network, in the form of an ASDGrammar.

Parameters:
network - the network to be used.
Returns:
true if network is not null, false if network is null.

useNetwork

public boolean useNetwork(java.lang.String fileName)
Sets the ASDDecider instance to use an ASDGrammar loaded from a specified file.

Parameters:
fileName - the name of the file containing the network.
Returns:
true if successful, false if the network cannot be loaded successfully from the file.