Package nltk :: Module grammar :: Class FeatureGrammar
[hide private]
[frames] | no frames]

type FeatureGrammar

source code

        object --+    
                 |    
ContextFreeGrammar --+
                     |
                    FeatureGrammar

A feature-based grammar. This is equivalent to a ContextFreeGrammar whose nonterminals are FeatStructNonterminals.

A grammar consists of a start state and a set of productions. The set of terminals and nonterminals is implicitly specified by the productions.

Instance Methods [hide private]
 
__init__(self, start, productions)
Create a new feature-based grammar, from the given start state and set of Productions.
source code
 
_calculate_indexes(self) source code
list of Production
productions(self, lhs=None, rhs=None, empty=False)
Return the grammar productions, filtered by the left-hand side or the first item in the right-hand side.
source code
set of Nonterminal
leftcorners(self, cat)
Return the set of all words that the given category can start with.
source code
set of Nonterminal
leftcorner_parents(self, cat)
Return the set of all categories for which the given category is a left corner.
source code
 
_get_type_if_possible(self, item)
Helper function which returns the TYPE feature of the item, if it exists, otherwise it returns the item itself
source code

Inherited from ContextFreeGrammar: __repr__, __str__, check_coverage, is_binarised, is_chomsky_normal_form, is_flexible_chomsky_normal_form, is_leftcorner, is_lexical, is_nonempty, is_nonlexical, max_len, min_len, start

Method Details [hide private]

__init__(self, start, productions)
(Constructor)

source code 

Create a new feature-based grammar, from the given start state and set of Productions.

Parameters:
Overrides: ContextFreeGrammar.__init__

_calculate_indexes(self)

source code 
Overrides: ContextFreeGrammar._calculate_indexes

productions(self, lhs=None, rhs=None, empty=False)

source code 

Return the grammar productions, filtered by the left-hand side or the first item in the right-hand side.

Parameters:
  • lhs - Only return productions with the given left-hand side.
  • rhs - Only return productions with the given first item in the right-hand side.
  • empty - Only return productions with an empty right-hand side.
Returns: list of Production
A list of productions matching the given constraints.
Overrides: ContextFreeGrammar.productions

leftcorners(self, cat)

source code 

Return the set of all words that the given category can start with. Also called the first set in compiler construction.

Parameters:
  • cat - the parent of the leftcorners
Returns: set of Nonterminal
the set of all leftcorners
Overrides: ContextFreeGrammar.leftcorners

leftcorner_parents(self, cat)

source code 

Return the set of all categories for which the given category is a left corner.

Parameters:
  • cat - the suggested leftcorner
Returns: set of Nonterminal
the set of all parents to the leftcorner
Overrides: ContextFreeGrammar.leftcorner_parents