<commit_before>package Autocomplete;

import java.sql.*;
import java.util.*;


class Database extends Main{  
	public static void main(String args[]){  
		try{  
			Connection con=DriverManager.getConnection("jdbc:mysql://box1275.bluehost.com:3306/jlindber_autocomplete","jlindber_public","Gnx-H7G-BBf-gdk");  
			constructWordTree(con);
			Statement stmt=con.createStatement();  
			//Boolean r=stmt.execute("INSERT INTO `jlindber_autocomplete`.`charTree` (`address`, `content`, `priority`, `isWord`, `children`) VALUES (NULL, 't', '0', '1', NULL);"); 
			ResultSet rs=stmt.executeQuery("SELECT * FROM `wordTree`");  
			ResultSetMetaData rsmd = rs.getMetaData();
			System.out.println(rsmd);
			while(rs.next()){  
				for (int i = 1; i<5; i++){
				System.out.print(rsmd.getColumnTypeName(i) +": "+rs.getObject(i) + "     ");  
				}
				System.out.println(" ");
			}
			con.close();  
		}catch(Exception e){ 
			System.out.println(e);
		}  
	}  

	public static void constructCharTree(Connection con){
		try{  
			Statement stmt=con.createStatement();  
			ResultSet rs=stmt.executeQuery("SELECT * FROM `charTree`"); 
			HashMap<Node,int[]> nodeChildren =new HashMap<Node,int[]>(); 
			ArrayList<Node> nodes = new ArrayList<Node>();
			while(rs.next()){
				Node n = new Node(rs.getInt("id"), rs.getString("content"),rs.getInt("priority"), rs.getBoolean("isWord"));
				nodes.add(n);
				String childString = rs.getString("children");
				if (childString!=null){
					String[] childrenStringArray = childString.split(",");
					int[] childrenIntArray = new int[childrenStringArray.length];
					for(int i = 0; i<childrenStringArray.length; i++) {
						childrenIntArray[i] = Integer.parseInt(childrenStringArray[i]);
					}
					nodeChildren.put(n, childrenIntArray);
				}else{
					nodeChildren.put(n, null);
					}
			} 
			
			for(int i = 0; i<nodes.size(); i++) {
				int[] c = nodeChildren.get(nodes.get(i));
				if (c != null){
					for(int child = 0; child<=c.length; child++) {
						nodes.get(i).children.addAll(searchForNodeWithId(child, nodes));
						//System.out.println(child);
					}
				}
			}
			
			Main.charTree.origin = searchForNodeWithId(1, nodes).get(0);
			//System.out.println(Arrays.toString(nodeChildren.get(nodes.get(2))));
			//System.out.println(nodes);

		}catch(Exception e){ 
			System.out.println(e);
		}  
		
	
	}
	
	
	public static void constructWordTree(Connection con){
		try{  
			Statement stmt=con.createStatement();  
			ResultSet rs=stmt.executeQuery("SELECT * FROM `wordTree`"); 
			HashMap<Node,int[]> nodeChildren =new HashMap<Node,int[]>(); 
			ArrayList<Node> nodes = new ArrayList<Node>();
			while(rs.next()){
				Node n = new Node(rs.getInt("id"), rs.getString("content"),rs.getInt("priority"),false);
				nodes.add(n);
				String childString = rs.getString("children");
				if (childString!=null){
					String[] childrenStringArray = childString.split(",");
					int[] childrenIntArray = new int[childrenStringArray.length];
					for(int i = 0; i<childrenStringArray.length; i++) {
						childrenIntArray[i] = Integer.parseInt(childrenStringArray[i]);
					}
					nodeChildren.put(n, childrenIntArray);
				}else{
					nodeChildren.put(n, null);
					}
			} 
			
			for(int i = 0; i<nodes.size(); i++) {
				int[] c = nodeChildren.get(nodes.get(i));
				if (c != null){
					for(int child = 0; child<=c.length; child++) {
						nodes.get(i).children.addAll(searchForNodeWithId(child, nodes));
						//System.out.println(child);
					}
				}
			}
			
			Main.wordTree.origin = searchForNodeWithId(1, nodes).get(0);
			//System.out.println(Arrays.toString(nodeChildren.get(nodes.get(2))));
			System.out.println(Main.wordTree.origin.children.get(0).content);

		}catch(Exception e){ 
			System.out.println(e);
		}  
		
	
	}
	public static ArrayList<Node> searchForNodeWithId(int id, ArrayList<Node> n){
		ArrayList<Node> f = new ArrayList<Node>();
		for(int i = 0; i<n.size(); i++) {
			if (n.get(i).id == id){
				f.add(n.get(i));
			}
		}
		return f;
	} 

}



