public class ASDParser extends java.lang.Object implements ASDSemantics
Modifier and Type | Field and Description |
---|---|
java.lang.String |
ANYTHING
The string used to match anything at all in a given phrase
or phrase 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 and Description |
---|
ASDParser()
Initializes an ASDParser with no semantics or application.
|
ASDParser(java.lang.Object app)
Initializes an instance with the ASDParser itself to
interpret semantic actions and semantic values in the grammar,
and with application-specific messages to be sent to the
specified application.
|
ASDParser(java.lang.Object app,
ASDSemantics semanticsInstance)
Initializes an ASDParser 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.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
advance()
Attempts to advance the parse state one step.
|
boolean |
backup()
Attempts to backtrack the parse 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() |
java.lang.String |
bracketPhrase(ASDPhraseNode p) |
ASDPhraseNode |
currentNode() |
boolean |
done()
Tests whether or not a parse has been completed successfully.
|
java.util.ArrayList<java.lang.String> |
expectedTypes() |
java.util.HashMap<java.lang.String,java.lang.Object> |
features() |
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 ASDParser instance for parsing a given
string as one of a list of expected phrase types.
|
ASDGrammar |
lexicon() |
boolean |
parse()
Attempts to find next parse of current phrase structure.
|
int |
parse(int maxSteps)
Attempts to find next parse of current phrase structure
in a specified maximum number of advance steps.
|
int |
parseStepNumber() |
ASDPhraseNode |
phraseStructure() |
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 parsed.
|
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 parsed, provided they are compatible with feature
values already assigned.
|
ASDPhraseNode |
segment(java.lang.String aString)
Creates a phrase structure, a chain of ASDPhraseNodes,
each containing one word, number, punctuation mark, or
quoted string from the given String, with
a dummy header node at the beginning of the chain.
|
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 phrase 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 ASDParser 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 |
setSaveUniquelyParsedSubphrases(boolean save)
Tells the ASDParser instance whether or not to retain uniquely-parsed
subphrases when it backtracks.
|
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 parse of current phrase structure
in a specified maximum number of advance steps;
displays the parse tree to System.out after each step.
|
boolean |
useGrammar(ASDGrammar grammar)
Sets the ASDParser instance to use a given ASDGrammar.
|
boolean |
useGrammar(java.lang.String fileName)
Sets the ASDParser 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.
|
public java.lang.String ANYTHING
public java.lang.String CLOSEQUOTE
public java.lang.String DUMMYWORD
public java.lang.String NOADVANCE
public java.lang.String NO
public java.lang.String NUMBER
public java.lang.String OPENQUOTE
public java.lang.String QUIT
public java.lang.String SPACECHARS
public java.lang.String SPECIALCHARS
public java.lang.String STRING
public java.lang.String SUCCEED
public static java.lang.String UNKNOWN
public ASDParser()
public ASDParser(java.lang.Object app)
app
- the target for application-specific messagespublic ASDParser(java.lang.Object app, ASDSemantics semanticsInstance)
app
- the target for application-specific messagessemanticsInstance
- instance of a class that implements
ASDSemantics (null if none)public ASDPhraseNode currentNode()
public java.util.ArrayList<java.lang.String> expectedTypes()
public java.util.HashMap<java.lang.String,java.lang.Object> features()
public java.lang.Object get(java.lang.String featureName)
featureName
- the feature whose value is to be obtainedpublic ASDGrammar lexicon()
public ASDPhraseNode phraseStructure()
public int parseStepNumber()
public void set(java.lang.String featureName, java.lang.Object value)
featureName
- the feature whose value is to be setvalue
- the value to be assigned to featureNamepublic java.lang.Object valueOf(java.lang.String featureName)
featureName
- the feature whose value is to be obtainedpublic void initialize(java.lang.String aString, java.util.ArrayList<java.lang.String> expected)
aString
- the string to be parsedexpected
- an ArrayList of strings, each the name
of one of the expected phrase types.public java.lang.String advance()
public boolean backup()
public java.lang.String bracketPhrase()
public java.lang.String bracketPhrase(ASDPhraseNode p)
p
- an ASDPhraseNode in a phrase structurepublic boolean done()
public boolean parse()
public int parse(int maxSteps)
maxSteps
- the maximum number of steps permittedpublic void raiseFeatures()
public java.lang.String raiseFeaturesChecking()
public ASDPhraseNode segment(java.lang.String aString)
aString
- a string to be parsedpublic java.lang.String semanticAction(java.lang.String action)
semanticAction
in interface ASDSemantics
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.public java.lang.Object semanticValue(java.lang.String value)
semanticValue
in interface ASDSemantics
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.public void setANYTHING(java.lang.String newValue)
newValue
- is the new value used to match anythingpublic void setCLOSEQUOTE(java.lang.String newValue)
newValue
- is the new value used to end a quoted stringpublic void setNOADVANCE(java.lang.String newValue)
newValue
- is the new value to be returned when no
advance was possible for the parserpublic void setDUMMYWORD(java.lang.String newValue)
newValue
- is the new value which represents a dummy wordpublic void setNUMBER(java.lang.String newValue)
newValue
- is the new value which stands for a numeric valuepublic void setOPENQUOTE(java.lang.String newValue)
newValue
- is the new value which represents an open quotepublic void setQUIT(java.lang.String newValue)
newValue
- is the new value which is returned when parser quitspublic void setSaveUniquelyParsedSubphrases(boolean save)
save
- when true tells the parser to save uniquely-parsed subphrasespublic void setSPACECHARS(java.lang.String newValue)
newValue
- is the string of characters to be used as delimiterspublic void setSPECIALCHARS(java.lang.String newValue)
newValue
- is the string of characters to be recognized
as individual tokenspublic void setSTRING(java.lang.String newValue)
newValue
- is the string to stand for a quoted stringpublic void setSUCCEED(java.lang.String newValue)
newValue
- is the string to be returned when the parser
succeeds in completing a parsepublic void setUNKNOWN(java.lang.String newValue)
newValue
- is the string to represent an unknown wordpublic void showTree()
public void stepParse(int maxSteps)
maxSteps
- the maximum number of steps permittedpublic boolean useGrammar(ASDGrammar grammar)
grammar
- the grammar to be used.public boolean useGrammar(java.lang.String fileName)
fileName
- the name of the file containing the grammar.