forked from florentdelgrange/projetBdd1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
171 lines (156 loc) · 6.24 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
__author__ = 'Martin'
import sys
from bdd import *
def run(application):
input = raw_input("SGBD>>")
if input == 'exit':
print("Good Bye")
return False
elif input == "help":
showHelp()
return True
else:
execute(application,input.split())
return True
def showHelp():
print(10*"#"+"List of commands"+10*"#"+"\n")
print(3*" - "+"showTables : show the name of all the tables in the database")
print(3*" - "+"showDep (nameTable)*: show all the functional dependencies (for nameTable)*")
print(3*" - "+"addDep nameTable : add a functional dependence to nameTable")
print(3*" - "+"delDep nameTable : delete a functional dependence to nameTable")
print(3*" - "+"showAtt nameTable : show the name of all the attributes of nameTable")
print(3*" - "+"showLogCons nameTable : show all the logical dependencies")
print(3*" - "+"findSuperKey nameTable : find all the super keys of nameTable")
print(3*" - "+"findKey nameTable : find the key of nameTable")
print(3*" - "+"isBcnf nameTable : say if nameTable is in BCNF")
print(3*" - "+"respect nameTable : say if all the functional dependence are respected")
print(3*" - "+"is3nf nameTable : say if nameTable is in 3NF\n")
def execute(application,command):
if 'showTables' in command:
tableList = application.get_tables()
for table in tableList:
print (table)
elif 'showDep' in command:
depList = application.funcDep()
if len(depList) <= 0:
print("No dependencies")
else:
for dep in depList:
if len(command) > 1:
if command[1] == dep[0]:
print (dep[0]+" "+dep[1]+" -> "+dep[2])
else:
print (dep[0]+" | "+dep[1]+" -> "+dep[2])
elif 'addDep' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
print("Dependence is like X -> A")
x = raw_input("Enter X : ")
a = raw_input("Enter A : ")
application.add_dep((command[1],x,a,))
elif 'delDep' in command:
if (len(command) <= 1):
print("Parameter is missing")
else:
print("Dependence is like X ->A")
x = raw_input("Enter X : ")
a = raw_input("Enter A : ")
application.delete_dep(command[1],x,a)
elif 'showAtt' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
attList = application.get_attributes(command[1])
for att in attList:
print (att),
print("\n")
elif 'showLogCons' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else:
number = 1
while number > 0:
depList = application.get_logical_consequence(command[1])
if len(depList) <= 0:
print("No logical consequence ")
break
else:
i=1
for dep in depList:
print (str(i)+" : "+dep[0]+" "+dep[1]+" -> "+dep[2])
i+=1
i=1
number = raw_input("If you want delete a dependence enter the correct number else enter 0")
if number == "0":
break
else:
for dep in depList:
if str(i) == number:
application.delete_dep(dep)
print("Consequence delete")
i+=1
elif 'findSuperKey' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
superKeyList = application.find_super_key(command[1])
for superKey in superKeyList:
for att in superKey:
print(att),
print("\n")
elif 'findKey' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
keyList = application.find_key(command[1])
for key in keyList:
for att in key:
print(att),
print("\n")
elif 'isBcnf' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
print(application.is_BCNF(command[1]))
elif 'is3nf' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
if(not application.is_3NF(command[1])):
respect = application.respect(command[1])
if len(respect) == 0:
print(application.is_3NF(command[1]))
input = raw_input("Do you want to make decomposition in 3NF (y/n) ")
if "y" in input or "Y" in input:
application.decompose(command[1])
print("Decomposition finished")
else:
print("The functional dependencies are not respected")
else:
print(application.is_3NF(command[1]))
elif 'respect' in command:
if(len(command)) <= 1:
print("Parameter is missing")
else :
respect = application.respect(command[1])
if len(respect) == 0:
print("All the dependencies are respected")
else:
print("Som dependence are not respected")
i=1
for triplet in respect:
print (str(i)+" : "+triplet[0]+" "+triplet[1]+" -> "+triplet[2])
i+=1
number = raw_input("Do you want delete a functional dependence ? (Enter the a number or 0 to continue")
while int(number) != 0:
application.delete_dep(respect[int(number)-1])
if len(respect) - 1 <= 0:
break
else:
print("Command not found")
print("Type \'Help\' to know how use SGBD")
input = raw_input("Enter the name of the database that you want use : ")
application = Bdd(input)
while run(application):
continue