neurolang.expression_walker#

Functions

expression_iterator(expression[, ...])

Iterate traversing expression tree.

expression_iterator_constant(current_element)

fix_children_order(dfs, expression, children)

Classes

ChainedWalker(*walkers)

EntryPointPatternWalker(*args, **kwargs)

Pattern walker with an entrypoint.

ExpressionBasicEvaluator(*args, **kwargs)

ExpressionWalker(*args, **kwargs)

Walks through an expression and each of its arguments

FunctionApplicationToPythonLambda(*args, ...)

Convert a FunctionApplication expression with constant functor into a python lambda expression where the symbols are the parameters.

IdentityWalker(*args, **kwargs)

Walks through expressions without doing a thing.

PatternWalker(*args, **kwargs)

ReplaceExpressionWalker(symbol_replacements)

ReplaceExpressionsByValues(symbol_table)

ReplaceSymbolWalker(symbol_replacements)

ReplaceSymbolsByConstants(symbol_table)

ResolveSymbolMixin(*args, **kwargs)

TypedSymbolTableEvaluator([symbol_table])

TypedSymbolTableEvaluatorMixin([symbol_table])

class neurolang.expression_walker.EntryPointPatternWalker(*args, **kwargs)#

Pattern walker with an entrypoint. All walks must start from the entry point pattern. This is useful to enforce agreement with a global grammatical and syntactical construction.

match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.ExpressionBasicEvaluator(*args, **kwargs)#
match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.ExpressionWalker(*args, **kwargs)#

Walks through an expression and each of its arguments

match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.IdentityWalker(*args, **kwargs)#

Walks through expressions without doing a thing.

match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.PatternWalker(*args, **kwargs)#
match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.ReplaceExpressionsByValues(symbol_table)#
match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.ReplaceSymbolWalker(symbol_replacements)#
match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.ReplaceSymbolsByConstants(symbol_table)#
match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

class neurolang.expression_walker.TypedSymbolTableEvaluator(symbol_table=None)#
match(expression)#

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

Goes through the triplets in in patterns and calls the action specified by the first satisfied triplet.

pattern_match(pattern, expression)#

Return True if pattern matches expression.

Patterns are of the following form:

  • ... matches everything.

  • Expression class matches if expression is instance of the given class for any type.

  • Expression [T] matches if expression is instance of the given class with expression.type a subtype of T.

  • Expression [T](Pattern_0, Pattern_1, ....., Pattern_N) matches if expression is instance of the given class with expression.type a subtype of T and recursively matches the construction parameters of the instance on the types given as Pattern_0, Pattern_1, etc.

  • (Pattern_0, ....., Pattern_N) matches when expression is a tuple of length N + 1 where expression[0] matches Pattern_0, expression[1] matches Pattern_1, etc.

  • instance an instance of a python class not subclassing Expression matches when instance == expression

property patterns#

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

  • pattern: is an Expression class, or instance where construction parameters and the type can be replaced by an ellipsis … to signal a wildcard. See pattern_match() for more details.

  • guard: is a function mapping an Expression instance to a boolean or None.

  • action: is the method receiving the matching expression instance to be executed upon pattern and match being True.

type#

alias of Any

neurolang.expression_walker.add_entry_point_match(pattern, guard=None)#

Decorate by adding patterns to a PatternMatcher class.

Should be used as @add_match(PATTERN, GUARD) to turn the decorated method, receiving an instance of Expression into a matching case. See PatternMatcher.pattern_match() for more details on patterns.

Additionally, this decorator sets the entry point which should be the first match for specific walkers.

neurolang.expression_walker.add_match(pattern, guard=None)#

Decorate by adding patterns to a PatternMatcher class.

Should be used as @add_match(PATTERN, GUARD) to turn the decorated method, receiving an instance of Expression into a matching case. See PatternMatcher.pattern_match() for more details on patterns.

neurolang.expression_walker.expression_iterator(expression, include_level=False, dfs=True)#

Iterate traversing expression tree.

Iterates over elements (parameter_name, parameter_object) when include_level is False.

If include_level is True then the iterated elements are (parameter_name, parameter_object, depth_level).

If dfs is true the iteration is in DFS order else is in BFS.