neurolang.probabilistic.magic_sets_processing module

class neurolang.probabilistic.magic_sets_processing.ReplaceWLQWalker(wlq_expressions)

Bases: ExpressionWalker

Initialize the walker with matchings {S{D} : S{D2}}. The walker will then match rules that look like D(x, y, PROB) :- A(x, y)

and replace them by

D(x, y, PROB) :- D2(x, y) D2(x, y) :- A(x, y)

Attributes:
patterns

Property holding an iterator of triplets (pattern, guard, action).

Methods

match(expression)

Find the action for a given expression by going through the patterns.

pattern_match(pattern, expression)

Return True if pattern matches expression.

type

implication

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

process_expression

process_iterable_argument

replace_probabilistic_predicate

replace_probabilistic_queries

walk

implication(impl)
replace_probabilistic_predicate(expr)
replace_probabilistic_queries(impl)
type = typing.Any
neurolang.probabilistic.magic_sets_processing.probabilistic_postprocess_magic_rules(program: DatalogProgram, query: Implication, magic_rules: Union)

Within language probabilistic queries (wlq) cannot be solved when they depend on one another, which is something that Magic Sets rewrite can introduce.

This post processing step transforms a program where a wlq depends on another, i.e.

A(x, PROB) :- B(x), C(x) C(x) :- D(x, p) D(x, PROB) :- E(x)

into

A(x, PROB) :- B(x), C(x) C(x) :- D2(x) D(x, PROB) :- D2(x) D2(x) :- E(x)

neurolang.probabilistic.magic_sets_processing.update_rules_with_new_prob_expressions(magic_rules, rules_to_update, wlq_exprs)