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 TestSSDExamples 
{

    public static void main(String[] args)
    {
	try{
	
	    Schema src=Schema.getSchema("y1l");
            src.listSchema(System.out,Schema.LIST_SCHEMA_NORMAL,true);
	    
	    Schema [] tgts = 
		new Schema[]{Schema.getSchema("y1"), Schema.getSchema("y2")};

	    QueryReformulator qr=new QueryReformulator(src,tgts);
	    FragmentProcessor fp=new FragmentProcessor();
	    FunctionTable ft=new SSDFunctionTable();
	    //FunctionTable ft=new StandardFunctionTable();
	    Evaluator e=new Evaluator(ft);

	    String [][] query=new String[][]{
		{"Querying course names", "distinct [{x} | {x,y} <- <<code,root,<<course,root>>>>]"},
		{"Querying students'name", "distinct [{x} | {x,y} <- <<name,root,<<course,root>>,<<student,root,<<course,root>>>>>>]"},
		{"Querying complex nodes (student and course)", "[{x,y} | {x,y} <- <<student,root,<<course,root>>>>]"},
		{"Querying courses that Mary took", "distinct [{a,b} | {a,z1} <- <<code,root,<<course,root>>>>; {w1,z2} <- <<student,root,<<course,root>>>>; {b,w2} <- <<name,root,<<course,root>>,<<student,root,<<course,root>>>>>>; (=) w1 w2; (=) z1 z2; (=) b 'Mary']" }};
		
	    //Querying code
	    //ASG q=new ASG("distinct [{x} | {x,y} <- <<code,root,<<course,root>>>>]");
	    //Querying students' name
	    //ASG q=new ASG("distinct [{x} | {x,y} <- <<name,root,<<course,root>>,<<student,root,<<course,root>>>>>>]");
	    
	    //Querying student and course values 
	    //ASG q=new ASG("[{x,y} | {x,y} <- <<student,root,<<course,root>>>>]");
	    
	    //Querying name='Mary' 
	    //ASG q=new ASG("[{n,s} | {n,s} <- <<name,root,<<course,root>>,<<student,root,<<course,root>>>>>>]");


	    //Querying courses that Mary took
//  	    ASG q=new ASG("distinct[{a,b} | {a,z1} <- <<code,root,<<course,root>>>>; {w1,z2} <- <<student,root,<<course,root>>>>; {b,w2} <- <<name,root,<<course,root>>,<<student,root,<<course,root>>>>>>; (=) w1 w2; (=) z1 z2; (=) b 'Mary']");

	    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();
	}
    }
}








