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

Class ProximateTokensRule

source code

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

An abstract base class for brill rules whose condition checks for the presence of tokens with given properties at given ranges of positions, relative to the token.

Each subclass of proximate tokens brill rule defines a method extract_property, which extracts a specific property from the the token, such as its text or tag. Each instance is parameterized by a set of tuples, specifying ranges of positions and property values to check for in those ranges:

The brill rule is then applicable to the nth token iff:

For example, a proximate token brill template with start=end=-1 generates rules that check just the property of the preceding token. Note that multiple properties may be included in a single rule; the rule applies if they all hold.

Nested Classes [hide private]

Inherited from yaml.YAMLObject: __metaclass__, yaml_dumper, yaml_loader

Instance Methods [hide private]
 
__init__(self, original_tag, replacement_tag, *conditions)
Construct a new brill rule that changes a token's tag from original_tag to replacement_tag if all of the properties specified in conditions hold.
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, other) source code
 
__ne__(self, other) source code
 
__hash__(self)
hash(x)
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
_condition_to_str(self, condition)
Return a string representation of the given condition.
source code
 
_range_to_str(self, start, end)
Return a string representation for the given range.
source code

Inherited from BrillRule: apply

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

Class Methods [hide private]
 
to_yaml(cls, dumper, data)
Convert a Python object to a representation node.
source code
 
from_yaml(cls, loader, node)
Convert a representation node to a Python object.
source code
Static Methods [hide private]
any
extract_property(token)
Returns some property characterizing this token, such as its base lexical item or its tag.
source code
Class Variables [hide private]

Inherited from yaml.YAMLObject: yaml_flow_style, yaml_tag

Instance Variables [hide private]

Inherited from BrillRule: original_tag, replacement_tag

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, original_tag, replacement_tag, *conditions)
(Constructor)

source code 

Construct a new brill rule that changes a token's tag from original_tag to replacement_tag if all of the properties specified in conditions hold.

Parameters:
  • conditions (tuple of (int, int, *)) - A list of 3-tuples (start, end, value), each of which specifies that the property of at least one token between n+start and n+end (inclusive) is value.
Raises:
  • ValueError - If start>end for any condition.
Overrides: BrillRule.__init__

to_yaml(cls, dumper, data)
Class Method

source code 

Convert a Python object to a representation node.

Overrides: yaml.YAMLObject.to_yaml
(inherited documentation)

from_yaml(cls, loader, node)
Class Method

source code 

Convert a representation node to a Python object.

Overrides: yaml.YAMLObject.from_yaml
(inherited documentation)

extract_property(token)
Static Method

source code 

Returns some property characterizing this token, such as its base lexical item or its tag.

Each implentation of this method should correspond to an implementation of the method with the same name in a subclass of ProximateTokensTemplate.

Parameters:
  • token (Token) - The token
Returns: any
The property

applies(self, tokens, index)

source code 
Parameters:
  • tokens - A tagged sentence
  • index - The index to check
Returns: Boolean
True if the rule would change the tag of tokens[index], False otherwise
Overrides: BrillRule.applies
(inherited documentation)

__eq__(self, other)
(Equality operator)

source code 
Overrides: BrillRule.__eq__

__ne__(self, other)

source code 
Overrides: BrillRule.__ne__

__hash__(self)
(Hashing function)

source code 

hash(x)

Overrides: BrillRule.__hash__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

_condition_to_str(self, condition)

source code 

Return a string representation of the given condition. This helper method is used by __str__.

_range_to_str(self, start, end)

source code 

Return a string representation for the given range. This helper method is used by __str__.