CSc 8710 Fall 2005
Homework 4 (Due: November 7, 2005 - Monday)

JDBC Connect String on tinman:

 try {
    conn = DriverManager.getConnection (
         "jdbc:oracle:thin:@tinman.cs.gsu.edu:1521:sid9ir2",
         "userid","password");
  } catch (SQLException e1) {
      out.println("Error connecting to Oracle:"+e1.getMessage());
        return;
    }

  1. Write a Java program that implements the "Naive" algorithm to compute the "sibling", "cousin", and "related" tables of the following deductive database:
    sibling(X,Y) :- parent(X,Z), parent(Y,Z), X <> Y.
    cousin(X,Y) :- parent(X,Xp), parent(Y,Yp), sibling(Xp,Yp).
    cousin(X,Y) :- parent(X,Xp), parent(Y,Yp), cousin(Xp,Yp).
    related (X,Y) :- sibling(X,Y).
    related(X,Y) :- related(X,Z), parent(Y,Z).
    related(X,Y) :- related(Z,Y), parent(X,Z).
    
    Keep track of the total number of SQL "insert" statements that are submitted to the server for each IDB predicate. Print the number of inserts for each predicate.
  2. Write a Java program that implements the "Semi-Naive" algorithm to compute the "sibling", "cousin", and "related" tables of the same database. Keep track of the total number of SQL "insert" statements that are submitted to the server for each IDB predicate.
  3. Write a Java program that implements the "Semi-Naive" algorithm to compute the "sibling" and "cousin" tables using the magic sets transformed IDB for the query:
      query(X) :- cousin("tom",X).
    
    The magic sets transformed IDB is:
    magic_cousin_bf("tom").
    magic_cousin_bf(Xp) :- parent(X,Xp), magic_cousin_bf(X).
    magic_sibling_bf(Xp) :- parent(X,Xp), magic_cousin_bf(X).
    
    query(X) :- cousin_bf(h,X).
    cousin_bf(X,Y) :- parent(X,Xp), parent(Y,Yp), sibling_bf(Xp,Yp),
                      magic_cousin_bf(X).
    cousin_bf(X,Y) :- parent(X,Xp), parent(Y,Yp), cousin_bf(Xp,Yp),
                      magic_cousin_bf(X).
    sibling_bf(X,Y) :- parent(X,Z), parent(Y,Z), X <> Y,
                       magic_sibling_bf(X).
    
    Keep track of the total number of SQL "insert" statements that are submitted to the server for each IDB predicate.
  4. You may assume that the tables for sibling, cousin, and related are available in the database before you run your Java program.
  5. I will give you two different EDBs to test your program.
    EDB 1
    EDB 2
    EDB 3