Пример #1
0
    def test_keys(self):
        attrs = norm.parseAttrs('A,B,C,D,E,F,G')
        fds = norm.parseFds('A,C->D;A,C->E;B,F->E;A,F,G->B;B,D->C')
        R = norm.relation(attrs, fds)

        (minKeys, supKeys) = R.getKeys()

        print(R)
        print("minKeys: {}".format(";".join(
            ["(" + ",".join(sorted(list(s))) + ")" for s in minKeys])))
        print("supKeys: {}".format(";".join(
            ["(" + ",".join(sorted(list(s))) + ")" for s in supKeys])))
        print("")
        attrs = norm.parseAttrs('A,B,C')
        fds = norm.parseFds('A,B->C')
        R = norm.relation(attrs, fds)

        (minKeys, supKeys) = R.getKeys()
        (minKeys, supKeys) = R.getKeys()
        (minKeys, supKeys) = (sorted(list(minKeys)), sorted(list(supKeys)))
        print(R)
        print("minKeys: {}".format(";".join(
            ["(" + ",".join(sorted(list(s))) + ")" for s in minKeys])))
        print("supKeys: {}".format(";".join(
            ["(" + ",".join(sorted(list(s))) + ")" for s in supKeys])))
Пример #2
0
    def test_multi1(self):
        print("test_multi1")
        attrs = norm.parseAttrs('A,B,C')
        fds = norm.parseFds('A->B;B->C')
        R = norm.relation(attrs, fds)

        (minKeys, supKeys) = R.getKeys()
        print(R)
        print("minKeys: {}".format(";".join(
            ["(" + ",".join(sorted(list(s))) + ")" for s in minKeys])))
        print("supKeys: {}".format(";".join(
            ["(" + ",".join(sorted(list(s))) + ")" for s in supKeys])))
        print("")

        R1 = R.getProjection(norm.parseAttrs('A,B'))
        R2 = R.getProjection(norm.parseAttrs('A,C'))

        print(R1)
        print("")
        print(R2)
        print("")

        isDependencyPreserving = norm.checkFdEq(R.fds, R1.fds + R2.fds)
        print("Is Dependency Preserving"
              if isDependencyPreserving else "Is NOT Dependency Preserving")
Пример #3
0
    def test_proj(self):
        attrs = norm.parseAttrs('A,B,C,D,E,F,G')
        fds = norm.parseFds('A,C->D;A,C->E;B,F->E;A,F,G->B;B,D->C')
        R = norm.relation(attrs, fds)
        subAttrs = norm.parseAttrs('A,C,D,E')

        print(R)
        print("")
        print(R.getProjection(subAttrs))
Пример #4
0
 def test_closure(self):
     attrs = norm.parseAttrs('A,B,C,D,E,F,G')
     fds = norm.parseFds('A,C->D;A,C->E;B,F->E;A,F,G->B;B,D->C')
     R = norm.relation(attrs, fds)
     tests = [('A', R, 'A'), ('A,B', R, 'A,B'), ('A,C', R, 'A,C,D,E'),
              ('B,D', R, 'B,C,D'), ('A,B,C', R, 'A,B,C,D,E'),
              ('A,C,F,G', R, 'A,B,C,D,E,F,G')]
     for t in tests:
         self.assertEqual((norm.closure(norm.parseAttrs(t[0]), fds)),
                          norm.parseAttrs(t[2]), "closure wrong ans")
Пример #5
0
        print(R1)
        print("")
        print(R2)
        print("")

        isDependencyPreserving = norm.checkFdEq(R.fds, R1.fds + R2.fds)
        print("Is Dependency Preserving"
              if isDependencyPreserving else "Is NOT Dependency Preserving")


if __name__ == "__main__":
    # unittest.main()

    attrs = norm.parseAttrs("A,B,C,D,E,F,G")
    fds = norm.parseFds("A,C->B,F;B,E->F,G;B,G->E;A,G->B,E;E,F->D")
    R = norm.relation(attrs, fds)

    l = [
        R.getProjection(norm.parseAttrs(i))
        for i in ["A,F,G", "A,B,C,F", "B,D,E,F", "A,B,E,G"]
    ]
    norm.isLosslessChaseTest(l, fds, verbose=True)

    exit()

    attrs = norm.parseAttrs("A,B,C,D,E,F,G")
    fds = norm.parseFds("A,C->D;A,C->E;B,F->E;A,F,G->B;B,D->C")
    R = norm.relation(attrs, fds)

    (minKeys, supKeys) = R.getKeys()
    print(R)