Formatron v0.4.9
Formatron empowers everyone to control the output format of language models with minimal overhead.
Loading...
Searching...
No Matches
formatron.extractor.SubstringExtractor Class Reference

An extractor that extracts a substring of a given string from the input string. More...

Inheritance diagram for formatron.extractor.SubstringExtractor:
formatron.extractor.NonterminalExtractor formatron.extractor.Extractor

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)
 

Detailed Description

An extractor that extracts a substring of a given string from the input string.

Definition at line 240 of file extractor.py.

Constructor & Destructor Documentation

◆ __init__()

formatron.extractor.SubstringExtractor.__init__ ( self,
str string,
str capture_name,
str nonterminal,
* ,
bool extract_empty_substring = False )

Initialize the substring extractor.

Parameters
stringThe string to extract.
nonterminalThe nonterminal representing the extractor.
capture_nameThe name of the capture, or None if the extractor does not capture.
extract_empty_substringWhether to extract empty substring as a valid substring.

Reimplemented from formatron.extractor.NonterminalExtractor.

Definition at line 250 of file extractor.py.

Member Function Documentation

◆ extract()

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.

◆ kbnf_definition()

str formatron.extractor.SubstringExtractor.kbnf_definition ( self)

Reimplemented from formatron.extractor.Extractor.

Definition at line 285 of file extractor.py.

Member Data Documentation

◆ _string

formatron.extractor.SubstringExtractor._string
protected

Definition at line 253 of file extractor.py.

◆ _suffix_automaton

formatron.extractor.SubstringExtractor._suffix_automaton
protected

Definition at line 252 of file extractor.py.

◆ extract_empty_substring

formatron.extractor.SubstringExtractor.extract_empty_substring

Definition at line 254 of file extractor.py.


The documentation for this class was generated from the following file: