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