Package nltk :: Package tag :: Module brill :: Class SymmetricProximateTokensTemplate
[hide private]
[frames] | no frames]

Class SymmetricProximateTokensTemplate

source code

    object --+    
             |    
BrillTemplateI --+
                 |
                SymmetricProximateTokensTemplate

Simulates two ProximateTokensTemplates which are symmetric across the location of the token. For rules of the form "If the nth token is tagged A, and any tag preceding or following the nth token by a distance between x and y is B, and ... , then change the tag of the nth token from A to C."

One ProximateTokensTemplate is formed by passing in the same arguments given to this class's constructor: tuples representing intervals in which a tag may be found. The other ProximateTokensTemplate is constructed with the negative of all the arguments in reversed order. For example, a SymmetricProximateTokensTemplate using the pair (-2,-1) and the constructor SymmetricProximateTokensTemplate generates the same rules as a SymmetricProximateTokensTemplate using (-2,-1) plus a second SymmetricProximateTokensTemplate using (1,2).

This is useful because we typically don't want templates to specify only "following" or only "preceding"; we'd like our rules to be able to look in either direction.

Instance Methods [hide private]
 
__init__(self, rule_class, *boundaries)
Construct a template for generating proximate token brill rules.
source code
list of ProximateTokensRule
applicable_rules(self, tokens, index, correctTag)
See BrillTemplateI for full specifications.
source code
Set
get_neighborhood(self, tokens, index)
Returns the set of indices i such that applicable_rules(token, i, ...) depends on the value of the indexth subtoken of token.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, rule_class, *boundaries)
(Constructor)

source code 

Construct a template for generating proximate token brill rules.

Parameters:
  • rule_class (class) - The proximate token brill rule class that should be used to generate new rules. This class must be a subclass of ProximateTokensRule.
  • boundaries (tuple of (int, int)) - A list of tuples (start, end), each of which specifies a range for which a condition should be created by each rule.
Raises:
  • ValueError - If start>end for any boundary.
Overrides: BrillTemplateI.__init__

applicable_rules(self, tokens, index, correctTag)

source code 

See BrillTemplateI for full specifications.

Parameters:
  • tokens - The tagged tokens being tagged.
  • i - The index of the token whose tag should be corrected.
  • correctTag - The correct tag for the ith token.
Returns: list of ProximateTokensRule
Overrides: BrillTemplateI.applicable_rules

get_neighborhood(self, tokens, index)

source code 

Returns the set of indices i such that applicable_rules(token, i, ...) depends on the value of the indexth subtoken of token.

This method is used by the "fast" Brill tagger trainer.

Parameters:
  • token - The tokens being tagged.
  • index - The index whose neighborhood should be returned.
Returns: Set
Overrides: BrillTemplateI.get_neighborhood
(inherited documentation)