class TagRule: (source)
Known subclasses: nltk.tbl.rule.Rule
Constructor: TagRule(original_tag, replacement_tag)
An interface for tag transformations on a tagged corpus, as performed by tbl taggers. Each transformation finds all tokens in the corpus that are tagged with a specific original tag and satisfy a specific condition, and replaces their tags with a replacement tag. For any given transformation, the original tag, replacement tag, and condition are fixed. Conditions may depend on the token under consideration, as well as any other tokens in the corpus.
Tag rules must be comparable and hashable.
Method | __eq__ |
Undocumented |
Method | __hash__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __ne__ |
Undocumented |
Method | applies |
No summary |
Method | apply |
Apply this rule at every position in positions where it applies to the given sentence. 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. |
Instance Variable | original |
The tag which this TagRule may cause to be replaced. |
Instance Variable | replacement |
The tag with which this TagRule may replace another tag. |
nltk.tbl.rule.Rule
Parameters | |
tokens:list(str) | A tagged sentence |
index:int | The index to check |
Returns | |
bool | True if the rule would change the tag of tokens[index], False otherwise |
Apply this rule at every position in positions where it applies to the given sentence. 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:list(tuple(str, str)) | The tagged sentence |
positions:list(int) | The positions where the transformation is to be tried. If not specified, try it at all positions. |
Returns | |
int | The indices of tokens whose tags were changed by this rule. |