neurolang.frontend.datalog.sugar package¶
Set of syntactic sugar processors at the intermediate level.
- class neurolang.frontend.datalog.sugar.Column(set_symbol, column_position)¶
Bases:
DefinitionMethods
__call__(*args, **kwargs)Call self as a function.
apply(*args)Builds a new expression using a tuple of its parameters
unapply()Returns a tuple of parameters used to build the expression.
cast
change_type
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.ConvertAttrSToSelectByColumn(*args, **kwargs)¶
Bases:
ExpressionWalkerConvert terms such as P.s[c] or getattr(P, s)[c] at SelectByFirstColumn(P, s).
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.conversion
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
process_expression
process_iterable_argument
walk
- conversion(expression)¶
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.RecogniseSSugar(*args, **kwargs)¶
Bases:
PatternWalkerRecognising datalog terms such as P.s[c] or getattr(P, s)[c].
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.constant
others
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
s_sugar
symbol
walk
- constant(expression)¶
- others(expression)¶
- s_sugar(expression)¶
- symbol(expression)¶
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.SelectByFirstColumn(set_symbol, selector)¶
Bases:
DefinitionMethods
__call__(*args, **kwargs)Call self as a function.
apply(*args)Builds a new expression using a tuple of its parameters
unapply()Returns a tuple of parameters used to build the expression.
cast
change_type
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.TranslateColumnsToAtoms(*args, **kwargs)¶
Bases:
PatternWalkerSyntactic sugar to handle cases where the first column is used as a selector. Specifically cases such as
>>> Implication(B(z), C(z, Column(A, 1)))
is transformed to
>>> Implication(B(z), Conjunction((A(fresh0, fresh1), C(z, fresh1))))
If this syntactic sugar is on the head, then every atom that, by type has two arguments, but only one is used, will be replaced by the case where first argument is the sugared element.
>>> Implication(Column(A, 2), B(Column(A, 2), x)))
is transformed to
>>> Implication(A(fresh0, fresh1, fresh2), B(fresh2, x)))
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.application_column_sugar
conjunction_column_sugar
implication_column_sugar
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
walk
- application_column_sugar(expression)¶
- conjunction_column_sugar(expression)¶
- implication_column_sugar(expression)¶
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.TranslateHeadConstantsToEqualities(*args, **kwargs)¶
Bases:
PatternWalkerSyntactic sugar to convert datalog rules having constants in the head to having equalities in the body.
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.head_constants_to_equalities
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
walk
- head_constants_to_equalities(expression)¶
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.TranslateProbabilisticQueryMixin(*args, **kwargs)¶
Bases:
PatternWalker- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.Translate an expression of the form
conditional_query
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
walk
within_language_prob_query
- conditional_query(implication)¶
- rewrite_conditional_query(impl)¶
- Translate an expression of the form
P(x, y, z) :- Q(x) & R(y) // T(z)
- to its equivalent expression
F1(x, y, z, PROB) :- Q(x) & R(y) &T(z) F2(z, PROB) :- T(z) P(x, y, z, p) :- F1(x, y, z, p1) & F2(z, p2) & (p == p1 / p2)
- type = typing.Any¶
- within_language_prob_query(implication)¶
- class neurolang.frontend.datalog.sugar.TranslateQueryBasedProbabilisticFactMixin(*args, **kwargs)¶
Bases:
PatternWalkerTranslate an expression of the form
(P @ y)(x) :- Q(x)
to its equivalent query-based probabilistic fact
P(x) : y :- Q(x)
This is useful when the rule was defined at the frontend level using the sugar syntax (P @ y)[x] = Q[x].
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
query_based_probchoice_wannabe
query_based_probfact_wannabe
walk
- query_based_probchoice_wannabe(impl)¶
- query_based_probfact_wannabe(impl)¶
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.TranslateSSugarToSelectByColumn(*args, **kwargs)¶
Bases:
PatternWalkerSyntactic sugar to convert datalog terms P.s[c] to SelectByFirstColumn(P, s).
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
replace_s_getattr_by_first_column
walk
- replace_s_getattr_by_first_column(expression)¶
- type = typing.Any¶
- class neurolang.frontend.datalog.sugar.TranslateSelectByFirstColumn(*args, **kwargs)¶
Bases:
PatternWalkerSyntactic sugar to handle cases where the first column is used as a selector. Specifically cases such as
>>> Implication(B(z), C(z, SelectByFirstColumn(A, c)))
is transformed to
>>> Implication(B(z), Conjunction((A(c, fresh), C(z, fresh))))
If this syntactic sugar is on the head, then every atom that, by type has two arguments, but only one is used, will be replaced by the case where first argument is the sugared element.
>>> Implication(SelectByFirstColumn(A, c), Conjunction((eq(x), B(x))))
is transformed to
>>> Implication(A(c, fresh), Conjunction((eq(fresh, x), B(x))))
- Attributes:
patternsProperty 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
Trueifpatternmatchesexpression.application_column_sugar
conjunction_column_sugar
implication_column_sugar
implication_select_by_left_head
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
walk
- application_column_sugar(expression)¶
- conjunction_column_sugar(expression)¶
- implication_column_sugar(expression)¶
- implication_select_by_left_head(expression)¶
- type = typing.Any¶
Subpackages¶
Submodules¶
- neurolang.frontend.datalog.sugar.spatial module
DetectEuclideanDistanceBoundMatrixDetectEuclideanDistanceBoundMatrix.any_other_expression()DetectEuclideanDistanceBoundMatrix.get_distance_upper_bound()DetectEuclideanDistanceBoundMatrix.get_range_pred_for_coord()DetectEuclideanDistanceBoundMatrix.get_var_to_euclidean_equality()DetectEuclideanDistanceBoundMatrix.implication()DetectEuclideanDistanceBoundMatrix.type
TranslateEuclideanDistanceBoundMatrixMixinTranslateEuclideanDistanceBoundMatrixMixin.euclidean_spatial_bound()TranslateEuclideanDistanceBoundMatrixMixin.safe_range_pred_to_coord_set()TranslateEuclideanDistanceBoundMatrixMixin.solve_spatial_bound()TranslateEuclideanDistanceBoundMatrixMixin.typeTranslateEuclideanDistanceBoundMatrixMixin.upper_bound_to_max_dist()