<commit_before>package allow.simulator.knowledge.crf;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import allow.simulator.entity.Entity;
import allow.simulator.knowledge.TravelExperience;
import allow.simulator.knowledge.crf.DBConnector.DBType;

public class CRFLocalKnowledge implements CRFKnowledgeModel {
	
	private static final String MY_SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS %1$s "
			+ "(nodeId INT, prevNodeId INT, weather TINYINT UNSIGNED, weekday TINYINT UNSIGNED, "
			+ "timeOfDay TINYINT UNSIGNED, modality TINYINT UNSIGNED, ttime FLOAT, prevttime FLOAT, "
			+ "fillLevel FLOAT, weight DOUBLE, "
			+ "PRIMARY KEY(nodeId, prevNodeId, weather, weekday, timeOfDay, modality));%2$s";
	
//	private static final String POSTGRE_SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS %1$s "
//			+ " (entryNo SERIAL PRIMARY KEY, nodeId INTEGER, prevNodeId INTEGER, "
//			+ "weather SMALLINT, weekday SMALLINT, "
//			+ "timeOfDay SMALLINT, modality SMALLINT, ttime REAL, prevttime REAL, fillLevel REAL, "
//			+ "number REAL, "
//			+ "UNIQUE(nodeId, prevNodeId, weather, weekday, timeOfDay, modality)); "
//			+ "CREATE INDEX on %2$s "
//			+ "(nodeId, modality, timeOfDay, weekday, prevNodeId, prevttime)";
	
//	private static final String MY_SQL_SHOW_TABLES = "SHOW TABLES LIKE '%1$s'";
	
//	private static final String POSTGRE_SQL_SHOW_TABLES = "SELECT * FROM pg_catalog.pg_tables where "
//			+ "tablename like '%1s'";
	
	private static final String SQL_INSERT_VALUES = "INSERT INTO %1$s "
			+ " (nodeId, prevNodeId, weather, weekday, timeOfDay, modality, ttime, prevttime, fillLevel, weight)"
			+ " VALUES ";
	
	private static final String MY_SQL_UPDATE_ON_INSERT = "ON DUPLICATE KEY UPDATE "
			+ "ttime=(%1$s.ttime * %1$s.weight + VALUES(ttime)) / (%1$s.weight + 1), "
			+ "prevttime=(%1$s.prevttime * %1$s.weight + VALUES(prevttime)) / (%1$s.weight + 1), "
			+ "filllevel=(%1$s.filllevel * %1$s.weight + VALUES(filllevel)) / (%1$s.weight + 1), "
			+ "weight=LN(EXP(%1$s.weight) + EXP(1))";
	
	private static final String MY_SQL_MERGE_SIMPLE = "CREATE TABLE IF NOT EXISTS %1$s AS SELECT * FROM %2$s; "
			+ "ALTER TABLE %1$s ADD PRIMARY KEY(nodeId, prevNodeId, weather, weekday, timeOfDay, modality);";
			// + ", startTime INT UNSIGNED, endTime INT UNSIGNED, "
			// + "ALTER TABLE %1$s ADD INDEX(nodeId, prevNodeId, weather, weekday, timeOfDay, modality);";
	
	private static final String MY_SQL_MERGE_MUTUAL = 
			"CREATE TEMPORARY TABLE ex AS (SELECT nodeId, prevNodeId, weather, "
			+ "weekday, timeOfDay, modality, ttime, prevttime, filllevel, weight FROM %1$s); "
			
			+ "INSERT INTO %1$s (SELECT * FROM %2$s) "
			+ "ON DUPLICATE KEY UPDATE "
			+ "ttime=(%1$s.ttime*%1$s.weight+VALUES(ttime)*VALUES(weight))/(%1$s.weight+VALUES(weight)), "
			+ "prevttime=(%1$s.prevttime*%1$s.weight+VALUES(prevttime)*VALUES(weight))/(%1$s.weight+VALUES(weight)), "
			+ "filllevel=(%1$s.filllevel*%1$s.weight+VALUES(filllevel)*VALUES(weight))/(%1$s.weight+VALUES(weight)), "
			+ "weight=LN(EXP(%1$s.weight)+EXP(VALUES(weight))); "
			
			+ "INSERT INTO %2$s (SELECT * FROM ex) "
			+ "ON DUPLICATE KEY UPDATE "<commit_msg>* Removed unnecessary statements<commit_after>package allow.simulator.knowledge.crf;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import allow.simulator.entity.Entity;
import allow.simulator.knowledge.TravelExperience;
import allow.simulator.knowledge.crf.DBConnector.DBType;

public class CRFLocalKnowledge implements CRFKnowledgeModel {
	
	private static final String MY_SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS %1$s "
			+ "(nodeId INT, prevNodeId INT, weather TINYINT UNSIGNED, weekday TINYINT UNSIGNED, "
			+ "timeOfDay TINYINT UNSIGNED, modality TINYINT UNSIGNED, ttime FLOAT, prevttime FLOAT, "
			+ "fillLevel FLOAT, weight DOUBLE, "
			+ "PRIMARY KEY(nodeId, prevNodeId, weather, weekday, timeOfDay, modality));%2$s";
	
	private static final String SQL_INSERT_VALUES = "INSERT INTO %1$s "
			+ " (nodeId, prevNodeId, weather, weekday, timeOfDay, modality, ttime, prevttime, fillLevel, weight)"
			+ " VALUES ";
	
	private static final String MY_SQL_UPDATE_ON_INSERT = "ON DUPLICATE KEY UPDATE "
			+ "ttime=(%1$s.ttime * %1$s.weight + VALUES(ttime)) / (%1$s.weight + 1), "
			+ "prevttime=(%1$s.prevttime * %1$s.weight + VALUES(prevttime)) / (%1$s.weight + 1), "
			+ "filllevel=(%1$s.filllevel * %1$s.weight + VALUES(filllevel)) / (%1$s.weight + 1), "
			+ "weight=LN(EXP(%1$s.weight) + EXP(1))";
	
	private static final String MY_SQL_MERGE_SIMPLE = "CREATE TABLE IF NOT EXISTS %1$s AS SELECT * FROM %2$s; "
			+ "ALTER TABLE %1$s ADD PRIMARY KEY(nodeId, prevNodeId, weather, weekday, timeOfDay, modality);";
	
	private static final String MY_SQL_MERGE_MUTUAL = 
			"CREATE TEMPORARY TABLE ex AS (SELECT nodeId, prevNodeId, weather, "
			+ "weekday, timeOfDay, modality, ttime, prevttime, filllevel, weight FROM %1$s); "
			
			+ "INSERT INTO %1$s (SELECT * FROM %2$s) "
			+ "ON DUPLICATE KEY UPDATE "
			+ "ttime=(%1$s.ttime*%1$s.weight+VALUES(ttime)*VALUES(weight))/(%1$s.weight+VALUES(weight)), "
			+ "prevttime=(%1$s.prevttime*%1$s.weight+VALUES(prevttime)*VALUES(weight))/(%1$s.weight+VALUES(weight)), "
			+ "filllevel=(%1$s.filllevel*%1$s.weight+VALUES(filllevel)*VALUES(weight))/(%1$s.weight+VALUES(weight)), "
			+ "weight=LN(EXP(%1$s.weight)+EXP(VALUES(weight))); "
			
			+ "INSERT INTO %2$s (SELECT * FROM ex) "
			+ "ON DUPLICATE KEY UPDATE "
{'fraction_non_alphanumeric': 0.151098410430434, 'fraction_numerical': 0.013038042507590641, 'mean_word_length': 4.839416058394161, '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': '3436115', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2042, 'n_words': 457}