ch.uzh.ifi.attempto.chartparser
Class Grammar

java.lang.Object
  extended by ch.uzh.ifi.attempto.chartparser.Grammar
Direct Known Subclasses:
ACEEditorGrammar, ACEGrammar

public class Grammar
extends java.lang.Object

This class represents a grammar that is needed to run the chart parser. A grammar can be created either directly in Java or on the basis of a file in the Codeco notation. See the package description of ch.uzh.ifi.attempto.codeco for more information about the Codeco notation.

Author:
Tobias Kuhn

Constructor Summary
Grammar()
          Creates an empty grammar.
 
Method Summary
 void addGrammarRule(GrammarRule rule)
          Adds a grammar rule.
 void addLexicalRule(LexicalRule lexRule)
          Adds a lexical rule.
 boolean containsFeatureName(java.lang.String featureName)
          Returns whether the given feature name is used in this grammar.
 boolean containsNonterminalSymbol(java.lang.String nonterminalSymbol)
          Returns whether the given nonterminal symbol is used in this grammar.
 boolean containsPreterminalSymbol(java.lang.String preterminalSymbol)
          Returns whether the given preterminal symbol is used in this grammar.
 boolean containsTerminalSymbol(java.lang.String terminalSymbol)
          Returns whether the given terminal symbol is used in this grammar.
 java.util.Set<java.lang.String> getFeatureNames()
          Returns a set of all names of features used in feature structures of categories contained in this grammar.
 java.util.List<LexicalRule> getLexicalRulesByCategory(java.lang.String categoryName)
          Returns the list of lexical rules with a pre-terminal category of the specified name.
 java.util.List<LexicalRule> getLexicalRulesByWord(java.lang.String word)
          Returns the list of lexical rules for the specified word.
 java.util.Set<java.lang.String> getNonterminalSymbols()
          Returns a set of all nonterminal symbols used in this grammar.
 java.util.Set<java.lang.String> getPreterminalSymbols()
          Returns a set of all preterminal symbols used in this grammar.
 java.util.List<GrammarRule> getRulesByHeadName(java.lang.String name)
          Returns the grammar rules with a head category of the specified name.
protected static StringRef getStringRef(int varID, java.util.HashMap<java.lang.Integer,StringRef> featureHash)
          This is an auxiliary method for grammar classes that are automatically generated out of a Codeco representation.
 java.util.Set<java.lang.String> getTerminalSymbols()
          Returns a set of all terminal symbols used in this grammar.
protected static void setFeature(FeatureMap fm, java.lang.String featureName, int varID, java.util.HashMap<java.lang.Integer,StringRef> featureHash)
          This is an auxiliary method for grammar classes that are automatically generated out of a Codeco representation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grammar

public Grammar()
Creates an empty grammar.

Method Detail

addGrammarRule

public void addGrammarRule(GrammarRule rule)
Adds a grammar rule.

Parameters:
rule - The grammar rule to be added.

addLexicalRule

public void addLexicalRule(LexicalRule lexRule)
Adds a lexical rule. Lexical rules could also be called "lexicon entries".

Parameters:
lexRule - The lexical rule to be added.

getRulesByHeadName

public java.util.List<GrammarRule> getRulesByHeadName(java.lang.String name)
Returns the grammar rules with a head category of the specified name.

Parameters:
name - The name of the head category.
Returns:
A list of grammar rules.

getLexicalRulesByCategory

public java.util.List<LexicalRule> getLexicalRulesByCategory(java.lang.String categoryName)
Returns the list of lexical rules with a pre-terminal category of the specified name.

Parameters:
categoryName - The name of the pre-terminal category.
Returns:
A list of lexical rules.

getLexicalRulesByWord

public java.util.List<LexicalRule> getLexicalRulesByWord(java.lang.String word)
Returns the list of lexical rules for the specified word. The word corresponds to a terminal category.

Parameters:
word - The word.
Returns:
A list of lexical rules.

getFeatureNames

public java.util.Set<java.lang.String> getFeatureNames()
Returns a set of all names of features used in feature structures of categories contained in this grammar.

Returns:
A set of all used feature names.

containsFeatureName

public boolean containsFeatureName(java.lang.String featureName)
Returns whether the given feature name is used in this grammar.

Parameters:
featureName - The feature name.
Returns:
true if the feature name is used.

getTerminalSymbols

public java.util.Set<java.lang.String> getTerminalSymbols()
Returns a set of all terminal symbols used in this grammar.

Returns:
A set of all terminal symbols.

containsTerminalSymbol

public boolean containsTerminalSymbol(java.lang.String terminalSymbol)
Returns whether the given terminal symbol is used in this grammar.

Parameters:
terminalSymbol - The terminal symbol.
Returns:
true if the symbol is used.

getPreterminalSymbols

public java.util.Set<java.lang.String> getPreterminalSymbols()
Returns a set of all preterminal symbols used in this grammar.

Returns:
A set of all preterminal symbols.

containsPreterminalSymbol

public boolean containsPreterminalSymbol(java.lang.String preterminalSymbol)
Returns whether the given preterminal symbol is used in this grammar.

Parameters:
preterminalSymbol - The preterminal symbol.
Returns:
true if the symbol is used.

getNonterminalSymbols

public java.util.Set<java.lang.String> getNonterminalSymbols()
Returns a set of all nonterminal symbols used in this grammar.

Returns:
A set of all nonterminal symbols.

containsNonterminalSymbol

public boolean containsNonterminalSymbol(java.lang.String nonterminalSymbol)
Returns whether the given nonterminal symbol is used in this grammar.

Parameters:
nonterminalSymbol - The nonterminal symbol.
Returns:
true if the symbol is used.

setFeature

protected static void setFeature(FeatureMap fm,
                                 java.lang.String featureName,
                                 int varID,
                                 java.util.HashMap<java.lang.Integer,StringRef> featureHash)
This is an auxiliary method for grammar classes that are automatically generated out of a Codeco representation. It sets a feature of a feature map to a certain unbound variable.

Parameters:
fm - The feature map for which a feature should be set.
featureName - The name of the feature to be set.
varID - The identifier of the unbound variable to which the feature should be set.
featureHash - A hash map with variable identiers as keys and the string reference objects that represent the respective variables as values.

getStringRef

protected static StringRef getStringRef(int varID,
                                        java.util.HashMap<java.lang.Integer,StringRef> featureHash)
This is an auxiliary method for grammar classes that are automatically generated out of a Codeco representation. It returns a string reference object that represents a certain unbound variable.

Parameters:
varID - The identifier of the unbound variable for which a string reference object should be returned.
featureHash - A hash map with variable identiers as keys and the string reference objects that represent the respective variables as values.
Returns:
A string reference object.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright 2008-2012, AceWiki developers