Skip to content

Commit

Permalink
Made first version for translation using !natural_language
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Dec 11, 2024
1 parent 32f961a commit d1a544b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ class TestedType:
class ExpressionString(str):
pass


class ReturnOracle(dict):
pass

class NaturalLanguageMap(dict):
pass


OptionDict = dict[str, int | bool]
YamlObject = (
YamlDict | list | bool | float | int | str | None | ExpressionString | ReturnOracle
YamlDict | list | bool | float | int | str | None | ExpressionString | ReturnOracle | NaturalLanguageMap
)


Expand Down Expand Up @@ -137,6 +139,12 @@ def _return_oracle(loader: yaml.Loader, node: yaml.Node) -> ReturnOracle:
), f"A custom oracle must be an object, got {result} which is a {type(result)}."
return ReturnOracle(result)

def _natural_language_map(loader: yaml.Loader, node: yaml.Node) -> NaturalLanguageMap:
result = _parse_yaml_value(loader, node)
assert isinstance(
result, dict
), f"A natural language map must be an object, got {result} which is a {type(result)}."
return NaturalLanguageMap(result)

def _parse_yaml(yaml_stream: str) -> YamlObject:
"""
Expand All @@ -148,6 +156,7 @@ def _parse_yaml(yaml_stream: str) -> YamlObject:
yaml.add_constructor("!" + actual_type, _custom_type_constructors, loader)
yaml.add_constructor("!expression", _expression_string, loader)
yaml.add_constructor("!oracle", _return_oracle, loader)
yaml.add_constructor("!natural_language", _natural_language_map, loader)

try:
return yaml.load(yaml_stream, loader)
Expand Down

0 comments on commit d1a544b

Please sign in to comment.