Esempio n. 1
0
 def enterConstant(self, ctx: frameQLParser.ConstantContext):
     #ExpressionTree
     if len(self.FIFO) == 0:
         return
     if len(ctx.getText().split('AND')) > 1 or len(
             ctx.getText().split('OR')) > 1:
         return
     if len(self.arithmeticFIFO) > 0:
         self.arithmeticFIFO[-1].children.append(
             ExpressionConstant(ctx.getText()))
     elif self.currentComparisonExpression != None:
         self.currentComparisonExpression.children.append(
             ExpressionConstant(ctx.getText()))
Esempio n. 2
0
 def enterExpressionAtomPredicate(
         self, ctx: frameQLParser.ExpressionAtomPredicateContext):
     if self.currentComparisonExpression.children[0] == None:
         if ctx.getText() in self.listAttributes:
             self.currentComparisonExpression.children[0] = ExpressionTuple(
                 ctx.getText())
         else:
             self.currentComparisonExpression.children[
                 0] = ExpressionConstant(ctx.getText())
     elif self.currentComparisonExpression.children[
             0] != None and self.currentComparisonExpression.children[
                 1] == None:
         if ctx.getText() in self.listAttributes:
             self.currentComparisonExpression.children[1] = ExpressionTuple(
                 ctx.getText())
         else:
             self.currentComparisonExpression.children[
                 1] = ExpressionConstant(ctx.getText())
Esempio n. 3
0
    def enterExpressionAtomPredicate(
            self, ctx: frameQLParser.ExpressionAtomPredicateContext):
        self.count += 1
        self.listAttributes = ['ID', 'CLASS', 'REDNESS', 'SPEED']

        if (self.currentComparisonExpression != None):
            if self.currentComparisonExpression.children[0] == None:
                if ctx.getText() in self.listAttributes:
                    self.currentComparisonExpression.children[
                        0] = ExpressionTuple(ctx.getText())
                else:
                    self.currentComparisonExpression.children[
                        0] = ExpressionConstant(ctx.getText())
            elif self.currentComparisonExpression.children[
                    0] != None and self.currentComparisonExpression.children[
                        1] == None:
                if ctx.getText() in self.listAttributes:
                    self.currentComparisonExpression.children[
                        1] = ExpressionTuple(ctx.getText())
                else:
                    self.currentComparisonExpression.children[
                        1] = ExpressionConstant(ctx.getText())
Esempio n. 4
0
    def traverseExpTree(node, children=[]):

        if hasattr(node, 'children'):
            if len(node.children) == 0:
                return
            for child in node.children:
                traverseExpTree(child, children)
        if hasattr(node, 'attribute'):
            children.append(ExpressionConstant(node.attribute))
            print(node.attribute, end=', ')
        elif hasattr(node, 'data'):
            children.append(ExpressionConstant(node.data))
            print(node.data, end=', ')
        elif hasattr(node, 'operator'):
            if node.operator in ['+', '-', '*', '/']:
                ExpressionArithmetic(children, node.operator)
            elif node.operator in ['AND', 'OR', 'NOT']:
                ExpressionLogical(children, node.operator, node.parent)
            else:
                ExpressionComparison(children, node.operator)
            children = []
            print(node.operator, end=', ')
        else:
            print(node, end=', ')
Esempio n. 5
0
    def enterMathExpressionAtom(self,
                                ctx: frameQLParser.MathExpressionAtomContext):
        operator = ctx.mathOperator().getText()
        left = ExpressionTuple(ctx.getText().split(operator)[0])
        right = ExpressionConstant(ctx.getText().split(operator)[1])

        if (self.currentComparisonExpression != None):
            if self.currentComparisonExpression.children[0].data == (
                    ctx.getText()):
                self.currentComparisonExpression.children[
                    0] = ExpressionArithmetic([left, right], operator)
            elif self.currentComparisonExpression.children[
                    0] != None and self.currentComparisonExpression.children[
                        1].data == (ctx.getText()):
                self.currentComparisonExpression.children[
                    1] = ExpressionArithmetic([left, right], operator)
Esempio n. 6
0
from Expressions.ExpressionComparison import ExpressionComparison
from Expressions.ExpressionConstant import ExpressionConstant
from Expressions.ExpressionTuple import ExpressionTuple
from Expressions.ExpressionLogical import ExpressionLogical
from Expressions.ExpressionArithmetic import ExpressionArithmetic

from Nodes.NodeCondition import NodeCondition
from Nodes.NodeCross import NodeCross
from Nodes.NodeProjection import NodeProjection

data = [[0, 50, 'bus'], [1, 100, 'car'], [2, 50, 'van'], [3, 150, 'bus'],
        [4, 120, 'bus'], [5, 130, 'car'], [6, 250, 'bus'], [7, 70, 'van'],
        [8, 110, 'bus']]

expression1 = ExpressionTuple('REDNESS')  #class
expression2 = ExpressionConstant('bus')  #bus
expression31 = ExpressionTuple('CLASS')
expression32 = ExpressionConstant('30')
expression3 = ExpressionArithmetic([expression31, expression32], '-')  #redness
expression4 = ExpressionConstant('100')  #100
expression5 = ExpressionComparison([expression1, expression2], '=')  #=
expression6 = ExpressionComparison([expression3, expression4], '>')  #>
expression7 = ExpressionLogical([expression5, expression6], 'AND')  #AND

node1 = NodeCross(data)
node2 = NodeCondition(node1, expression7)
node3 = NodeProjection(node2, [0, 2])
print(node3.processing())