ch.uzh.ifi.attempto.chartparser
Class ChartParser

java.lang.Object
  extended by ch.uzh.ifi.attempto.chartparser.ChartParser
All Implemented Interfaces:
PredictiveParser

public class ChartParser
extends java.lang.Object
implements PredictiveParser

This is a chart parser (concretely an Earley parser) that implements the predictive parser interface.

Author:
Tobias Kuhn
See Also:
Grammar

Constructor Summary
ChartParser(Grammar grammar, java.lang.String startCategoryName)
          Creates a new chart parser for the given grammar.
ChartParser(Grammar grammar, java.lang.String startCategoryName, java.util.List<Nonterminal> context)
          Creates a new chart parser for the given grammar.
 
Method Summary
 void addToken(java.lang.String token)
          Adds the token to the end of the token sequence.
 void addTokens(java.util.List<java.lang.String> tokens)
          Adds the tokens to the token list.
 void debug(boolean debug)
          This method can be used to switch on/off debug mode (default is off).
 java.util.Set<CPAbstractOption> getAbstractOptions()
          This method returns a set of abstract options describing the possible next tokens at the end position in an abstract way.
 java.util.Set<CPAbstractOption> getAbstractOptions(int position)
          This method returns a set of abstract options describing the possible next tokens at the given position in an abstract way.
 java.util.List<FeatureMap> getBackwardReferences()
          Returns a list of feature maps that show how the backward references at the end of the token sequence can be resolved.
 java.util.List<FeatureMap> getBackwardReferences(int pos)
          Return a list of feature maps that show how the backward references at the given position in the text can be resolved.
 java.util.Set<CPConcreteOption> getConcreteOptions()
          This method returns a set of concrete options describing the possible next tokens at the end position in a concrete way.
 java.util.Set<CPConcreteOption> getConcreteOptions(int position)
          This method returns a set of concrete options describing the possible next tokens at the given position in a concrete way.
 CPNextTokenOptions getNextTokenOptions()
          This method returns the options for the next token to be added at the end.
 CPNextTokenOptions getNextTokenOptions(int position)
          This methods shows the possible tokens that could be used to continue the text at the given position.
 ParseTree getParseTree()
          Returns the parse tree of the parsed text if it is a complete statement according to the given grammar and start category.
 ParseTree getParseTree(java.lang.String categoryName)
          Returns the parse tree of the parsed text if it is a complete statement according to the given grammar and category.
 int getReference()
          This method should return the token number to which the last token refers, if it is a reference like "it".
 int getReference(int pos)
          This method returns the token number to which the token at the given position refers, if it is a reference.
 int getTokenCount()
          Returns the number of tokens of the current (partial) text.
 java.util.List<java.lang.String> getTokens()
          Returns the current token sequence.
 boolean isComplete()
          Returns true if the current token sequence is a complete statement.
 boolean isPossibleNextToken(java.lang.String token)
          Returns whether the given token is a possible next token.
 void removeAllTokens()
          Removes all tokens in the current token sequence.
 void removeToken()
          Removes the last token.
 void setDynamicLexicon(DynamicLexicon dynLexicon)
          Sets the dynamic lexicon.
 void setPositionIdentifierPrefix(java.lang.String prefix)
          Sets the prefix for the position identifiers that are assigned to the variables of the position operator "#".
 void setTokens(java.util.List<java.lang.String> tokens)
          Sets the given tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartParser

public ChartParser(Grammar grammar,
                   java.lang.String startCategoryName,
                   java.util.List<Nonterminal> context)
Creates a new chart parser for the given grammar. The grammar must not be changed afterwards.

Parameters:
grammar - The grammar to be used by the chart parser.
startCategoryName - The name of the start category.
context - A list of forward references and scope openers that define the context.

ChartParser

public ChartParser(Grammar grammar,
                   java.lang.String startCategoryName)
Creates a new chart parser for the given grammar. The grammar must not be changed afterwards.

Parameters:
grammar - The grammar to be used by the chart parser.
startCategoryName - The name of the start category.
Method Detail

debug

public void debug(boolean debug)
This method can be used to switch on/off debug mode (default is off). In debug mode, messages about the actions of the chart parser are printed onto the standard error device.

Parameters:
debug - true to switch debug mode on, or false to switch it off.

setDynamicLexicon

public void setDynamicLexicon(DynamicLexicon dynLexicon)
Sets the dynamic lexicon.

Parameters:
dynLexicon - The dynamic lexicon.

setPositionIdentifierPrefix

public void setPositionIdentifierPrefix(java.lang.String prefix)
Sets the prefix for the position identifiers that are assigned to the variables of the position operator "#". The default prefix is "#" so that the position identifiers are "#0", "#1", "#2" and so on.

Parameters:
prefix - The new prefix.

addToken

public void addToken(java.lang.String token)
Description copied from interface: PredictiveParser
Adds the token to the end of the token sequence.

Specified by:
addToken in interface PredictiveParser
Parameters:
token - The new token to be added.

addTokens

