forked from potassco/eclingo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from jorgefandinno/lute/reificationStep4_testi…
…ngAST Lute/reification step4 testing ast
- Loading branch information
Showing
4 changed files
with
129 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
clingo==5.5.2 | ||
clingo==5.6.2 | ||
clingox==1.2.0.post4 | ||
--extra-index-url https://test.pypi.org/simple/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Module providing an AST function Trasnformer""" | ||
import clingo | ||
from clingo import ast | ||
from clingo.ast import ASTType, Transformer | ||
|
||
|
||
def _rule_to_symbolic_term_adapter(rules): | ||
"""Helper function""" | ||
rule_trans = SymbolicTermToFunctionTransformer() | ||
rule = rule_trans.visit_sequence(rules) | ||
return rule | ||
|
||
|
||
class SymbolicTermToFunctionTransformer(Transformer): | ||
"""Transforms a SymbolicTerm AST into a Function AST""" | ||
|
||
def visit_Interval(self, term): # pylint: disable=invalid-name | ||
"""Visit AST to ensure right Interval element is SymbolicTerm""" | ||
|
||
assert term.right.ast_type == ASTType.SymbolicTerm | ||
|
||
return term | ||
|
||
def visit_Heuristic(self, term): # pylint: disable=invalid-name | ||
"""Visit AST to ensure modifier Heuristic element is SymbolicTerm""" | ||
|
||
new_args = [] | ||
for x in term.atom.symbol.arguments: | ||
if x.ast_type == ASTType.SymbolicTerm: | ||
|
||
location = x.location | ||
symbol = x.symbol | ||
name = symbol.name | ||
arguments = symbol.arguments | ||
|
||
function = ast.Function(location, name, arguments, False) | ||
new_args.append(function) | ||
term.atom.symbol.arguments = new_args | ||
|
||
final_atom = ast.SymbolicAtom(term.atom.symbol) | ||
fin_heur = ast.Heuristic( | ||
term.location, | ||
final_atom, | ||
term.body, | ||
term.bias, | ||
term.priority, | ||
term.modifier, | ||
) | ||
|
||
return fin_heur | ||
|
||
def visit_SymbolicTerm(self, term): # pylint: disable=invalid-name | ||
"""Visit AST to find SymbolicTerm""" | ||
|
||
if term.symbol.type != clingo.SymbolType.Function: | ||
return term | ||
|
||
location = term.location | ||
symbol = term.symbol | ||
name = symbol.name | ||
arguments = symbol.arguments | ||
|
||
function = ast.Function(location, name, arguments, False) | ||
return function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters