<commit_before>package gr.uoi.cs.daintiness.hecate.parser;

import gr.uoi.cs.daintiness.hecate.sql.Attribute;
import gr.uoi.cs.daintiness.hecate.sql.Schema;
import gr.uoi.cs.daintiness.hecate.sql.Table;

import java.io.IOException;

import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

/**
 * This class uses the parser of the generated ANTLR grammar to parse
 * the file given to the constructor.
 * @author giskou
 */
public class HecateParser {
	static Schema s;
	
	/**
	 * 
	 * @param filePath The path of the file to be parsed.
	 * @throws IOException
	 * @throws RecognitionException
	 */
	public static Schema parse(String filePath) {
		CharStream      charStream = null;
		
		try {
			charStream = new ANTLRFileStream(filePath);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		DDLLexer        lexer = new DDLLexer(charStream) ;
		TokenStream     tokenStream = new CommonTokenStream(lexer);
		DDLParser       parser = new DDLParser(tokenStream) ;
		ParseTree       root = parser.start();
		SchemaLoader    loader = new SchemaLoader();
		ParseTreeWalker walker = new ParseTreeWalker();
		walker.walk(loader, root);
		
		return s;
	}
	
	private static class SchemaLoader extends DDLBaseListener {
		
		private Table t;
		private Attribute a;
		boolean foundTableConst = false;
		
		public void enterStart (DDLParser.StartContext ctx) {
			System.out.println("Starting");
			s = new Schema();
		}
		public void exitStart (DDLParser.StartContext ctx) {
			System.out.println("\n\n\n" + s.print());
		}
		
		public void enterTable (DDLParser.TableContext ctx) {
			String tableName = ctx.table_name().getText();
			t = new Table(tableName);
			System.out.println("TABLE : " + tableName);
		}
		public void exitTable (DDLParser.TableContext ctx) {
			s.addTable(t);
			System.out.println();
		}
		
		public void enterColumn (DDLParser.ColumnContext ctx) {
			String colName = ctx.col_name().getText();
			String colType = ctx.data_type().getText();
			colType = colType.toUpperCase();
			a = new Attribute(colName, colType);
		}
		
		public void exitColumn (DDLParser.ColumnContext ctx) {
			System.out.print(a.getName() + " ");
			t.addAttribute(a);
		}
		
		public void enterLine_constraint(DDLParser.Line_constraintContext ctx) {
			if (ctx.getText().contains("PRIMARY")) {
				t.addAttrToPrimeKey(a);
			}
		}
		public void exitLine_constraint(DDLParser.Line_constraintContext ctx) {
			System.out.print( "PRIMARY ");
		}
		
		public void enterTable_constraint(DDLParser.Table_constraintContext ctx) {
			foundTableConst = true;
		}
		public void exitTable_constraint(DDLParser.Table_constraintContext ctx) {
			foundTableConst = false;
		}
		
		public void enterPrimary (DDLParser.PrimaryContext ctx) {
			if (foundTableConst) {
				String todo = ctx.parNameList().getText();
				todo = todo.substring(1, todo.length()-1);
				String[] names = todo.split(",");
				for (String s : names) {
					if (t.getAttrs().get(s) != null){
						t.addAttrToPrimeKey(t.getAttrs().get(s));
					}
				}
			}
		}
	}
}<commit_msg>remove quotes from names and add title to schema<commit_after>package gr.uoi.cs.daintiness.hecate.parser;

import gr.uoi.cs.daintiness.hecate.sql.Attribute;
import gr.uoi.cs.daintiness.hecate.sql.Schema;
import gr.uoi.cs.daintiness.hecate.sql.Table;

import java.io.File;
import java.io.IOException;

import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

/**
 * This class uses the parser of the generated ANTLR grammar to parse
 * the file given to the constructor.
 * @author giskou
 */
public class HecateParser {
	static Schema s;
	
	/**
	 * 
	 * @param filePath The path of the file to be parsed.
	 * @throws IOException
	 * @throws RecognitionException
	 */
	public static Schema parse(String filePath) {
		CharStream      charStream = null;
		
		try {
			charStream = new ANTLRFileStream(filePath);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		DDLLexer        lexer = new DDLLexer(charStream) ;
		TokenStream     tokenStream = new CommonTokenStream(lexer);
		DDLParser       parser = new DDLParser(tokenStream) ;
		ParseTree       root = parser.start();
		SchemaLoader    loader = new SchemaLoader();
		ParseTreeWalker walker = new ParseTreeWalker();
		walker.walk(loader, root);
		String[] path = filePath.split(File.separator);
		s.setTitle(path[path.length-1]);
		return s;
	}
	
	private static class SchemaLoader extends DDLBaseListener {
		
		private Table t;
		private Attribute a;
		boolean foundTableConst = false;
		
		public void enterStart (DDLParser.StartContext ctx) {
			System.out.println("Starting");
			s = new Schema();
		}
		public void exitStart (DDLParser.StartContext ctx) {
			System.out.println("\n\n\n" + s.print());
		}
		
		public void enterTable (DDLParser.TableContext ctx) {
			String tableName = removeQuotes(ctx.table_name().getText());
			t = new Table(tableName);
			System.out.println("TABLE : " + tableName);
		}
		public void exitTable (DDLParser.TableContext ctx) {
			s.addTable(t);
			System.out.println();
		}
		
		public void enterColumn (DDLParser.ColumnContext ctx) {
			String colName = removeQuotes(ctx.col_name().getText());
			String colType = ctx.data_type().getText();
			colType = colType.toUpperCase();
			a = new Attribute(colName, colType);
		}
		
		public void exitColumn (DDLParser.ColumnContext ctx) {
			System.out.print(a.getName() + " ");
			t.addAttribute(a);
		}
		
		public void enterLine_constraint(DDLParser.Line_constraintContext ctx) {
			if (ctx.getText().contains("PRIMARY")) {
				t.addAttrToPrimeKey(a);
			}
		}
		public void exitLine_constraint(DDLParser.Line_constraintContext ctx) {
			System.out.print( "PRIMARY ");
		}
		
		public void enterTable_constraint(DDLParser.Table_constraintContext ctx) {
			foundTableConst = true;
		}
		public void exitTable_constraint(DDLParser.Table_constraintContext ctx) {
			foundTableConst = false;
		}
		
		public void enterPrimary (DDLParser.PrimaryContext ctx) {
			if (foundTableConst) {
				String todo = ctx.parNameList().getText();
				todo = todo.substring(1, todo.length()-1);
				String[] names = todo.split(",");
				for (String s : names) {
					if (t.getAttrs().get(s) != null){
						t.addAttrToPrimeKey(t.getAttrs().get(s));
					}
				}
			}
		}
		
		private boolean hasQuotes(String s) {
			switch (s.charAt(0)) {
				case '\'':
				case '\"':
				case '`':
					return true;
				default:
					return false;
			}
		}
		
		private String removeQuotes(String s) {
			if (hasQuotes(s)) {
				String res = null;
				res = s.substring(1, s.length()-1);
				return res;
			}
			return s;
		}
	}
}
{'fraction_non_alphanumeric': 0.1201794979666246, 'fraction_numerical': 0.003085121301360258, 'mean_word_length': 3.595360824742268, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625584', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2312, 'n_words': 510}