Skip to content

Commit

Permalink
Add support for aggregate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhorcas committed Oct 24, 2024
1 parent 02f9f86 commit 0ca7c21
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import functools
from typing import Any, Optional

from antlr4 import CommonTokenStream, FileStream
Expand Down Expand Up @@ -285,14 +286,28 @@ def process_aggregate_function_constraint(
if isinstance(string_function, UVLPythonParser.LengthAggregateFunctionContext):
literal = string_function.reference()
return Node(ASTOperation.LEN, Node(literal.getText().replace('"', '')))
else:
raise NotImplementedError(f"String function {type(string_function)} not handled.")
elif isinstance(aggregate_function, UVLPythonParser.NumericAggregateFunctionExpressionContext):
numeric_function = aggregate_function.numericAggregateFunction()
if isinstance(numeric_function, UVLPythonParser.FloorAggregateFunctionContext):
literal = numeric_function.reference()
return Node(ASTOperation.FLOOR, Node(literal.getText().replace('"', '')))
elif isinstance(numeric_function, UVLPythonParser.CeilAggregateFunctionContext):
literal = numeric_function.reference()
return Node(ASTOperation.CEIL, Node(literal.getText().replace('"', '')))
else:
raise NotImplementedError(f"Numeric function {type(numeric_function)} not handled.")
elif isinstance(aggregate_function, UVLPythonParser.AvgAggregateFunctionContext):
pass
#literals = aggregate_function.reference()
#print(literals)
#return Node(ASTOperation.AVG, literal.getText().replace('"', ''))
literals = aggregate_function.reference()
elements = [Node(literal.getText().replace('"', '')) for literal in literals]
return functools.reduce(lambda node, left: AST.create_binary_operation(ASTOperation.AVG,
Node(left), node).root, elements)
elif isinstance(aggregate_function, UVLPythonParser.SumAggregateFunctionContext):
pass
#print("sum")
literals = aggregate_function.reference()
elements = [Node(literal.getText().replace('"', '')) for literal in literals]
return functools.reduce(lambda node, left: AST.create_binary_operation(ASTOperation.SUM,
Node(left), node).root, elements)
else:
raise NotImplementedError(f"Aggregate function {type(aggregate_function)} not handled.")
return None
Expand Down

0 comments on commit 0ca7c21

Please sign in to comment.