neurolang.datalog.constraints_representation module

Compiler for the intermediate representation of a Datalog program. The DatalogProgram class processes the intermediate representation of a program and extracts the extensional, intensional, and builtin sets and has support for constraints.

class neurolang.datalog.constraints_representation.DatalogConstraintsMixin(*args, **kwargs)

Bases: PatternWalker

Attributes:
patterns

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

Methods

constraints()

Function that returns the constraints contained in the Datalog program.

get_constraints()

Returns the contraints in a dictionary, where the key is the functor of the consequent of each of the rules.

match(expression)

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

pattern_match(pattern, expression)

Return True if pattern matches expression.

set_constraints(categorized_constraints)

This function receives a dictionary with the contraints organized according to the functor of its consequent and is in charge of setting it both in the symbol table and in the global variable categorized_contraints, useful for XRewriter optimizations.

type

add_existential_rules

add_logic_constraint

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

walk

add_existential_rules(rules)
add_logic_constraint(expression)
categorized_constraints = {}
constraints()

Function that returns the constraints contained in the Datalog program.

Returns:
Union of formulas containing all constraints loaded into the program.
existential_rules = {}
get_constraints()

Returns the contraints in a dictionary, where the key is the functor of the consequent of each of the rules.

Returns:
Dictionary containing all constraints loaded in the datalog program,
indexed according to the functor of the rule consequent.
protected_keywords = {'__constraints__'}
set_constraints(categorized_constraints)

This function receives a dictionary with the contraints organized according to the functor of its consequent and is in charge of setting it both in the symbol table and in the global variable categorized_contraints, useful for XRewriter optimizations.

Parameters:
categorized_constraintsdict

Dictionary of constraints where each key is the functor of the consequent of the rules and the values are lists of contraints with each rule associated to the corresponding functor.

type = typing.Any
class neurolang.datalog.constraints_representation.DatalogConstraintsProgram(symbol_table=None)

Bases: DatalogConstraintsMixin, DatalogProgramMixin, ExpressionWalker

Attributes:
included_constants
included_functions
patterns

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

Methods

constant_equals

constraints()

Function that returns the constraints contained in the Datalog program.

get_constraints()

Returns the contraints in a dictionary, where the key is the functor of the consequent of each of the rules.

infer_iterable_type(iterable)

Infer the type of iterable elements without modifying the iterable.

match(expression)

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

pattern_match(pattern, expression)

Return True if pattern matches expression.

set_constraints(categorized_constraints)

This function receives a dictionary with the contraints organized according to the functor of its consequent and is in charge of setting it both in the symbol table and in the global variable categorized_contraints, useful for XRewriter optimizations.

type

union_of_cq(expression)

This pattern is here to avoid processing the full program when one rule is rewritten.

add_existential_rules

add_extensional_predicate_from_tuples

add_included_constants_and_functions_to_symbol_table

add_logic_constraint

builtins

extensional_database

fact

intensional_database

new_set

pattern_match_expression

pattern_match_expression_parameters

pattern_match_expression_tuple

pattern_match_tuple

pop_scope

predicate_terms

process_expression

process_iterable_argument

push_scope

statement_intensional

symbol

walk

protected_keywords = {'__constraints__'}
type = typing.Any
class neurolang.datalog.constraints_representation.RightImplication(antecedent, consequent)

Bases: LogicOperator

This class defines implications to the right. They are used to define constraints in datalog programs. The functionality is the same as that of an implication, but with body and head inverted in position.

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
neurolang.datalog.constraints_representation.reachable_code(query, datalog)

Produces the code reachable by a query

Parameters:
queryImplication

Rule to figure out the reachable program from

datalogDatalogProgram

datalog instance containing the EDB and IDB.

Returns:
ExpressionBlock

Code needed to solve the query.