neurolang.expression_walker#
Functions
|
Iterate traversing expression tree. |
|
|
|
Classes
|
|
|
Pattern walker with an entrypoint. |
|
|
|
Walks through an expression and each of its arguments |
|
Convert a FunctionApplication expression with constant functor into a python lambda expression where the symbols are the parameters. |
|
Walks through expressions without doing a thing. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Walk each expression object once during a walk. |
|
Walk once each expression that is the argument of several others in the expression walked, keeping only their results: for solvers, whose results are relations to free once used. |
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- 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
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
- class neurolang.expression_walker.WalkExpressionsOnceMixin(*args, **kwargs)#
Walk each expression object once during a walk.
An action that rewrites an expression walks the rewritten expression, whose children have been walked already, and an expression can be the argument of several others: a plan whose operations use their operand twice is a DAG whose tree is exponentially larger. The result of walking an expression is kept, by identity of the expression, until the outermost walk ends, which makes the walk linear in the number of distinct expressions. Only for walkers whose result of walking an expression does not change during a walk.
- match(expression)#
Find the action for a given expression by going through the
patterns.Goes through the triplets in in
patternsand calls the action specified by the first satisfied triplet.
- pattern_match(pattern, expression)#
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == 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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
Walk once each expression that is the argument of several others in the expression walked, keeping only their results: for solvers, whose results are relations to free once used.
Find the action for a given expression by going through the
patterns.Goes through the triplets in in
patternsand calls the action specified by the first satisfied triplet.
Return
Trueifpatternmatchesexpression.Patterns are of the following form:
...matches everything.Expressionclass matches ifexpressionis instance of the given class for anytype.Expression[T]matches ifexpressionis instance of the given class withexpression.typea subtype ofT.Expression[T](Pattern_0, Pattern_1, ....., Pattern_N)matches ifexpressionis instance of the given class withexpression.typea subtype ofTand recursively matches the construction parameters of the instance on the types given asPattern_0,Pattern_1, etc.(Pattern_0, ....., Pattern_N)matches when expression is atupleof length N + 1 whereexpression[0]matchesPattern_0,expression[1]matchesPattern_1, etc.instancean instance of a python class not subclassingExpressionmatches wheninstance == expression
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. Seepattern_match()for more details.guard: is a function mapping an Expression instance to a boolean orNone.action: is the method receiving the matchingexpressioninstance to be executed upon pattern and match beingTrue.
alias of
Any
- neurolang.expression_walker.add_entry_point_match(pattern, guard=None)#
Decorate by adding patterns to a
PatternMatcherclass.Should be used as @add_match(PATTERN, GUARD) to turn the decorated method, receiving an instance of
Expressioninto a matching case. SeePatternMatcher.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
PatternMatcherclass.Should be used as @add_match(PATTERN, GUARD) to turn the decorated method, receiving an instance of
Expressioninto a matching case. SeePatternMatcher.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.