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

An extractor that uses multiple extractors to extract data. More...

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

Public Member Functions

 __init__ (self, typing.Iterable[Extractor] choices, str capture_name, str nonterminal)
 Initialize the choice extractor.
 
typing.Optional[tuple[str, typing.Any]] extract (self, str input_str)
 Extract data from the input string using the first succeeding extractor.
 
- 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

 _choices
 
- 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 uses multiple extractors to extract data.

It stops at the first succeeding extractor.

Definition at line 194 of file extractor.py.

Constructor & Destructor Documentation

◆ __init__()

formatron.extractor.ChoiceExtractor.__init__ ( self,
typing.Iterable[Extractor] choices,
str capture_name,
str nonterminal )

Initialize the choice extractor.

Parameters
choicesThe extractors to choose from. The order determines the extractors' priority.
capture_nameThe name of the capture, or None if the extractor does not capture.
nonterminalThe nonterminal representing the extractor.

Reimplemented from formatron.extractor.NonterminalExtractor.

Definition at line 204 of file extractor.py.

Member Function Documentation

◆ extract()

typing.Optional[tuple[str, typing.Any]] formatron.extractor.ChoiceExtractor.extract ( self,
str input_str )

Extract data from the input string using the first succeeding extractor.

Parameters
input_strThe input string.
Returns
The remaining string and the extracted data, or None if all extractors failed.

Reimplemented from formatron.extractor.Extractor.

Definition at line 216 of file extractor.py.

◆ kbnf_definition()

str formatron.extractor.ChoiceExtractor.kbnf_definition ( self)

Reimplemented from formatron.extractor.Extractor.

Definition at line 231 of file extractor.py.

Member Data Documentation

◆ _choices

formatron.extractor.ChoiceExtractor._choices
protected

Definition at line 206 of file extractor.py.


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