geneticengine.grammar.synthetic_grammar
Module Contents
Functions
|
Dynamically creates a new data class with the given name and arguments. |
|
Returns a list of names for non_terminal_symbols. |
|
Returns a new abstract class, with the provided name. |
|
Creates a class representing a Production. |
|
|
|
Generates a random grammar, based on a particular seed. |
Attributes
- geneticengine.grammar.synthetic_grammar.create_dataclass_dynamically(name, args={}, annotations={}, parent_class=ABC)
Dynamically creates a new data class with the given name and arguments.
- Parameters:
name (str) – the name of the new data class
args (dict[str, Any]) – the attributes and values for the new data class. Default is an empty dictionary.
annotations (dict[str, Any]) – the type annotations for the new data class. Default is an empty dictionary.
parent_class (type) – the parent class for the new data class. Default is ABC (abstract base class).
- Returns:
The new data class created
- Return type:
type
- geneticengine.grammar.synthetic_grammar.make_non_terminal_names(count)
Returns a list of names for non_terminal_symbols.
- Parameters:
count (int)
- geneticengine.grammar.synthetic_grammar.make_non_terminal_class(name)
Returns a new abstract class, with the provided name.
- Parameters:
name (str)
- geneticengine.grammar.synthetic_grammar.make_production(index, nt, field_types)
Creates a class representing a Production.
- Parameters:
index (int)
nt (type)
field_types (list[type])
- Return type:
type
- geneticengine.grammar.synthetic_grammar.A
- geneticengine.grammar.synthetic_grammar.select_random(rd, how_many, candidates)
- Parameters:
rd (random.Random)
how_many (int)
candidates (list[A])
- Return type:
set[A]
- geneticengine.grammar.synthetic_grammar.create_arbitrary_grammar(seed, non_terminals_count, recursive_non_terminals_count, productions_per_non_terminal=lambda rd: ..., non_terminals_per_production=lambda rd: ..., base_types={int, bool})
Generates a random grammar, based on a particular seed.
- Parameters:
seed (int)
non_terminals_count (int)
recursive_non_terminals_count (int)
productions_per_non_terminal (Callable[[random.Random], int])
non_terminals_per_production (Callable[[random.Random], int])
base_types (set[type])
- Return type:
tuple[list[type], type]