Exemple #1
0
def isThirdNF(relation):
    primes = set(attr for key in relation.candidateKeys() for attr in key)

    if (not isSecondNF(relation)):
        return False

    return every(
        relation.fdSet, lambda fdItem: set(fdItem[1]).issubset(fdItem[0]) or
        relation.validKey(fdItem[0]) or set(fdItem[1]).issubset(primes))
Exemple #2
0
    def candidateKeys(self):
        keys = []
        for i in range(1, len(self.__attributes__) + 1):
            # Generate possible combinations and filter out the super sets of existing candidate Keys
            possibilities = [
                item for item in combinations(self.__attributes__, i)
                if not len(keys)
                or every(keys, lambda key: not set(key).issubset(item))
            ]
            # add to candidate Keys if it is a valid Key in relation
            keys += [item for item in possibilities if self.validKey(item)]

        return keys
Exemple #3
0
    def candidateKeys(self):
        #generating all possible combinations of attributes
        keys = []
        for i in range(1, len(self.__attributes__) + 1):

            possibilities = [
                item for item in combinations(self.__attributes__, i)
                if not len(keys)
                or every(keys, lambda key: not set(key).issubset(item))
            ]

            keys += [item for item in possibilities if self.validKey(item)]

        return keys
Exemple #4
0
def cover(fd1, fd2):
    return every(
        lambda item: fd1.closureSet(item).issubset(fd2.closureSet(item)),
        fd1.leftSideSet())
Exemple #5
0
def isBCNF(relation):
    if (not isThirdNF(relation)):
        return False

    return every(relation.fdSet.leftSideSet(),
                 lambda lhs: relation.validKey(lhs))