class FeatureGrammar(CFG): (source)
Constructor: FeatureGrammar(start, productions)
A feature-based grammar. This is equivalent to a CFG whose nonterminals are all FeatStructNonterminal.
A grammar consists of a start state and a set of productions. The set of terminals and nonterminals is implicitly specified by the productions.
Class Method | fromstring |
Return a feature structure based grammar. |
Method | __init__ |
Create a new feature-based grammar, from the given start state and set of Productions. |
Method | leftcorner |
Return the set of all categories for which the given category is a left corner. |
Method | leftcorners |
Return the set of all words that the given category can start with. Also called the "first set" in compiler construction. |
Method | productions |
Return the grammar productions, filtered by the left-hand side or the first item in the right-hand side. |
Method | _calculate |
Undocumented |
Method | _get |
Helper function which returns the TYPE feature of the item, if it exists, otherwise it returns the item itself |
Instance Variable | _empty |
Undocumented |
Instance Variable | _empty |
Undocumented |
Instance Variable | _lexical |
Undocumented |
Instance Variable | _lhs |
Undocumented |
Instance Variable | _rhs |
Undocumented |
Inherited from CFG
:
Class Method | binarize |
Convert all non-binary rules into binary by introducing new tokens. Example:: Original: |
Class Method | eliminate |
Eliminate start rule in case it appears on RHS Example: S -> S0 S1 and S0 -> S1 S Then another rule S0_Sigma -> S is added |
Class Method | remove |
Remove nonlexical unitary rules and convert them to lexical |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | check |
Check whether the grammar rules cover the given list of tokens. If not, then raise an exception. |
Method | chomsky |
Returns a new Grammer that is in chomsky normal :param: new_token_padding |
Method | is |
Return True if all productions are at most binary. Note that there can still be empty and unary productions. |
Method | is |
Return True if the grammar is of Chomsky Normal Form, i.e. all productions are of the form A -> B C, or A -> "s". |
Method | is |
Return True if all productions are of the forms A -> B C, A -> B, or A -> "s". |
Method | is |
True if left is a leftcorner of cat, where left can be a terminal or a nonterminal. |
Method | is |
Return True if all productions are lexicalised. |
Method | is |
Return True if there are no empty productions. |
Method | is |
Return True if all lexical rules are "preterminals", that is, unary rules which can be separated in a preprocessing step. |
Method | max |
Return the right-hand side length of the longest grammar production. |
Method | min |
Return the right-hand side length of the shortest grammar production. |
Method | start |
Return the start symbol of the grammar |
Method | _calculate |
Pre-calculate of which form(s) the grammar is. |
Method | _calculate |
Undocumented |
Instance Variable | _all |
Undocumented |
Instance Variable | _categories |
Undocumented |
Instance Variable | _immediate |
Undocumented |
Instance Variable | _immediate |
Undocumented |
Instance Variable | _is |
Undocumented |
Instance Variable | _is |
Undocumented |
Instance Variable | _leftcorner |
Undocumented |
Instance Variable | _leftcorner |
Undocumented |
Instance Variable | _leftcorners |
Undocumented |
Instance Variable | _max |
Undocumented |
Instance Variable | _min |
Undocumented |
Instance Variable | _productions |
Undocumented |
Instance Variable | _start |
Undocumented |
def fromstring(cls, input, features=None, logic_parser=None, fstruct_reader=None, encoding=None): (source) ¶
nltk.grammar.CFG.fromstring
Return a feature structure based grammar.
as a list of strings. :param features: a tuple of features (default: SLASH, TYPE) :param logic_parser: a parser for lambda-expressions, by default, LogicParser() :param fstruct_reader: a feature structure parser (only if features and logic_parser is None)
Parameters | |
input | a grammar, either in the form of a string or else |
features | Undocumented |
logic | Undocumented |
fstruct | Undocumented |
encoding | Undocumented |
nltk.grammar.CFG.__init__
Create a new feature-based grammar, from the given start state and set of Productions.
Parameters | |
start:FeatStructNonterminal | The start symbol |
productions:list(Production) | The list of productions that defines the grammar |
nltk.grammar.CFG.leftcorner_parents
Return the set of all categories for which the given category is a left corner.
nltk.grammar.CFG.leftcorners
Return the set of all words that the given category can start with. Also called the "first set" in compiler construction.
nltk.grammar.CFG.productions
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(Production) | Undocumented |