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

Source Code for Package nltk.tag

  1  # Natural Language Toolkit: Taggers 
  2  # 
  3  # Copyright (C) 2001-2008 NLTK Project 
  4  # Author: Edward Loper <[email protected]> 
  5  #         Steven Bird <[email protected]> (minor additions) 
  6  # URL: <http://nltk.org> 
  7  # For license information, see LICENSE.TXT 
  8   
  9  """ 
 10  Classes and interfaces for tagging each token of a sentence with 
 11  supplementary information, such as its part of speech.  This task, 
 12  which is known as X{tagging}, is defined by the L{TaggerI} interface. 
 13  """ 
 14   
 15  from api import * 
 16  from util import * 
 17  from simplify import * 
 18  from sequential import * 
 19  from brill import * 
 20   
 21  __all__ = [ 
 22      # Tagger interface 
 23      'TaggerI', 
 24       
 25      # Should these be included:? 
 26      #'SequentialBackoffTagger', 'ContextTagger', 
 27   
 28      # Sequential backoff taggers. 
 29      'DefaultTagger', 'UnigramTagger', 'BigramTagger', 'TrigramTagger', 
 30      'NgramTagger', 'AffixTagger', 'RegexpTagger', 
 31   
 32      # Brill tagger -- trainer names? 
 33      'BrillTagger', 'BrillTaggerTrainer', 'FastBrillTaggerTrainer', 
 34   
 35      # Utilities.  Note: conversion functions x2y are intentionally 
 36      # left out; they should be accessed as nltk.tag.x2y().  Similarly 
 37      # for nltk.tag.accuracy. 
 38      'untag',  
 39      ] 
 40   
 41  # Import hmm module if numpy is installed 
 42  try: 
 43      import numpy 
 44      from hmm import * 
 45      __all__ += ['HiddenMarkovModelTagger', 'HiddenMarkovModelTrainer',] 
 46      # [xx] deprecated HiddenMarkovModel etc objects? 
 47  except ImportError: 
 48      pass 
 49   
 50   
 51  ###################################################################### 
 52  #{ Deprecated 
 53  ###################################################################### 
 54  from nltk.internals import Deprecated 
55 -class TagI(TaggerI, Deprecated):
56 """Use nltk.TaggerI instead."""
57 -class SequentialBackoff(SequentialBackoffTagger, Deprecated):
58 """Use nltk.SequentialBackoffTagger instead. Note: the methods 59 used to subclass SequentialBackoffTagger do not match those of 60 the old nltk.tag.SequentialBackoff; see the api docs for info."""
61 -class Ngram(SequentialBackoffTagger, Deprecated):
62 """Use nltk.NgramTagger instead. Note: NgramTagger.train() is now 63 a factory method."""
64 - def __init__(self, n, cutoff=1, backoff=None):
65 SequentialBackoffTagger.__init__(self, backoff) 66 self._cutoff = cutoff 67 self._n = n
68 - def train(self, tagged_corpus, verbose=False):
69 self._tagger = NgramTagger.train( 70 tagged_corpus, self._n, self.backoff, self._cutoff, verbose)
71 - def choose_tag(self, tokens, index, history):
72 return self._tagger.choose_tag(tokens, index, history)
73 -class Unigram(Ngram, Deprecated):
74 """Use nltk.UnigramTagger instead."""
75 - def __init__(self, cutoff=1, backoff=None):
76 Ngram.__init__(self, 1, cutoff, backoff)
77 -class Bigram(Ngram, Deprecated):
78 """Use nltk.BigramTagger instead."""
79 - def __init__(self, cutoff=1, backoff=None):
80 Ngram.__init__(self, 2, cutoff, backoff)
81 -class Trigram(Ngram, Deprecated):
82 """Use nltk.TrigramTagger instead."""
83 - def __init__(self, cutoff=1, backoff=None):
84 Ngram.__init__(self, 3, cutoff, backoff)
85 -class Affix(SequentialBackoffTagger, Deprecated):
86 """Use nltk.AffixTagger instead."""
87 - def __init__(self, length, minlength, backoff=None):
88 SequentialBackoffTagger.__init__(self, backoff) 89 self._len = length 90 self._minlen = minlength 91 self._cutoff = cutoff
92 - def train(self, tagged_corpus):
93 self._tagger = AffixTagger.train( 94 tagged_corpus, self._minlen, self._len, self.backoff)
95 - def choose_tag(self, tokens, index, history):
96 return self._tagger.choose_tag(tokens, index, history)
97 -class Lookup(UnigramTagger, Deprecated):
98 """Use UnigramTagger instead."""
99 -class Regexp(RegexpTagger, Deprecated):
100 """Use RegexpTagger instead."""
101