Type RegexpChunkRule
object
--+
|
RegexpChunkRule
- Known Subclasses:
-
ChinkRule
,
ChunkRule
,
ExpandLeftRule
,
ExpandRightRule
,
MergeRule
,
SplitRule
,
UnChunkRule
A rule specifying how to modify the chunking in a
ChunkString
, using a transformational regular expression.
The RegexpChunkRule
class itself can be used to implement
any transformational rule based on regular expressions. There are also a
number of subclasses, which can be used to implement simpler types of
rules, based on matching regular expressions.
Each RegexpChunkRule
has a regular expression and a
replacement expression. When a RegexpChunkRule
is applied to a
ChunkString
, it searches the ChunkString
for
any substring that matches the regular expression, and replaces it using
the replacement expression. This search/replace operation has the same
semantics as re.sub
.
Each RegexpChunkRule
also has a description string, which
gives a short (typically less than 75 characters) description of the
purpose of the rule.
This transformation defined by this RegexpChunkRule
should only add and remove braces; it should not modify the
sequence of angle-bracket delimited tags. Furthermore, this
transformation may not result in nested or mismatched bracketing.
Method Summary |
|
__init__ (self,
regexp,
repl,
descr)
Construct a new RegexpChunkRule. |
string
|
__repr__ (self)
Return a string representation of this rule. |
None
|
apply (self,
chunkstr)
Apply this rule to the given ChunkString . |
string
|
descr (self)
Return a short description of the purpose and/or effect of this rule. |
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__ ,
__str__
|
__init__(self,
regexp,
repl,
descr)
(Constructor)
Construct a new RegexpChunkRule.
-
- Parameters:
regexp -
This RegexpChunkRule 's regular expression. When
this rule is applied to a ChunkString , any substring
that matches regexp will be replaced using the
replacement string repl . Note that this must be a
normal regular expression, not a tag pattern.
(type=regexp or string )
repl -
This RegexpChunkRule 's replacement expression.
When this rule is applied to a ChunkString , any
substring that matches regexp will be replaced using
repl .
(type=string )
descr -
A short description of the purpose and/or effect of this
rule.
(type=string )
- Overrides:
__builtin__.object.__init__
|
__repr__(self)
(Representation operator)
-
- Returns:
-
A string representation of this rule. This string
representation has the form:
<RegexpChunkRule: '{<IN|VB.*>}'->'<IN>'>
Note that this representation does not include the description
string; that string can be accessed separately with the
descr method.
(type=string )
- Overrides:
__builtin__.object.__repr__
|
apply(self,
chunkstr)
Apply this rule to the given ChunkString . See the class
reference documentation for a description of what it means to apply a
rule.
-
- Parameters:
chunkstr -
The chunkstring to which this rule is applied.
(type=ChunkString )
- Returns:
-
None
- Raises:
ValueError -
If this transformation generated an invalid chunkstring.
|
descr(self)
-
- Returns:
-
a short description of the purpose and/or effect of this
rule.
(type=string )
|