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

An abstract extractor that extracts data from a string and offers its KBNF rules definition. More...

Inheritance diagram for formatron.extractor.Extractor:
formatron.extractor.LiteralExtractor formatron.extractor.NonterminalExtractor formatron.extractor.ChoiceExtractor formatron.extractor.SubstringExtractor formatron.formats.json.JsonExtractor formatron.formats.regex.RegexExtractor

Public Member Functions

 __init__ (self, typing.Optional[str] capture_name=None)
 Initialize an extractor.
 
typing.Optional[tuple[str, typing.Any]] extract (self, str input_str)
 Extract data from the input string, or None if the extraction failed.
 
str kbnf_reference (self)
 
 __str__ (self)
 
str kbnf_definition (self)
 

Protected Attributes

 _capture_name
 

Properties

typing.Optional[str] capture_name (self)
 Get the name of the capture, or None if the extractor does not capture.
 

Detailed Description

An abstract extractor that extracts data from a string and offers its KBNF rules definition.

Definition at line 14 of file extractor.py.

Constructor & Destructor Documentation

◆ __init__()

formatron.extractor.Extractor.__init__ ( self,
typing.Optional[str] capture_name = None )

Initialize an extractor.

Parameters
capture_nameThe name of the capture, or None if the extractor does not capture.

Reimplemented in formatron.extractor.ChoiceExtractor, formatron.extractor.LiteralExtractor, formatron.extractor.NonterminalExtractor, formatron.extractor.SubstringExtractor, formatron.formats.json.JsonExtractor, and formatron.formats.regex.RegexExtractor.

Definition at line 21 of file extractor.py.

Member Function Documentation

◆ __str__()

formatron.extractor.Extractor.__str__ ( self)

Definition at line 69 of file extractor.py.

◆ capture_name()

typing.Optional[str] formatron.extractor.Extractor.capture_name ( self)

Get the name of the capture, or None if the extractor does not capture.

Definition at line 35 of file extractor.py.

◆ extract()

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

Extract data from the input string, or None if the extraction failed.

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

Reimplemented in formatron.extractor.ChoiceExtractor, formatron.extractor.LiteralExtractor, formatron.extractor.SubstringExtractor, formatron.formats.json.JsonExtractor, and formatron.formats.regex.RegexExtractor.

Definition at line 48 of file extractor.py.

◆ kbnf_definition()

◆ kbnf_reference()

str formatron.extractor.Extractor.kbnf_reference ( self)

Member Data Documentation

◆ _capture_name

formatron.extractor.Extractor._capture_name
protected

Definition at line 22 of file extractor.py.


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