flair.models.RegexpTagger#
- class flair.models.RegexpTagger(mapping)View on GitHub#
Bases:
object
- __init__(mapping)View on GitHub#
This tagger is capable of tagging sentence objects with given regexp -> label mappings.
I.e: The tuple (r’([”'])(?:(?=(\?))2.)*?1’, ‘QUOTE’) maps every match of the regexp to a <QUOTE> labeled span and therefore labels the given sentence object with RegexpTagger.predict(). This tagger supports multilabeling so tokens can be included in multiple labeled spans. The regexp are compiled internally and an re.error will be raised if the compilation of a given regexp fails.
If a match violates (in this case overlaps) a token span, an exception is raised.
- Parameters:
mapping (
Union
[list
[tuple
[str
,str
]],tuple
[str
,str
]]) – A list of tuples or a single tuple representing a mapping as regexp -> label
Methods
__init__
(mapping)This tagger is capable of tagging sentence objects with given regexp -> label mappings.
predict
(sentences)Predict the given sentences according to the registered mappings.
register_labels
(mapping)Register a regexp -> label mapping.
remove_labels
(labels)Remove a registered regexp -> label mapping given by label.
Attributes
- property registered_labels#
- register_labels(mapping)View on GitHub#
Register a regexp -> label mapping.
- Parameters:
mapping (
Union
[list
[tuple
[str
,str
]],tuple
[str
,str
]]) – A list of tuples or a single tuple representing a mapping as regexp -> label
- remove_labels(labels)View on GitHub#
Remove a registered regexp -> label mapping given by label.
- Parameters:
labels (
Union
[list
[str
],str
]) – A list of labels or a single label as strings.
- predict(sentences)View on GitHub#
Predict the given sentences according to the registered mappings.
- Return type:
list
[Sentence
]