class documentation

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_tag The tag which this TagRule may cause to be replaced.
Instance Variable replacement_tag The tag with which this TagRule may replace another tag.
def __eq__(self, other): (source)
overridden in nltk.tbl.rule.Rule

Undocumented

def __hash__(self): (source)
overridden in nltk.tbl.rule.Rule

Undocumented

def __init__(self, original_tag, replacement_tag): (source)
overridden in nltk.tbl.rule.Rule

Undocumented

def __ne__(self, other): (source)
overridden in nltk.tbl.rule.Rule

Undocumented

@abstractmethod
def applies(self, tokens, index): (source)
overridden in nltk.tbl.rule.Rule
Parameters
tokens:list(str)A tagged sentence
index:intThe index to check
Returns
boolTrue if the rule would change the tag of tokens[index], False otherwise
def apply(self, tokens, positions=None): (source)

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
intThe indices of tokens whose tags were changed by this rule.
original_tag = (source)

The tag which this TagRule may cause to be replaced.

replacement_tag = (source)

The tag with which this TagRule may replace another tag.