jacques package¶
Subpackages¶
Submodules¶
jacques.constants module¶
Constants for Jacques.
jacques.server module¶
- class jacques.server.ExampleModel(*, id: str, dsl: str, code: str)¶
Bases:
BaseModel- code: str¶
- dsl: str¶
- id: str¶
- class jacques.server.JacquesServer(host: str, port: int)¶
Bases:
objectJacquesServer is a class that runs a FastAPI server providing REST API to interact with backend.
- async jacques.server.export_rules(filename: ExportRequest)¶
Export rules to a file
- Parameters:
filename – filename to export to
- Returns:
Status object
- async jacques.server.get_rule_source(rule_id: str)¶
Request a rule source code.
- Parameters:
rule_id – rule id
- Returns:
rule source code
- async jacques.server.get_rules()¶
Get all rules request:
- Returns:
list of rules
- async jacques.server.override(rule: OverridenRuleModel)¶
Sends a rule override to backend
- Parameters:
rule – rule override object
- Returns:
status of the operation
- async jacques.server.process_all_examples()¶
Process all examples supplied to jacques – request
- Returns:
Status object
- async jacques.server.push_example(example: ExampleModel)¶
Send an example to Jacques
- Parameters:
example – ExampleModel - example to be sent
- Returns:
Status
- async jacques.server.reset()¶
Reset the backend state.
- Returns:
Status object
- async jacques.server.translate(request: TranslationRequest)¶
Makes a request to the server to translate a DSL string into Python code.
- Parameters:
request – A TranslationRequest object containing the DSL string.
- Returns:
A TranslationResponse object containing the Python code.
jacques.utils module¶
This module provides reuseable utilities for many of the other modules in the jacques package.
- jacques.utils.dict_to_string(dictionary: dict) str¶
- jacques.utils.gaussian(x, mu=0, sig=1)¶
- jacques.utils.id_generator()¶
- jacques.utils.indent(string: str, indentation: int = 1) str¶
- jacques.utils.is_float(string) bool¶
- jacques.utils.is_superstring(long: str, short: str)¶
- jacques.utils.key_by_value(dictionary, value, compare_callback=None)¶
- jacques.utils.list_compare(list1: List, list2: List, lambda_left: Optional[Callable] = None, lambda_right: Optional[Callable] = None) bool¶
- jacques.utils.sanitize(string: str) str¶
- jacques.utils.sanitize_whitespace_and_symbols(string: str) str¶
Module contents¶
- class jacques.Jacques¶
Bases:
objectThe core class of the package.
- encountered(obj)¶
Register an object name as encountered.
- Parameters:
obj – The object name to register.
- except_match(example_id: str, source_code_regex: str)¶
Add a regex to the list of exceptions for the given example.
- Parameters:
example_id – The id of the example to add the exception to.
source_code_regex – The regex to add to the list of exceptions.
- export_rules(filename: str = 'rules_exported.py')¶
Export the ruleset to a file.
- Parameters:
filename – The name of the file to export the ruleset to.
- get_rule_by_name(name: str) Rule¶
Get a rule by its name.
- Parameters:
name – The name of the rule to get.
- Returns:
The rule with the given name.
- override_rule(rule: OverridenRule)¶
Override a rule. Immediately registers it with code generator.
- Parameters:
rule – The rule to override.
- process_all_examples()¶
Process all examples and extract rules from them. This method is to be called after providing all desired examples.
- push_example(dsl_string: str, code_string: str) None¶
Push an example to the list of examples.
- Parameters:
dsl_string – The DSL string of the example.
code_string – The code string of the example.
- push_examples_from_file(path: str) None¶
Push examples from a file.
- Parameters:
path – The path to the file to push examples from.
- Raises:
FileNotFoundError – If the file does not exist.
- push_init_statement(dsl_string: str, code_string: str) None¶
- remove_example(example: Example)¶
Remove an example from the list of examples.
- Parameters:
example – The example to remove.
- reset()¶
Reset the ruleset, code generator, and all of Jacque runtime memory.
- class jacques.JacquesServer(host: str, port: int)¶
Bases:
objectJacquesServer is a class that runs a FastAPI server providing REST API to interact with backend.