Formatron v0.4.9
Formatron empowers everyone to control the output format of language models with minimal overhead.
|
An extractor that extracts a substring of a given string from the input string. More...
Public Member Functions | |
__init__ (self, str string, str capture_name, str nonterminal, *, bool extract_empty_substring=False) | |
Initialize the substring extractor. | |
typing.Optional[tuple[str, str]] | extract (self, str input_str) |
Extract the longest substring of a given string from the input string. | |
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. | |
Public Attributes | |
extract_empty_substring | |
Protected Attributes | |
_suffix_automaton | |
_string | |
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 substring of a given string from the input string.
Definition at line 240 of file extractor.py.
formatron.extractor.SubstringExtractor.__init__ | ( | self, | |
str | string, | ||
str | capture_name, | ||
str | nonterminal, | ||
* | , | ||
bool | extract_empty_substring = False ) |
Initialize the substring extractor.
string | The string to extract. |
nonterminal | The nonterminal representing the extractor. |
capture_name | The name of the capture, or None if the extractor does not capture. |
extract_empty_substring | Whether to extract empty substring as a valid substring. |
Reimplemented from formatron.extractor.NonterminalExtractor.
Definition at line 250 of file extractor.py.
typing.Optional[tuple[str, str]] formatron.extractor.SubstringExtractor.extract | ( | self, | |
str | input_str ) |
Extract the longest substring of a given string from the input string.
If extract_empty_substring is True, empty string is always a valid substring, so the returned string could be empty and None
will never be returned. Otherwise, empty string is not a valid substring, so the returned string could not be empty and None
will be returned if the input string does not contain the given string.
Reimplemented from formatron.extractor.Extractor.
Definition at line 262 of file extractor.py.
str formatron.extractor.SubstringExtractor.kbnf_definition | ( | self | ) |
Reimplemented from formatron.extractor.Extractor.
Definition at line 285 of file extractor.py.
|
protected |
Definition at line 253 of file extractor.py.
|
protected |
Definition at line 252 of file extractor.py.
formatron.extractor.SubstringExtractor.extract_empty_substring |
Definition at line 254 of file extractor.py.