<commit_before>"""
This module holds the class for the EsperTransformer.
"""
from arionBackend.models.event_type import EventType
from arionBackend.models.hierarchy import Hierarchy
from arionBackend.models.query import Query
from arionBackend.transformation.esper.esper_query import QueryParser
from arionBackend.transformation.esper.event_type_retriever import EventTypeRetriever
from arionBackend.transformation.transformer import Transformer


class EsperTransformer(Transformer):
	"""
	This class extends the abstract base class Transformer and implements a transformer for Esper EPL.
	"""

	def transform(self, name, queries):
		"""
		This method transform an Esper EPL query into a hierarchy.
		:param name: name of hierarchy
		:param queries: Esper EPL queries
		"""

		hierarchy = Hierarchy(name=name, json_representation={})
		hierarchy.save()
		query_objects = []
		concerned_event_types = []
		feeding_event_type_objects = []
		for query in queries:
			parsed_query = QueryParser.parse_query_to_eqmn(query)
			if parsed_query:
				inserting_event_type, created = EventType.objects.get_or_create(
					name=EventTypeRetriever.find_inserting_event_type(parsed_query["eqmn_representation"]["output"]),
					hierarchy=hierarchy)
				concerned_event_types.append(inserting_event_type)
				feeding_event_types = list(EventTypeRetriever.find_feeding_event_types(
					parsed_query["eqmn_representation"]["input"]))
				for feeding_event_type in feeding_event_types:
					event_type, created = EventType.objects.get_or_create(
						name=feeding_event_type, hierarchy=hierarchy)
					feeding_event_type_objects.append(event_type)
				query = Query(
					query_string=query, hierarchy=hierarchy, eqmn_representation=parsed_query["eqmn_representation"],
					output_event_type=inserting_event_type)
				query.save()
				query.inserting_event_types.set(feeding_event_type_objects)
				query.save()
				query_objects.append(query)
			else:
				for query in query_objects:
					query.delete()
				for event_type in list(set(concerned_event_types + feeding_event_type_objects)):
					event_type.delete()
				hierarchy.delete()
				return False
		return True<commit_msg>fixing garbage collection if queries are malformed<commit_after>"""
This module holds the class for the EsperTransformer.
"""
from arionBackend.models.event_type import EventType
from arionBackend.models.hierarchy import Hierarchy
from arionBackend.models.query import Query
from arionBackend.transformation.esper.esper_query import QueryParser
from arionBackend.transformation.esper.event_type_retriever import EventTypeRetriever
from arionBackend.transformation.transformer import Transformer


class EsperTransformer(Transformer):
	"""
	This class extends the abstract base class Transformer and implements a transformer for Esper EPL.
	"""

	def transform(self, name, queries):
		"""
		This method transform an Esper EPL query into a hierarchy.
		:param name: name of hierarchy
		:param queries: Esper EPL queries
		"""

		hierarchy = Hierarchy(name=name, json_representation={})
		hierarchy.save()
		query_objects = []
		for query in queries:
			parsed_query = QueryParser.parse_query_to_eqmn(query)
			feeding_event_type_objects = []
			if parsed_query:
				output_event_type, created = EventType.objects.get_or_create(
					name=EventTypeRetriever.find_inserting_event_type(parsed_query["eqmn_representation"]["output"]),
					hierarchy=hierarchy)
				feeding_event_types = list(EventTypeRetriever.find_feeding_event_types(
					parsed_query["eqmn_representation"]["input"]))
				for feeding_event_type in feeding_event_types:
					event_type, created = EventType.objects.get_or_create(
						name=feeding_event_type, hierarchy=hierarchy)
					feeding_event_type_objects.append(event_type)
				query = Query(
					query_string=query, hierarchy=hierarchy, eqmn_representation=parsed_query["eqmn_representation"],
					output_event_type=output_event_type)
				query.save()
				query.inserting_event_types.set(feeding_event_type_objects)
				query.save()
				query_objects.append(query)
			else:
				hierarchy.delete()
				return False
		return True
{'fraction_non_alphanumeric': 0.0779126213592233, 'fraction_numerical': 0.0, 'mean_word_length': 5.572567783094099, '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': '4112026', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1247, 'n_words': 262}