<commit_before>package annis.sqlgen;

import annis.model.AnnisNode;
import annis.model.AnnisNode.TextMatching;

public class BaseNodeSqlGenerator {

	// pluggable access to tables representing the node
	private TableAccessStrategyFactory tableAccessStrategyFactory;
	
	///// Helpers
	
	protected TableAccessStrategy tables(AnnisNode node) {
		return tableAccessStrategyFactory.createTableAccessStrategy(node);
	}
	
	protected String tableAliasDefinition(AnnisNode node, String table, int count) {
		StringBuffer sb = new StringBuffer();
	
		sb.append(tables(node).tableName(table));
		sb.append(" AS ");
		sb.append(tables(node).aliasedTable(table, count));
	
		return sb.toString();
	}

	protected String join(String op, String lhs, String rhs) {
		return lhs + " " + op + " " + rhs;
	}

	protected String numberJoin(String op, String lhs, String rhs,
			int offset) {
				String plus = offset >= 0 ? " + " : " - ";
				return join(op, lhs, rhs) + plus + String.valueOf(Math.abs(offset));
			}
	
	protected String between(String lhs, String rhs, int min, int max) {
		String minPlus = min >= 0 ? " + " : " - ";
		String maxPlus = max >= 0 ? " + " : " - ";
		return lhs + " BETWEEN SYMMETRIC " + rhs + minPlus + String.valueOf(Math.abs(min)) + " AND " + rhs + maxPlus + String.valueOf(Math.abs(max));
	}

	protected String between(String lhs, int min, int max) {
		return lhs + " BETWEEN SYMMETRIC " + min + " AND " + max;
	}

	protected String sqlString(String string) {
		return "'" + string + "'";
	}

	protected String sqlString(String string, TextMatching textMatching) {
		if (textMatching == TextMatching.REGEXP_EQUAL)
			string = "^" + string + "$";
		return sqlString(string);
	}

	///// Getter / Setter

	public TableAccessStrategyFactory getTableAccessStrategyFactory() {
		return tableAccessStrategyFactory;
	}

	public void setTableAccessStrategyFactory(TableAccessStrategyFactory tableAccessStrategyFactory) {<commit_msg>- trying to escape SQL strings<commit_after>package annis.sqlgen;

import annis.model.AnnisNode;
import annis.model.AnnisNode.TextMatching;
import org.apache.commons.lang.StringEscapeUtils;

public class BaseNodeSqlGenerator {

	// pluggable access to tables representing the node
	private TableAccessStrategyFactory tableAccessStrategyFactory;
	
	///// Helpers
	
	protected TableAccessStrategy tables(AnnisNode node) {
		return tableAccessStrategyFactory.createTableAccessStrategy(node);
	}
	
	protected String tableAliasDefinition(AnnisNode node, String table, int count) {
		StringBuffer sb = new StringBuffer();
	
		sb.append(tables(node).tableName(table));
		sb.append(" AS ");
		sb.append(tables(node).aliasedTable(table, count));
	
		return sb.toString();
	}

	protected String join(String op, String lhs, String rhs) {
		return lhs + " " + op + " " + rhs;
	}

	protected String numberJoin(String op, String lhs, String rhs,
			int offset) {
				String plus = offset >= 0 ? " + " : " - ";
				return join(op, lhs, rhs) + plus + String.valueOf(Math.abs(offset));
			}
	
	protected String between(String lhs, String rhs, int min, int max) {
		String minPlus = min >= 0 ? " + " : " - ";
		String maxPlus = max >= 0 ? " + " : " - ";
		return lhs + " BETWEEN SYMMETRIC " + rhs + minPlus + String.valueOf(Math.abs(min)) + " AND " + rhs + maxPlus + String.valueOf(Math.abs(max));
	}

	protected String between(String lhs, int min, int max) {
		return lhs + " BETWEEN SYMMETRIC " + min + " AND " + max;
	}

	protected String sqlString(String string) {
		return "'" + StringEscapeUtils.escapeSql(string) + "'";
	}

	protected String sqlString(String string, TextMatching textMatching) {
		if (textMatching == TextMatching.REGEXP_EQUAL)
			string = "^" + string + "$";
		return sqlString(string);
	}

	///// Getter / Setter

	public TableAccessStrategyFactory getTableAccessStrategyFactory() {
		return tableAccessStrategyFactory;
	}

	public void setTableAccessStrategyFactory(TableAccessStrategyFactory tableAccessStrategyFactory) {
{'fraction_non_alphanumeric': 0.12128088754412507, 'fraction_numerical': 0.0015128593040847202, 'mean_word_length': 4.206036745406824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823740', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1204, 'n_words': 309}