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

Class BrillRule

source code

     object --+    
              |    
yaml.YAMLObject --+
                  |
                 BrillRule
Known Subclasses:

An interface for tag transformations on a tagged corpus, as performed by brill taggers. Each transformation finds all tokens in the corpus that are tagged with a specific original tag and satisfy a specific condition, and replaces their tags with a replacement tag. For any given transformation, the original tag, replacement tag, and condition are fixed. Conditions may depend on the token under consideration, as well as any other tokens in the corpus.

Brill rules must be comparable and hashable.

Nested Classes [hide private]

Inherited from yaml.YAMLObject: __metaclass__, yaml_dumper, yaml_loader

Instance Methods [hide private]
 
__init__(self, original_tag, replacement_tag)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
int
apply(self, tokens, positions=None)
Apply this rule at every position in positions where it applies to the given sentence.
source code
Boolean
applies(self, tokens, index)
Returns: True if the rule would change the tag of tokens[index], False otherwise
source code
 
__eq__(self) source code
 
__ne__(self) source code
 
__hash__(self)
hash(x)
source code

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

Class Methods [hide private]

Inherited from yaml.YAMLObject: from_yaml, to_yaml

Class Variables [hide private]

Inherited from yaml.YAMLObject: yaml_flow_style, yaml_tag

Instance Variables [hide private]
  original_tag
The tag which this BrillRule may cause to be replaced.
  replacement_tag
The tag with which this BrillRule may replace another tag.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, original_tag, replacement_tag)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

apply(self, tokens, positions=None)

source code 

Apply this rule at every position in positions where it applies to the given sentence. I.e., for each position p in positions, if tokens[p] is tagged with this rule's original tag, and satisfies this rule's condition, then set its tag to be this rule's replacement tag.

Parameters:
  • tokens (list of Token) - The tagged sentence
  • positions (list of int) - The positions where the transformation is to be tried. If not specified, try it at all positions.
Returns: int
The indices of tokens whose tags were changed by this rule.

applies(self, tokens, index)

source code 
Parameters:
  • tokens (list of Token) - A tagged sentence
  • index (int) - The index to check
Returns: Boolean
True if the rule would change the tag of tokens[index], False otherwise

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: object.__hash__
(inherited documentation)