1. Implement " Algorithm 15.3: Testing for Lossless Join Property" Input : A universal relation R, a decomposition D = {R1, R2, ..., Rm} of R, and a set F of functional dependencies. Output: Yes or No...

1 answer below »

1. Implement "Algorithm 15.3: Testing for Lossless Join Property"



Input: A universal relation R, a decomposition D = {R1, R2, ..., Rm} of R, and a set F of functional dependencies.


Output: Yes or No



2. Implement : "
Algorithm 15.5: Relational Decomposition into BCNF with Lossless (non-additive) join property"



Input: A universal relation R and a set of functional dependencies F on the attributes of R.



Output: Relations in BCNF

Answered Same DayFeb 18, 2021

Answer To: 1. Implement " Algorithm 15.3: Testing for Lossless Join Property" Input : A universal relation R, a...

Sandeep Kumar answered on Feb 18 2021
147 Votes
import re
def containsAll(str, set):
return 0 not in [c in str for c in set]
def bcnf(relation, dep, newRelations):
# GET RID OF
UNWANTED CHARACTERS IN INPUTTED RELATION
relationStripped = relation
for c in [',', '(', ')', ' ']:
relationStripped = relationStripped.replace(c, '')
relationStripped = sorted(relationStripped)
relationStripped = ''.join(relationStripped)
print(f"\nRELATION PASSED INTO FUNCTION IS {relationStripped}\n")
# NEEDED VARIABLES TO MAKE SURE ONLY FINAL DECOMPOSITIONS ARE APPENDED
splitHappened = False
potentialAdditions = []
# CHECK IF CLOSURE OF RHS IS SUPERKEY
for lhs in dep.keys():
counter = 0
closure = lhs
while counter < len(dep):
for compLHS in dep.keys():
if compLHS in closure and dep[compLHS] not in closure:
closure += dep[compLHS]
counter += 1
closure = sorted(closure)
closure = ''.join(closure)
if closure != relationStripped:
splitHappened = True
# SPLITTING IF CLOSURE IS NOT SUPERKEY
splitLeft = closure
splitRight = lhs
for i in relationStripped:
if i not in closure and i not in lhs:
splitRight += i
splitLeft = ''.join(sorted(splitLeft))
splitRight =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here