import java.sql.*;
import java.io.*;
import uk.ac.ic.doc.automed.*;
import uk.ac.ic.doc.automed.reps.*;
import uk.ac.ic.doc.automed.ssd.*;
import java.util.*;
import uk.ac.ic.doc.automed.wrappers.*;
import uk.ac.bbk.dcs.automed.qproc.*;
import uk.ac.bbk.dcs.automed.wrappers.*;
import uk.ac.ic.doc.automed.NotFoundException;

public class TestQuerySygIntegration 
{
    public static void main(String[] args)
    {
	try{
	
	    Schema src=Schema.getSchema("sc_s1zzg");

            src.listSchema(System.out,Schema.LIST_SCHEMA_NORMAL,true);
	    
	    Schema [] tgts = 
		new Schema[]{Schema.getSchema("sc_s1"), Schema.getSchema("sc_s2")};
	    QueryReformulator qr=new QueryReformulator(src,tgts);
	    FragmentProcessor fp=new FragmentProcessor();
	    FunctionTable ft=new SSDFunctionTable();
	    Evaluator e=new Evaluator(ft);

	    String [][] query=new String[][]{
    		{"Querying students' tutors", "distinct [{x,y} | {x,y} <- <<student,tutor>>]"},	
		{"Querying result table", "distinct [{x,y} | {x,y} <- <<result>>]"},
		{"Querying students' names", "distinct [{x,y} | {x,y} <- <<student,name>>]"},
		{"Querying students' grades", "distinct [{x,y,z} | {x,y,z} <- <<result,grade>>]"}

	    };
		
	    for(int i=0; i<query.length; i++)
	    {
		ASG q=new ASG(query[i][1]);

		System.out.println();
		System.out.println("***************************************************");
		System.out.println("\t" + query[i][0]);
		System.out.println("***************************************************");
		
		qr.reformulate(q);
		System.out.println("Query after query reformulator: ");
		System.out.println(q);
		System.out.println();
	    
		fp.process(q);
		System.out.println("Query after FragmentProcessor: ");
		System.out.println(q);
		System.out.println();

		e.evaluate(q);
		System.out.println("Query after evaluator: ");
		System.out.println(q);
		System.out.println();
  	    }

	}
	catch(NotFoundException e){
	    e.printStackTrace();
	}
	catch(Exception e){
	    e.printStackTrace();
	}
    }
}








