neurolang.probabilistic.query_resolution module

class neurolang.probabilistic.query_resolution.AddNeededProjections(needed_projections)

Bases: PatternWalker

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

add_projection

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

walk

add_projection(expression)
type = typing.Any
class neurolang.probabilistic.query_resolution.FilterZeroProbability(*args, **kwargs)

Bases: ExpressionWalker

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

add_zero_filter

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

process_expression

process_iterable_argument

walk

add_zero_filter(expression)
type = typing.Any
class neurolang.probabilistic.query_resolution.FloatArithmeticSimplifier(*args, **kwargs)

Bases: PatternWalker

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

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

simplify_mul_left

simplify_mul_right

walk

simplify_mul_left(expression)
simplify_mul_right(expression)
type = typing.Any
class neurolang.probabilistic.query_resolution.QueryBasedProbFactToDetRule(*args, **kwargs)

Bases: PatternWalker

Translate a query-based probabilistic fact to two rules. A deterministic rule that takes care of inferring the set of probabilistic tuples and their probabilities and a probabilistic rule that transforms the result from the deterministic resolution into a proper probabilistic table by re-attaching the deterministically-obtained probabilities.

For example, the rule P(x) : f(x) :- Q(x) is translated into the rules

_f1_(_f2_, x) :- Q(x), _f2_ = f(x) P(x) : _f2_ :- _f1_(_f2_, x)

where _f1_ and _f2_ are fresh symbols. Note: we make sure not to expose the resulting _f1_ relation to the user, as it is not part of her program.

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

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

query_based_probafact

union_with_query_based_pfact

walk

query_based_probafact(impl)
type = typing.Any
union_with_query_based_pfact(union)
class neurolang.probabilistic.query_resolution.RAQueryOptimiser(*args, **kwargs)

Bases: EliminateTrivialProjections, PushInSelections, RenameOptimizations, SimplifyExtendedProjectionsWithConstants, FloatArithmeticSimplifier, PushUnnamedSelectionsUp, ExpressionWalker

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

convert_extended_projection_2_projection

convert_extended_projection_2_rename

convert_rename_column

eliminate_trivial_nested_projection

eliminate_trivial_nested_unnamed_projection

eliminate_trivial_number_columns

eliminate_trivial_projection

eliminate_trivial_projection_number_columns

eliminate_trivial_selection_number_columns

invert_selection_order

merge_nested_rename_columns

merge_rename_column_group_by

merge_rename_columns_extended_projection

nested_extended_projection_constant

nested_extended_projection_leftnaturaljoin_constant

nested_extended_projection_leftnaturaljoin_constantr

nested_extended_projection_naturaljoin_constant_l

nested_extended_projection_naturaljoin_constantr

nested_extended_projection_outernaturaljoin_constant

nested_extended_projection_outernaturaljoin_constantr

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

process_expression

process_iterable_argument

push_and_rename_in_naturaljoin

push_computed_columns_up

push_computed_columns_up_flip

push_computed_columns_up_left

push_computed_columns_up_outer

push_rename_past_groupby

push_rename_past_projection

push_rename_past_selection

push_replace_null_in_ext_proj

push_selection_above_name_columns

push_selection_above_projection

push_selection_in_extended_projection

push_selection_in_groupby

push_selection_in_left

push_selection_in_leftnaturaljoin_left

push_selection_in_leftnaturaljoin_right

push_selection_in_outernaturaljoin_left

push_selection_in_outernaturaljoin_right

push_selection_in_projection

push_selection_in_replace_null

push_selection_in_right

remove_trivial_rename

replace_trivial_agg_groupby

simplify_mul_left

simplify_mul_right

simplify_projection_extended_projection

simplify_renames_name

split_rename_left_naturaljoin

split_rename_naturaljoin

split_rename_outer_naturaljoin

standardize_projected_column

switch_rename_replace_null

walk

type = typing.Any
neurolang.probabilistic.query_resolution.compute_probabilistic_solution(det_edb, pfact_db, pchoice_edb, prob_idb, succ_prob_solver, marg_prob_solver, check_qbased_pfact_tuple_unicity=False)
neurolang.probabilistic.query_resolution.compute_projections_needed_to_reintroduce_head_terms(ra_query: RelationalAlgebraOperation, flat_query: Implication, unified_query: Implication) Tuple[FunctionApplicationListMember, ...]

Produce the extended projection list for the terms that have been removed through unification of the query.

There are two such cases:

1. A head variable was repeated, such as in ans(y, y) and the extensional plan computes all possible values for y but will output only one column. This function makes sure that a second column for y is outputed, and that the resulting solution set will be a binary relation, as required.

2. The query’s head contains a constant, such as in ans(2, y), in which case a constant column is added to the solution set.

neurolang.probabilistic.query_resolution.generate_provenance_query_solver(symbol_table, run_relational_algebra_solver, needed_projections=None, solver_class=ProbSemiringToRelationalAlgebraSolver[typing.Any])

Generate a walker that solves a RAP query.

Parameters:
symbol_tableMapping

Mapping from symbols to probabilistic or deterministic sets to solve the query.

run_relational_algebra_solverbool

if true the walker will return a ProvenanceAlgebraSet containing a NamedAlgebraSet as relation attribute. If false the walker will produce a relational algebra expression as relation attribute.

solver_class: PatternWalker

class to translate a provenance RA sets program into a RA program. Default is ProbSemiringToRelationalAlgebraSolver.

neurolang.probabilistic.query_resolution.lift_solve_marg_query(rule, cpl, succ_solver)

Solve a MARG query on a CP-Logic program.

Parameters:
queryImplication

Consequent must be of type Condition. MARG query of the form ans(x) :- P(x).

cpl_programCPLogicProgram

CP-Logic program on which the query should be solved.

Returns:
ProvenanceAlgebraSet

Provenance set labelled with probabilities for each tuple in the result set.