コード例 #1
0
ファイル: test_line.py プロジェクト: ytann/sympy
def test_arguments():
    """Functions accepting `Point` objects in `geometry`
    should also accept tuples, lists, and generators and
    automatically convert them to points."""
    from sympy import subsets

    singles2d = ((1, 2), [1, 3], Point(1, 5))
    doubles2d = subsets(singles2d, 2)
    l2d = Line(Point2D(1, 2), Point2D(2, 3))
    singles3d = ((1, 2, 3), [1, 2, 4], Point(1, 2, 6))
    doubles3d = subsets(singles3d, 2)
    l3d = Line(Point3D(1, 2, 3), Point3D(1, 1, 2))
    singles4d = ((1, 2, 3, 4), [1, 2, 3, 5], Point(1, 2, 3, 7))
    doubles4d = subsets(singles4d, 2)
    l4d = Line(Point(1, 2, 3, 4), Point(2, 2, 2, 2))
    # test 2D
    test_single = ['contains', 'distance', 'equals', 'parallel_line', 'perpendicular_line', 'perpendicular_segment',
                   'projection', 'intersection']
    for p in doubles2d:
        Line2D(*p)
    for func in test_single:
        for p in singles2d:
            getattr(l2d, func)(p)
    # test 3D
    for p in doubles3d:
        Line3D(*p)
    for func in test_single:
        for p in singles3d:
            getattr(l3d, func)(p)
    # test 4D
    for p in doubles4d:
        Line(*p)
    for func in test_single:
        for p in singles4d:
            getattr(l4d, func)(p)
コード例 #2
0
    def graph_generation(self, Si, i):
        i_here = i + 1
        i_str = str(i)
        ipp_str = str(i + 1)
        #if i < len(self.Q):
        #print("Generating graphs for " + ipp_str + " quasi-identifiers", end="")
        # to create Si we need all column names of Ci
        # PRAGMA returns infos like (0, 'ID', 'INTEGER', 0, None, 1), (1, 'dim1', 'TEXT', 0, None, 0), ...
        self.cursor.execute("PRAGMA table_info(C" + i_str + ")")
        column_infos = list()
        column_infos_from_db = list(self.cursor)
        for column in column_infos_from_db:
            if column[1] == "ID":
                column_infos.append("ID INTEGER PRIMARY KEY")
            else:
                column_infos.append(str(column[1]) + " " + str(column[2]))
        self.cursor.execute("CREATE TABLE IF NOT EXISTS S" + i_str + " (" +
                            ', '.join(column_infos) + ")")
        question_marks = ""
        for j in range(0, len(column_infos_from_db) - 1):
            question_marks += " ?,"
        question_marks += " ? "

        self.cursor.executemany(
            "INSERT INTO S" + i_str + " values (" + question_marks + ")", Si)

        self.cursor.execute("SELECT * FROM S" + i_str)
        Si_new = set(self.cursor)

        # in the last iteration the phases are useless because after self.graph_generation only Si (Sn) is taken into account
        if i == len(self.Q):
            return
        i_here_str = str(i_here)
        self.cursor.execute("CREATE TABLE IF NOT EXISTS C" + ipp_str + " (" +
                            ', '.join(column_infos) + ")")
        self.cursor.execute("ALTER TABLE C" + ipp_str + " ADD COLUMN dim" +
                            i_here_str + " TEXT")
        self.cursor.execute("ALTER TABLE C" + ipp_str + " ADD COLUMN index" +
                            i_here_str + " INT")

        self.cursor.execute("UPDATE C" + ipp_str + " SET dim" + i_here_str +
                            " = 'null', index" + i_here_str +
                            "= 'null' WHERE index" + i_here_str + " is null")
        select_str = ""
        select_str_except = ""
        where_str = ""
        for j in range(2, i_here):
            j_str = str(j)
            if j == i_here - 1:
                select_str += ", p.dim" + j_str + ", p.index" + j_str + ", q.dim" + j_str + ", q.index" + j_str
                select_str_except += ", q.dim" + j_str + ", q.index" + j_str + ", p.dim" + j_str + ", p.index" + j_str
                where_str += " and p.dim" + j_str + "<q.dim" + j_str
            else:
                select_str += ", p.dim" + j_str + ", p.index" + j_str
                select_str_except += ", q.dim" + j_str + ", q.index" + j_str
                where_str += " and p.dim" + j_str + "=q.dim" + j_str + " and p.index" + j_str + "=q.index" + j_str

        # join phase
        if i > 1:
            self.cursor.execute(
                "INSERT INTO C" + ipp_str +
                " SELECT null, p.dim1, p.index1, p.ID, q.ID" + select_str +
                " FROM S" + i_str + " p, S" + i_str +
                " q WHERE p.dim1 = q.dim1 and p.index1 = q.index1 " +
                where_str)

        else:
            self.cursor.execute(
                "INSERT INTO C" + ipp_str +
                " SELECT null, p.dim1, p.index1, p.ID, q.ID, q.dim1, q.index1"
                " FROM S" + i_str + " p, S" + i_str + " q WHERE p.dim1<q.dim1")

        self.cursor.execute("SELECT * FROM C" + ipp_str)
        Ci_new = set(self.cursor)

        # prune phase
        # all subsets of Si == dims_and_indexes of all nodes in Si
        # for all nodes in Ci+1 we will remove the nodes that contain a subset of dims_and_indexes
        # which is not in all_subsets_of_Si
        all_subsets_of_Si = set()
        for node in Si_new:
            all_subsets_of_Si.add(
                tuple(self.get_dims_and_indexes_of_node(node)))
        for c in Ci_new:
            for s in subsets(self.get_dims_and_indexes_of_node(c), i):
                if s not in all_subsets_of_Si:
                    node_id = str(c[0])
                    self.cursor.execute("DELETE FROM C" + ipp_str +
                                        " WHERE C" + ipp_str + ".ID = " +
                                        node_id)

        # edge generation
        self.cursor.execute("CREATE TABLE IF NOT EXISTS E" + ipp_str +
                            " (start INT, end INT)")
        self.cursor.execute("INSERT INTO E" + ipp_str + " "
                            "WITH CandidatesEdges(start, end) AS ("
                            "SELECT p.ID, q.ID "
                            "FROM C" + ipp_str + " p,C" + ipp_str + " q,E" +
                            i_str + " e,E" + i_str + " f "
                            "WHERE (e.start = p.parent1 AND e.end = q.parent1 "
                            "AND f.start = p.parent2 AND f.end = q.parent2) "
                            "OR (e.start = p.parent1 AND e.end = q.parent1 "
                            "AND p.parent2 = q.parent2) "
                            "OR (e.start = p.parent2 AND e.end = q.parent2 "
                            "AND p.parent1 = q.parent1) "
                            ") "
                            "SELECT D.start, D.end "
                            "FROM CandidatesEdges D "
                            "EXCEPT "
                            "SELECT D1.start, D2.end "
                            "FROM CandidatesEdges D1, CandidatesEdges D2 "
                            "WHERE D1.end = D2.start")