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:
-
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
|
|
Boolean
|
applies(self,
tokens,
index)
Returns:
True if the rule would change the tag of tokens[index] ,
False otherwise |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inherited from BrillRule :
apply
Inherited from object :
__delattr__ ,
__getattribute__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__
|
Inherited from yaml.YAMLObject :
yaml_flow_style ,
yaml_tag
|
Inherited from object :
__class__
|
__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__
|
Convert a Python object to a representation node.
- Overrides:
yaml.YAMLObject.to_yaml
- (inherited documentation)
|
Convert a representation node to a Python object.
- Overrides:
yaml.YAMLObject.from_yaml
- (inherited documentation)
|
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
|
- 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)
|
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__.
|