public void addTokens(java.util.List<java.lang.String> tokens)
Description copied from interface: PredictiveParser
Adds the tokens to the token list.

Specified by:
addTokens in interface PredictiveParser
Parameters:
tokens - The tokens to be added.

removeToken

public void removeToken()
Description copied from interface: PredictiveParser
Removes the last token.

Specified by:
removeToken in interface PredictiveParser

removeAllTokens

public void removeAllTokens()
Description copied from interface: PredictiveParser
Removes all tokens in the current token sequence.

Specified by:
removeAllTokens in interface PredictiveParser

setTokens

public void setTokens(java.util.List<java.lang.String> tokens)
Description copied from interface: PredictiveParser
Sets the given tokens. Existing tokens are removed.

Specified by:
setTokens in interface PredictiveParser
Parameters:
tokens - The tokens.

getTokens

public java.util.List<java.lang.String> getTokens()
Description copied from interface: PredictiveParser
Returns the current token sequence.

Specified by:
getTokens in interface PredictiveParser
Returns:
The current token sequence.

getTokenCount

public int getTokenCount()
Description copied from interface: PredictiveParser
Returns the number of tokens of the current (partial) text.

Specified by:
getTokenCount in interface PredictiveParser
Returns:
The number of tokens.

getReference

public int getReference(int pos)
This method returns the token number to which the token at the given position refers, if it is a reference. -1 is returned if the given token is not a reference.

Parameters:
pos - The position of the token for which the reference should be returned.
Returns:
The token number to which the token at the given position refers, or -1.

getReference

public int getReference()
Description copied from interface: PredictiveParser
This method should return the token number to which the last token refers, if it is a reference like "it". -1 should be returned if the last token is not a reference, or if reference resolution is not implemented.

Specified by:
getReference in interface PredictiveParser
Returns:
The token number to which the last token refers.

getBackwardReferences

public java.util.List<FeatureMap> getBackwardReferences(int pos)
Return a list of feature maps that show how the backward references at the given position in the text can be resolved. These feature maps contain special features of the form "*pos" that denote the textual position of the respective forward references.

Parameters:
pos - The position of the backward reference.
Returns:
The list of feature maps.

getBackwardReferences

public java.util.List<FeatureMap> getBackwardReferences()
Returns a list of feature maps that show how the backward references at the end of the token sequence can be resolved.

Returns:
The list of feature maps.

isComplete

public boolean isComplete()
Description copied from interface: PredictiveParser
Returns true if the current token sequence is a complete statement.

Specified by:
isComplete in interface PredictiveParser
Returns:
true if the current token sequence is complete.

getParseTree

public ParseTree getParseTree(java.lang.String categoryName)
Returns the parse tree of the parsed text if it is a complete statement according to the given grammar and category. Null is returned if the text is not a complete statement.

Parameters:
categoryName - The category name.
Returns:
The parse tree.

getParseTree

public ParseTree getParseTree()
Returns the parse tree of the parsed text if it is a complete statement according to the given grammar and start category. Null is returned if the text is not a complete statement.

Returns:
The parse tree.

getNextTokenOptions

public CPNextTokenOptions getNextTokenOptions(int position)
This methods shows the possible tokens that could be used to continue the text at the given position.

Parameters:
position - The position at which the possible next tokens should be found.
Returns:
The options describing the possible next tokens.

getNextTokenOptions

public CPNextTokenOptions getNextTokenOptions()
Description copied from interface: PredictiveParser
This method returns the options for the next token to be added at the end.

Specified by:
getNextTokenOptions in interface PredictiveParser
Returns:
The options describing the possible next tokens.

getAbstractOptions

public java.util.Set<CPAbstractOption> getAbstractOptions(int position)
This method returns a set of abstract options describing the possible next tokens at the given position in an abstract way.

Parameters:
position - The position at which the possible next tokens should be found.
Returns:
The set of abstract options describing the possible next tokens.

getAbstractOptions

public java.util.Set<CPAbstractOption> getAbstractOptions()
This method returns a set of abstract options describing the possible next tokens at the end position in an abstract way.

Returns:
The set of abstract options describing the possible next tokens.

getConcreteOptions

public java.util.Set<CPConcreteOption> getConcreteOptions(int position)
This method returns a set of concrete options describing the possible next tokens at the given position in a concrete way.

Parameters:
position - The position at which the possible next tokens should be found.
Returns:
The set of concrete options describing the possible next tokens.

getConcreteOptions

public java.util.Set<CPConcreteOption> getConcreteOptions()
This method returns a set of concrete options describing the possible next tokens at the end position in a concrete way.

Returns:
The set of concrete options describing the possible next tokens.

isPossibleNextToken

public boolean isPossibleNextToken(java.lang.String token)
Description copied from interface: PredictiveParser
Returns whether the given token is a possible next token.

Specified by:
isPossibleNextToken in interface PredictiveParser
Parameters:
token - The token.
Returns:
true if the token is a possible next token.


Copyright 2008-2012, AceWiki developers