Skip to content

eval_translator

translate_multi_rule_eval(rule_inputs, data_input, with_comments=False, custom_nodes=None)

Given some rule inputs and a data input, generate the corresponding ASP definition ready to be executed.

Parameters:

Name Type Description Default
rule_inputs List[RuleInput]

multiple rule input objects with the rule definitions

required
data_input DataInput

single data input with data to be evaluated against the rules

required
with_comments bool

whether the returning ASP statements should include ASP comments

False
custom_nodes Optional[Dict[str, Type]]

optional dictionary of custom nodes to support in the rule translation

None

Returns:

Type Description
RuleOutput

data object with the generated ASP definition

Source code in json_logic_asp/translator/eval_translator.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def translate_multi_rule_eval(
    rule_inputs: List[RuleInput],
    data_input: DataInput,
    with_comments: bool = False,
    custom_nodes: Optional[Dict[str, Type]] = None,
) -> RuleOutput:
    """
    Given some rule inputs and a data input, generate the corresponding ASP definition ready to be executed.
    :param rule_inputs: multiple rule input objects with the rule definitions
    :param data_input: single data input with data to be evaluated against the rules
    :param with_comments: whether the returning ASP statements should include ASP comments
    :param custom_nodes: optional dictionary of custom nodes to support in the rule translation
    :return: data object with the generated ASP definition
    """
    stmts: List[str] = []

    data_str = generate_single_data_asp_definition(data_input=data_input, with_comments=with_comments)
    rule_str, rule_mapping = generate_multiple_rule_asp_definition(
        rule_inputs=rule_inputs, with_comments=with_comments, custom_nodes=custom_nodes
    )

    stmts.extend(data_str.split("\n"))
    stmts.append("")
    stmts.extend(rule_str.split("\n"))
    stmts.append("")
    stmts.append(ShowStatement(PredicateNames.RULE, 1).to_asp_statement())

    return RuleOutput(
        statements=stmts,
        rule_mapping=rule_mapping,
    )

translate_single_rule_eval(rule_input, data_input, with_comments=False, custom_nodes=None)

Given a rule input and a data input, generate the corresponding ASP definition ready to be executed.

Parameters:

Name Type Description Default
rule_input RuleInput

single rule input objects with the rule definition

required
data_input DataInput

single data input with data to be evaluated against the rules

required
with_comments bool

whether the returning ASP statements should include ASP comments

False
custom_nodes Optional[Dict[str, Type]]

optional dictionary of custom nodes to support in the rule translation

None

Returns:

Type Description
RuleOutput

data object with the generated ASP definition

Source code in json_logic_asp/translator/eval_translator.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def translate_single_rule_eval(
    rule_input: RuleInput,
    data_input: DataInput,
    with_comments: bool = False,
    custom_nodes: Optional[Dict[str, Type]] = None,
) -> RuleOutput:
    """
    Given a rule input and a data input, generate the corresponding ASP definition ready to be executed.
    :param rule_input: single rule input objects with the rule definition
    :param data_input: single data input with data to be evaluated against the rules
    :param with_comments: whether the returning ASP statements should include ASP comments
    :param custom_nodes: optional dictionary of custom nodes to support in the rule translation
    :return: data object with the generated ASP definition
    """
    return translate_multi_rule_eval(
        rule_inputs=[rule_input], data_input=data_input, with_comments=with_comments, custom_nodes=custom_nodes
    )