Package nltk_lite :: Package contrib :: Module marshalbrill :: Class ProximateTokensRule
[show private | hide private]
[frames | no frames]

Type ProximateTokensRule

object --+    
         |    
BrillRuleI --+
             |
            ProximateTokensRule

Known Subclasses:
ProximateTagsRule, ProximateWordsRule

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.
Method Summary
  __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.
  __eq__(self, other)
  __hash__(self)
  __repr__(self)
  __str__(self)
Boolean applies(self, tokens, index)
Return true if the rule would change the tag of tokens[index], False otherwise
int apply_at(self, tokens, positions)
Apply this rule at every position in positions where it applies to the corpus.
any extract_property(token)
Returns some property characterizing this token, such as its base lexical item or its tag. (Static method)
any original_tag(self)
Return the tag which this BrillRuleI may cause to be replaced.
any replacement_tag(self)
Return the tag with which this BrillRuleI may replace another tag.
Inherited from BrillRuleI: apply_to
Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Instance Method Details

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

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 - 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.
           (type=tuple of (int, int, *))
Raises:
ValueError - If start>end for any condition.
Overrides:
__builtin__.object.__init__

applies(self, tokens, index)

Parameters:
tokens - A tagged corpus
           (type=list of Token)
index - The index to check
           (type=int)
Returns:
True if the rule would change the tag of tokens[index], False otherwise
           (type=Boolean)
Overrides:
nltk_lite.contrib.marshalbrill.BrillRuleI.applies (inherited documentation)

apply_at(self, tokens, positions)

Apply this rule at every position in positions where it applies to the corpus. 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 - The tagged corpus
           (type=list of Token)
positions - The positions where the transformation is to be tried.
           (type=list of int)
Returns:
The indices of tokens whose tags were changed by this rule.
           (type=int)
Overrides:
nltk_lite.contrib.marshalbrill.BrillRuleI.apply_at (inherited documentation)

original_tag(self)

Returns:
The tag which this BrillRuleI may cause to be replaced.
           (type=any)
Overrides:
nltk_lite.contrib.marshalbrill.BrillRuleI.original_tag (inherited documentation)

replacement_tag(self)

Returns:
the tag with which this BrillRuleI may replace another tag.
           (type=any)
Overrides:
nltk_lite.contrib.marshalbrill.BrillRuleI.replacement_tag (inherited documentation)

Static Method Details

extract_property(token)

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 - The token
           (type=Token)
Returns:
The property
           (type=any)

Generated by Epydoc 2.1 on Tue Sep 5 09:37:21 2006 http://epydoc.sf.net