package caise05;

import java.sql.*;
import java.io.*;
import java.util.HashMap;
import java.util.ArrayList;
import uk.ac.ic.doc.automed.ssd.*;
import uk.ac.ic.doc.automed.*;

/**
 * An application to demonstrate how to create patterns for 
 * semistructured data
 */

public class DefinePatterns {

    public static void createPatterns()
	throws SQLException, IOException
    {
	//Create patterns for ug
	Pattern.retract("xmlname");
	Pattern xmlname=Pattern.createPattern("xmlname", "\\\\s+<name>(\\\\w+)</name>");
	Pattern.retract("xmltutor");
	Pattern xmltutor=Pattern.createPattern("xmltutor", "\\\\s+<tutor>(\\\\w+)</tutor>");
	Pattern.retract("xmlcode");
	Pattern xmlcode=Pattern.createPattern("xmlcode", "\\\\s+<course\\\\scode=\\\"(\\\\w+)\\\">");
	Pattern.retract("xmldept");
	Pattern xmldept=Pattern.createPattern("xmldept", "\\\\s+<dept>(\\\\w+)</dept>");
	Pattern.retract("xmllecturer");
	Pattern xmllecturer=Pattern.createPattern("xmllecturer", "\\\\s+<lecturer>(\\\\w+)</lecturer>");
	Pattern.retract("xmlyear");
	Pattern xmlyear=Pattern.createPattern("xmlyear", "\\\\s+<year>(\\\\d)</year>");
	Pattern.retract("xmlgrade");
	Pattern xmlgrade=Pattern.createPattern("xmlgrade", "\\\\s+<grade>([A-F])</grade>");
	//Create patterns for student
	Pattern.retract("csb");
	Pattern csb=Pattern.createPattern("csb", "\\\\[(\\\\w+),(\\\\w+),(\\\\w+)\\\\]");
	Pattern.retract("student");
	Pattern student=Pattern.createPattern("student", "\\\\s+student=(.*)");
	Pattern.retract("level");
	Pattern level=Pattern.createPattern("level", "\\\\s+level=(.*)");
	Pattern.retract("year");
	Pattern year=Pattern.createPattern("year", "\\\\s+year=(\\\\d)");
	Pattern.retract("grade");
	Pattern grade=Pattern.createPattern("grade", "\\\\s+grade=([A-F])?");
    }
 
    public static void main(String[] args) 
    {
	try 
	{
	    System.out.println("Creating Patterns ...");
	    createPatterns();
	}
	catch (SQLException se) { 
	    se.printStackTrace();
	}
	catch (IOException ie) {
	    ie.printStackTrace();
	}
    }

}













