Package nltk_lite :: Package parse :: Module pcfg
[hide private]
[frames] | no frames]

Module pcfg

source code

Classes [hide private]
  WeightedProduction
A probabilistic context free grammar production.
  WeightedGrammar
A probabilistic context-free grammar.
Functions [hide private]
 
induce(start, productions)
Induce a PCFG grammar from a list of productions.
source code
 
parse_pcfg_production(s)
Returns a list of PCFG productions
source code
 
parse_pcfg(s) source code
 
demo()
A demonstration showing how PCFG Grammars can be created and used.
source code
Variables [hide private]
  _PARSE_RE = re.compile(r'(?x)^\s*(\w+(?:/\w+)?)\s*(?:[-=]+>)\s...
  _SPLIT_RE = re.compile(r'(\w+(?:/\w+)?|\[[01]?\.\d+\]|[-=]+>|"...
  toy1 = <Grammar with 17 productions>
  toy2 = <Grammar with 23 productions>
Function Details [hide private]

induce(start, productions)

source code 

Induce a PCFG grammar from a list of productions.

The probability of a production A -> B C in a PCFG is:

| count(A -> B C) | P(B, C | A) = --------------- where * is any right hand side | count(A -> *)

Parameters:
  • start (Nonterminal) - The start symbol
  • productions (list of Production) - The list of productions that defines the grammar

Variables Details [hide private]

_PARSE_RE

Value:
re.compile(r'(?x)^\s*(\w+(?:/\w+)?)\s*(?:[-=]+>)\s*(?:("[^"]+"|\'[^\']\
+\'|\w+(?:/\w+)?|\[[01]?\.\d+\]|\|)\s*)*$')

_SPLIT_RE

Value:
re.compile(r'(\w+(?:/\w+)?|\[[01]?\.\d+\]|[-=]+>|"[^"]+"|\'[^\']+\'|\|\
)')