Class ProximateTokensRule
source code
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:
-
The nth token is tagged with the rule's original
tag; and
-
For each (start, end, value) triple:
-
The property value of at least one token between n+start and n+end
(inclusive) is value.
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.
|
__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
|
|
int
|
apply_at(self,
tokens,
positions)
Apply this rule at every position in positions where it
applies to the corpus. |
source code
|
|
Boolean
|
applies(self,
tokens,
index)
Returns:
True if the rule would change the tag of tokens[index] ,
False otherwise |
source code
|
|
any
|
|
any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inherited from BrillRuleI :
apply_to
Inherited from object :
__delattr__ ,
__getattribute__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__
|
__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:
object.__init__
|
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
|
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.
- Returns:
int
- The indices of tokens whose tags were changed by this rule.
- Overrides:
BrillRuleI.apply_at
- (inherited documentation)
|
- Returns: Boolean
- True if the rule would change the tag of
tokens[index] , False otherwise
- Overrides:
BrillRuleI.applies
- (inherited documentation)
|
- Returns: any
- The tag which this
BrillRuleI may cause to be
replaced.
- Overrides:
BrillRuleI.original_tag
- (inherited documentation)
|
- Returns: any
- the tag with which this
BrillRuleI may replace
another tag.
- Overrides:
BrillRuleI.replacement_tag
- (inherited documentation)
|
repr(x)
- Overrides:
object.__repr__
- (inherited documentation)
|
__str__(self)
(Informal representation operator)
| source code
|
str(x)
- Overrides:
object.__str__
- (inherited documentation)
|
Return a string representation of the given condition. This helper
method is used by __str__.
|
Return a string representation for the given range. This helper
method is used by __str__.
|