Package nltk :: Package parse
[hide private]
[frames] | no frames]

Source Code for Package nltk.parse

  1  # Natural Language Toolkit: Parsers 
  2  # 
  3  # Copyright (C) 2001-2008 NLTK Project 
  4  # Author: Steven Bird <[email protected]> 
  5  #         Edward Loper <[email protected]> 
  6  # URL: <http://nltk.org> 
  7  # For license information, see LICENSE.TXT 
  8  # 
  9   
 10  """ 
 11  Classes and interfaces for producing tree structures that represent 
 12  the internal organization of a text.  This task is known as X{parsing} 
 13  the text, and the resulting tree structures are called the text's 
 14  X{parses}.  Typically, the text is a single sentence, and the tree 
 15  structure represents the syntactic structure of the sentence. 
 16  However, parsers can also be used in other domains.  For example, 
 17  parsers can be used to derive the morphological structure of the 
 18  morphemes that make up a word, or to derive the discourse structure 
 19  for a set of utterances. 
 20   
 21  Sometimes, a single piece of text can be represented by more than one 
 22  tree structure.  Texts represented by more than one tree structure are 
 23  called X{ambiguous} texts.  Note that there are actually two ways in 
 24  which a text can be ambiguous: 
 25   
 26      - The text has multiple correct parses. 
 27      - There is not enough information to decide which of several 
 28        candidate parses is correct. 
 29   
 30  However, the parser module does I{not} distinguish these two types of 
 31  ambiguity. 
 32   
 33  The parser module defines C{ParserI}, a standard interface for parsing 
 34  texts; and two simple implementations of that interface, 
 35  C{ShiftReduceParser} and C{RecursiveDescentParser}.  It also contains 
 36  three sub-modules for specialized kinds of parsing: 
 37   
 38    - C{nltk.parser.chart} defines chart parsing, which uses dynamic 
 39      programming to efficiently parse texts. 
 40    - C{nltk.parser.probabilistic} defines probabilistic parsing, which 
 41      associates a probability with each parse. 
 42  """ 
 43   
 44  from api import * 
 45  from chart import * 
 46  from featurechart import * 
 47  from pchart import * 
 48  from rd import * 
 49  from sr import * 
 50  from util import * 
 51  from viterbi import * 
 52   
 53  __all__ = [ 
 54      # Parser interface 
 55      'ParserI', 
 56   
 57      # Parsers 
 58      'RecursiveDescentParser', 'SteppingRecursiveDescentParser', 
 59      'ShiftReduceParser', 'SteppingShiftReduceParser', 
 60      'EarleyChartParser', 'ChartParser', 'SteppingChartParser', 
 61      'BottomUpChartParser', 'InsideChartParser', 'RandomChartParser', 
 62      'UnsortedChartParser', 'LongestChartParser', 'ViterbiParser', 
 63      'FeatureEarleyChartParser', 
 64   
 65      ] 
 66   
 67  ###################################################################### 
 68  #{ Deprecated 
 69  ###################################################################### 
 70  from nltk.internals import Deprecated 
71 -class ParseI(ParserI, Deprecated):
72 """Use nltk.ParserI instead."""
73 -class AbstractParse(AbstractParser, Deprecated):
74 """Use nltk.ParserI instead."""
75 -class RecursiveDescent(RecursiveDescentParser, Deprecated):
76 """Use nltk.RecursiveDescentParser instead."""
77 -class SteppingRecursiveDescent(SteppingRecursiveDescentParser, Deprecated):
78 """Use nltk.SteppingRecursiveDescentParser instead."""
79 -class ShiftReduce(ShiftReduceParser, Deprecated):
80 """Use nltk.ShiftReduceParser instead."""
81 -class SteppingShiftReduce(SteppingShiftReduceParser, Deprecated):
82 """Use nltk.SteppingShiftReduceParser instead."""
83 -class EarleyChartParse(EarleyChartParser, Deprecated):
84 """Use nltk.EarleyChartParser instead."""
85 -class FeatureEarleyChartParse(FeatureEarleyChartParser, Deprecated):
86 """Use nltk.FeatureEarleyChartParser instead."""
87 -class ChartParse(ChartParser, Deprecated):
88 """Use nltk.ChartParser instead."""
89 -class SteppingChartParse(SteppingChartParser, Deprecated):
90 """Use nltk.SteppingChartParser instead."""
91 -class BottomUpChartParse(BottomUpChartParser, Deprecated):
92 """Use nltk.BottomUpChartParser instead."""
93 -class InsideParse(InsideChartParser, Deprecated):
94 """Use nltk.InsideChartParser instead."""
95 -class RandomParse(RandomChartParser, Deprecated):
96 """Use nltk.RandomChartParser instead."""
97 -class UnsortedParse(UnsortedChartParser, Deprecated):
98 """Use nltk.UnsortedChartParser instead."""
99 -class LongestParse(LongestChartParser, Deprecated):
100 """Use nltk.LongestChartParser instead."""
101 -class ViterbiParse(ViterbiParser, Deprecated):
102 """Use nltk.ViterbiParser instead."""
103 -class GrammarFile(Deprecated):
104 """Use nltk.data.load() instead.""" 105 # [xx] had directives: %start, %kimmo, %tagger_file?
106 - def __init__(self, filename=None, verbose=False):
107 raise ValueError("GrammarFile is no longer supported -- " 108 "use nltk.data.load() instead.")
109