Package nltk :: Package chunk :: Module regexp :: Class ChunkRuleWithContext
[hide private]
[frames] | no frames]

Class ChunkRuleWithContext

source code

     object --+    
              |    
RegexpChunkRule --+
                  |
                 ChunkRuleWithContext

A rule specifying how to add chunks to a ChunkString, using three matching tag patterns: one for the left context, one for the chunk, and one for the right context. When applied to a ChunkString, it will find any substring that matches the chunk tag pattern, is surrounded by substrings that match the two context patterns, and is not already part of a chunk; and create a new chunk containing the substring that matched the chunk tag pattern.

Caveat: Both the left and right context are consumed when this rule matches; therefore, if you need to find overlapping matches, you will need to apply your rule more than once.

Instance Methods [hide private]
 
__init__(self, left_context_tag_pattern, chunk_tag_pattern, right_context_tag_pattern, descr)
Construct a new ChunkRuleWithContext.
source code
string
__repr__(self)
Returns: A string representation of this rule.
source code

Inherited from RegexpChunkRule: apply, descr

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

Static Methods [hide private]

Inherited from RegexpChunkRule: parse

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, left_context_tag_pattern, chunk_tag_pattern, right_context_tag_pattern, descr)
(Constructor)

source code 

Construct a new ChunkRuleWithContext.

Parameters:
  • left_context_tag_pattern (string) - A tag pattern that must match the left context of chunk_tag_pattern for this rule to apply.
  • chunk_tag_pattern (string) - A tag pattern that must match for this rule to apply. If the rule does apply, then this pattern also identifies the substring that will be made into a chunk.
  • right_context_tag_pattern (string) - A tag pattern that must match the right context of chunk_tag_pattern for this rule to apply.
  • descr (string) - A short description of the purpose and/or effect of this rule.
Overrides: RegexpChunkRule.__init__

__repr__(self)
(Representation operator)

source code 
Returns: string
A string representation of this rule. This string representation has the form:
   <ChunkRuleWithContext: '<IN>', '<NN>', '<DT>'>

Note that this representation does not include the description string; that string can be accessed separately with the descr method.

Overrides: RegexpChunkRule.__repr__