relational/optimizer.py
LtWorf f5e16a0cf4 stub for optimizer
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@73 014f5005-505e-4b48-8d0a-63407b615a7c
2008-12-10 17:42:41 +00:00

55 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding=UTF-8
# Relational
# Copyright (C) 2008 Salvo "LtWorf" Tomaselli
#
# Relation is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
'''This module optimizes relational expressions into ones that require less time to be executed'''
RELATION=0
UNARY=1
BINARY=2
class node (object):
'''This class is a node of a relational expression. Leaves are relations and internal nodes are operations.'''
def __init__(self,expression):
'''expression must be a valid relational algrbra expression that would be accepted by the parser
and must be utf16'''
self.kind=0
self.name="a"
self.prop=""
'''*-ᑎᐅᐊᐅLEFTᐊᐅRIGHTᐊᐅFULLᐊπσρ'''
'''(a (a b c d)) ᑎ c - σ i==3(πa,b(a b ᑎ c))'''
for i in list(expression):
print i
def __str__(self):
if (self.kind==RELATION):
return self.name
elif (self.kind==UNARY):
return self.name + " "+ self.prop+ " (" + self.child +")"
elif (self.kind==BINARY):
return "("+ self.left + ") " + self.name + " (" + self.right+ ")"
n=node(u"(a b) c d")
print n