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: Definition

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

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: ExpressionWalker

Convert terms such as P.s[c] or getattr(P, s)[c] at SelectByFirstColumn(P, s).

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

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: PatternWalker

Recognising datalog terms such as P.s[c] or getattr(P, s)[c].

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

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: Definition

Methods

__call__(*args, **kwargs)

Call self as a function.

apply(*args)

Builds a new expression using a tuple of its parameters

type

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: PatternWalker

Syntactic 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:
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

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: PatternWalker

Syntactic sugar to convert datalog rules having constants in the head to having equalities in the body.

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

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:
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.

rewrite_conditional_query(impl)

Translate an expression of the form

type

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: PatternWalker

Translate 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:
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_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: PatternWalker

Syntactic sugar to convert datalog terms P.s[c] to SelectByFirstColumn(P, s).

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

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: PatternWalker

Syntactic 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:
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

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