<commit_before>package ingraph.report.generator

import ingraph.cypher2relalg.Cypher2Relalg
import ingraph.logger.IngraphLogger
import ingraph.relalg.inferencers.BasicSchemaInferencer
import ingraph.relalg.inferencers.ExtraVariableInferencer
import ingraph.relalg.inferencers.FullSchemaInferencer
import ingraph.relalg2rete.Relalg2ReteTransformation
import ingraph.relalg2tex.config.RelalgConverterConfig
import ingraph.relalg2tex.converters.relalgconverters.Relalg2TexExpressionConverter
import ingraph.relalg2tex.converters.relalgconverters.Relalg2TexTreeConverter
import ingraph.report.generator.data.TestQuery
import ingraph.report.generator.util.TechReportEscaper
import java.util.ArrayList
import java.util.List
import org.apache.commons.lang3.exception.ExceptionUtils
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtend.lib.annotations.Accessors
import relalg.RelalgContainer

class QueryProcessor {
	
	extension Relalg2ReteTransformation Relalg2ReteTransformation = new Relalg2ReteTransformation
	extension BasicSchemaInferencer basicSchemaInferencer = new BasicSchemaInferencer
	extension ExtraVariableInferencer extraVariableInferencer = new ExtraVariableInferencer
	extension FullSchemaInferencer fullSchemaInferencer = new FullSchemaInferencer
	extension TechReportEscaper escaper = new TechReportEscaper
	extension IngraphLogger logger = new IngraphLogger(QueryProcessor.name)

	protected val treeSerializerConfig = RelalgConverterConfig.builder.includeCommonVariables(true).textualOperators(true).build
	protected val treeSerializer = new Relalg2TexTreeConverter(treeSerializerConfig)
	protected val expressionConverter = new Relalg2TexExpressionConverter

	@Accessors(PUBLIC_GETTER) var totalQueries = 0
	@Accessors(PUBLIC_GETTER) var compilingQueries = 0
	@Accessors(PUBLIC_GETTER) val List<CharSequence> subsections = new ArrayList

	def void processQueries(Iterable<TestQuery> testQueries) {
		for (testQuery : testQueries) {
			toSubsection(testQuery)
		}
	}

	def void toSubsection(TestQuery testQuery) {
		totalQueries++
		var RelalgContainer container = null
		try {
			container = Cypher2Relalg.processString(testQuery.querySpecification)
			compilingQueries++
		} catch (Exception e) {
			error(ExceptionUtils.getStackTrace(e))
		}
		subsections.add(subsection(container, testQuery.queryName, testQuery.querySpecification, testQuery.regressionTest))
	}

	def subsection(RelalgContainer container, String name, String listing, boolean regressionTest) {
		'''
		\subsection[«name.escape»]{«name.escape»«IF (regressionTest)» \textcolor{gray}{[regression test]}«ENDIF»}

		\subsubsection*«"Query specification".toHeader(name)»

		\begin{lstlisting}
		«listing»
		\end{lstlisting}
<commit_msg>Only use info loglevel for errors<commit_after>package ingraph.report.generator

import ingraph.cypher2relalg.Cypher2Relalg
import ingraph.logger.IngraphLogger
import ingraph.relalg.inferencers.BasicSchemaInferencer
import ingraph.relalg.inferencers.ExtraVariableInferencer
import ingraph.relalg.inferencers.FullSchemaInferencer
import ingraph.relalg2rete.Relalg2ReteTransformation
import ingraph.relalg2tex.config.RelalgConverterConfig
import ingraph.relalg2tex.converters.relalgconverters.Relalg2TexExpressionConverter
import ingraph.relalg2tex.converters.relalgconverters.Relalg2TexTreeConverter
import ingraph.report.generator.data.TestQuery
import ingraph.report.generator.util.TechReportEscaper
import java.util.ArrayList
import java.util.List
import org.apache.commons.lang3.exception.ExceptionUtils
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtend.lib.annotations.Accessors
import relalg.RelalgContainer

class QueryProcessor {
	
	extension Relalg2ReteTransformation Relalg2ReteTransformation = new Relalg2ReteTransformation
	extension BasicSchemaInferencer basicSchemaInferencer = new BasicSchemaInferencer
	extension ExtraVariableInferencer extraVariableInferencer = new ExtraVariableInferencer
	extension FullSchemaInferencer fullSchemaInferencer = new FullSchemaInferencer
	extension TechReportEscaper escaper = new TechReportEscaper
	extension IngraphLogger logger = new IngraphLogger(QueryProcessor.name)

	protected val treeSerializerConfig = RelalgConverterConfig.builder.includeCommonVariables(true).textualOperators(true).build
	protected val treeSerializer = new Relalg2TexTreeConverter(treeSerializerConfig)
	protected val expressionConverter = new Relalg2TexExpressionConverter

	@Accessors(PUBLIC_GETTER) var totalQueries = 0
	@Accessors(PUBLIC_GETTER) var compilingQueries = 0
	@Accessors(PUBLIC_GETTER) val List<CharSequence> subsections = new ArrayList

	def void processQueries(Iterable<TestQuery> testQueries) {
		for (testQuery : testQueries) {
			toSubsection(testQuery)
		}
	}

	def void toSubsection(TestQuery testQuery) {
		totalQueries++
		var RelalgContainer container = null
		try {
			container = Cypher2Relalg.processString(testQuery.querySpecification)
			compilingQueries++
		} catch (Exception e) {
			info("An error occurred during the compilation of the query:")
			info(ExceptionUtils.getStackTrace(e))
		}
		subsections.add(subsection(container, testQuery.queryName, testQuery.querySpecification, testQuery.regressionTest))
	}

	def subsection(RelalgContainer container, String name, String listing, boolean regressionTest) {
		'''
		\subsection[«name.escape»]{«name.escape»«IF (regressionTest)» \textcolor{gray}{[regression test]}«ENDIF»}

		\subsubsection*«"Query specification".toHeader(name)»

		\begin{lstlisting}
		«listing»
		\end{lstlisting}

{'fraction_non_alphanumeric': 0.07126104997293885, 'fraction_numerical': 0.006494677972217211, 'mean_word_length': 7.555555555555555, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7592018', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1606, 'n_words': 334}