Formatron v0.4.9
Formatron empowers everyone to control the output format of language models with minimal overhead.
|
An extractor that extracts a string using a regular expression. More...
Public Member Functions | |
__init__ (self, str regex, str capture_name, str nonterminal) | |
Initialize the regex extractor. | |
typing.Optional[tuple[str, re.Match|None]] | extract (self, str input_str) |
Extract the string using the regular expression. | |
Public Member Functions inherited from formatron.extractor.NonterminalExtractor | |
str | nonterminal (self) |
Get the nonterminal of the extractor. | |
str | kbnf_reference (self) |
Public Member Functions inherited from formatron.extractor.Extractor | |
__str__ (self) | |
typing.Optional[str] | capture_name (self) |
Get the name of the capture, or None if the extractor does not capture. | |
Protected Attributes | |
_regex | |
Protected Attributes inherited from formatron.extractor.NonterminalExtractor | |
_nonterminal | |
Protected Attributes inherited from formatron.extractor.Extractor | |
_capture_name | |
Properties | |
str | kbnf_definition (self) |
An extractor that extracts a string using a regular expression.
formatron.formats.regex.RegexExtractor.__init__ | ( | self, | |
str | regex, | ||
str | capture_name, | ||
str | nonterminal ) |
Initialize the regex extractor.
regex | The regular expression for extraction. |
capture_name | The name of the capture, or None if the extractor does not capture. |
nonterminal | The nonterminal representing the extractor. |
Reimplemented from formatron.extractor.NonterminalExtractor.
typing.Optional[tuple[str, re.Match | None]] formatron.formats.regex.RegexExtractor.extract | ( | self, | |
str | input_str ) |
Extract the string using the regular expression.
Specifically, the first match(if any) of the regex pattern in the input string is returned.
input_str | The input string. |
re.Match
object, or None
if the extraction failed. Reimplemented from formatron.extractor.Extractor.
str formatron.formats.regex.RegexExtractor.kbnf_definition | ( | self | ) |
Reimplemented from formatron.extractor.Extractor.