/*
Create hashmap (a) of Node objects  --> int arrays
for element in query result
	Create Node Object with id, content, priority... of element
	Create int array of element.children
	Add relation to hashmap (a) of Node object --> int array
Create arraylist (d) of nodes from hashmap 

for element in arraylist (d)
	for c in a.get(element)<commit_msg>wordTree construction actually works now<commit_after>package Autocomplete;

import java.sql.*;
import java.util.*;


class Database extends Main{  
	public static void main(String args[]){  
		try{  
			Connection con=DriverManager.getConnection("jdbc:mysql://box1275.bluehost.com:3306/jlindber_autocomplete","jlindber_public","Gnx-H7G-BBf-gdk");  
			constructWordTree(con);
			Statement stmt=con.createStatement();  
			//Boolean r=stmt.execute("INSERT INTO `jlindber_autocomplete`.`charTree` (`address`, `content`, `priority`, `isWord`, `children`) VALUES (NULL, 't', '0', '1', NULL);"); 
			ResultSet rs=stmt.executeQuery("SELECT * FROM `wordTree`");  
			ResultSetMetaData rsmd = rs.getMetaData();
			System.out.println(rsmd);
			while(rs.next()){  
				for (int i = 1; i<5; i++){
				System.out.print(rsmd.getColumnTypeName(i) +": "+rs.getObject(i) + "     ");  
				}
				System.out.println(" ");
			}
			con.close();  
		}catch(Exception e){ 
			System.out.println(e);
		}  
	}  

	public static void constructCharTree(Connection con){
		try{  
			Statement stmt=con.createStatement();  
			ResultSet rs=stmt.executeQuery("SELECT * FROM `charTree`"); 
			HashMap<Node,int[]> nodeChildren =new HashMap<Node,int[]>(); 
			ArrayList<Node> nodes = new ArrayList<Node>();
			while(rs.next()){
				Node n = new Node(rs.getInt("id"), rs.getString("content"),rs.getInt("priority"), rs.getBoolean("isWord"));
				nodes.add(n);
				String childString = rs.getString("children");
				if (childString!=null){
					String[] childrenStringArray = childString.split(",");
					int[] childrenIntArray = new int[childrenStringArray.length];
					for(int i = 0; i<childrenStringArray.length; i++) {
						childrenIntArray[i] = Integer.parseInt(childrenStringArray[i]);
					}
					nodeChildren.put(n, childrenIntArray);
				}else{
					nodeChildren.put(n, null);
					}
			} 
			
			for(int i = 0; i<nodes.size(); i++) {
				int[] c = nodeChildren.get(nodes.get(i));
				if (c != null){
					for(int child = 0; child<c.length; child++) {
						nodes.get(i).children.addAll(searchForNodeWithId(c[child], nodes));
						//System.out.println(child);
					}
				}
			}
			
			Main.charTree.origin = searchForNodeWithId(1, nodes).get(0);
			//System.out.println(Arrays.toString(nodeChildren.get(nodes.get(2))));
			//System.out.println(nodes);

		}catch(Exception e){ 
			System.out.println(e);
		}  
		
	
	}
	
	
	public static void constructWordTree(Connection con){
		try{  
			Statement stmt=con.createStatement();  
			ResultSet rs=stmt.executeQuery("SELECT * FROM `wordTree`"); 
			HashMap<Node,int[]> nodeChildren =new HashMap<Node,int[]>(); 
			ArrayList<Node> nodes = new ArrayList<Node>();
			while(rs.next()){
				Node n = new Node(rs.getInt("id"), rs.getString("content"),rs.getInt("priority"),false);
				nodes.add(n);
				String childString = rs.getString("children");
				if (childString!=null){
					String[] childrenStringArray = childString.split(",");
					int[] childrenIntArray = new int[childrenStringArray.length];
					for(int i = 0; i<childrenStringArray.length; i++) {
						childrenIntArray[i] = Integer.parseInt(childrenStringArray[i]);
					}
					nodeChildren.put(n, childrenIntArray);
				}else{
					nodeChildren.put(n, null);
					}
			} 
			
			for(int i = 0; i<nodes.size(); i++) {
				int[] c = nodeChildren.get(nodes.get(i));
				if (c != null){
					for(int child = 0; child<c.length; child++) {
						nodes.get(i).children.addAll(searchForNodeWithId(c[child], nodes));
						System.out.println(child);
					}
				}
			}
			
			Main.wordTree.origin = searchForNodeWithId(1, nodes).get(0);
			//System.out.println(Arrays.toString(nodeChildren.get(nodes.get(2))));
			System.out.println(Main.wordTree.origin.children.get(0).children.get(0).content);

		}catch(Exception e){ 
			System.out.println(e);
		}  
		
	
	}
	public static ArrayList<Node> searchForNodeWithId(int id, ArrayList<Node> n){
		ArrayList<Node> f = new ArrayList<Node>();
		for(int i = 0; i<n.size(); i++) {
			if (n.get(i).id == id){
				f.add(n.get(i));
			}
		}
		return f;
	} 

}



/*
Create hashmap (a) of Node objects  --> int arrays
for element in query result
	Create Node Object with id, content, priority... of element
	Create int array of element.children
	Add relation to hashmap (a) of Node object --> int array
Create arraylist (d) of nodes from hashmap 

for element in arraylist (d)
	for c in a.get(element)
{'fraction_non_alphanumeric': 0.16767285567832327, 'fraction_numerical': 0.00626495044993735, 'mean_word_length': 3.638140517696778, 'pattern_counts': {'":': 2, '<': 43, '<?xml version=': 0, '>': 31, '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': '4487960', 'n_tokens_mistral': 3511, 'n_tokens_neox': 2929, 'n_words': 583}