Skip to content

PythonExporter

PythonExporter

Bases: Exporter

Export an engine and its components to Python.

related

Attributes

encapsulated instance-attribute

encapsulated = encapsulated

formatted instance-attribute

formatted = formatted

Functions

__init__

__init__(formatted: bool = True, encapsulated: bool = False) -> None

Constructor.

Parameters:

Name Type Description Default
formatted bool

try to format the code using black if it is installed

True
encapsulated bool

whether to encapsulate the code (using classes for engines and methods for other components).

False

activation

activation(activation: Activation | None) -> str

Return the code to construct the activation method in Python.

Parameters:

Name Type Description Default
activation Activation | None

activation method to export

required

Returns:

Type Description
str

code to construct the activation method in Python

defuzzifier

defuzzifier(defuzzifier: Defuzzifier | None) -> str

Return the code to construct the defuzzifier in Python.

Parameters:

Name Type Description Default
defuzzifier Defuzzifier | None

defuzzifier to export

required

Returns:

Type Description
str

code to construct the defuzzifier in Python

encapsulate

encapsulate(instance: Any) -> str

Encapsulate the instance in a new class if it is an engine, or in a create method otherwise.

Parameters:

Name Type Description Default
instance Any

object to encapsulate

required

Returns:

Type Description
str

if the instance is an engine, then the class constructing the engine during initialization;

str

otherwise a method constructing the object

engine

engine(engine: Engine) -> str

Return the code to construct the engine in Python.

Parameters:

Name Type Description Default
engine Engine

engine to export

required

Returns:

Type Description
str

code to construct the engine in Python

format

format(code: str, **kwargs: Any) -> str

Format the code using the black formatter if it is installed, otherwise no effects on the code.

Parameters:

Name Type Description Default
code str

code to format.

required
**kwargs Any

keyword arguments to pass to black.Mode

{}

Returns: code formatted if black is installed, otherwise the code without format

input_variable

input_variable(input_variable: InputVariable) -> str

Return the code to construct the input variable in Python.

Parameters:

Name Type Description Default
input_variable InputVariable

input variable to export

required

Returns:

Type Description
str

code to construct the input variable in Python

norm

norm(norm: Norm | None) -> str

Return the code to construct the norm in Python.

Parameters:

Name Type Description Default
norm Norm | None

norm to export

required

Returns:

Type Description
str

code to construct the norm in Python

output_variable

output_variable(output_variable: OutputVariable) -> str

Return the code to construct the output variable in Python.

Parameters:

Name Type Description Default
output_variable OutputVariable

output variable to export

required

Returns:

Type Description
str

code to construct the output variable in Python

rule

rule(rule: Rule) -> str

Return the code to construct the rule in Python.

Parameters:

Name Type Description Default
rule Rule

rule to export

required

Returns:

Type Description
str

code to construct the rule in Python

rule_block

rule_block(rule_block: RuleBlock) -> str

Return the code to construct the rule block in Python.

Parameters:

Name Type Description Default
rule_block RuleBlock

rule block variable to export

required

Returns:

Type Description
str

code to construct the rule block in Python

term

term(term: Term) -> str

Return the code to construct the term in Python.

Parameters:

Name Type Description Default
term Term

term to export

required

Returns:

Type Description
str

code to construct the term in Python

to_string

to_string(instance: Any) -> str

Return the code to construct the instance in Python.

Parameters:

Name Type Description Default
instance Any

fuzzylite object

required

Returns:

Type Description
str

code to construct the instance in Python