Skip to content
Snippets Groups Projects
Commit b5cc5681 authored by Lucy Anne Patton's avatar Lucy Anne Patton :speech_balloon:
Browse files

Uploaded Transformer.py

parent 8daa3c97
Branches
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 25 15:08:15 2021
@author: lukepatton
"""
class Transformer:
def __init__(self, transformation, criteria):
self.transformation = transformation
self.criteria = criteria
def check(self, input_set, output_set):
return self.criteria(self.transformation, input_set, output_set)
def transform(self, transformee):
return self.transformation(transformee)
class OneToOneNumberTransformer(Transformer):
def __init__(self, transformation_dictionary):
self.transformation_dictionary = transformation_dictionary
transformation = lambda a: [(transformation_dictionary[i] if i in transformation_dictionary else i) for i in a]
super().__init__(transformation, self.__criteria)
def __criteria(self, transformation, input_set, output_set):
passes = True
for sequence in input_set:
transformed = transformation(sequence)
matching_inputs = [a for a in input_set if set(a) == set(sequence)]
matching_outputs = [b for b in output_set if set(b) == set(transformed)]
if len(matching_inputs) != len(matching_outputs):
passes = False
return passes
class ReorderTransformer(Transformer):
def __init__(self, transformation_order_dictionary):
self.transformation_order_dictionary = transformation_order_dictionary
transformation = lambda a: self.__transformation(a, transformation_order_dictionary)
criteria = lambda a, b, c: True
super().__init__(transformation, criteria)
def __transformation(self, a, transformation_dictionary):
new_sequence = [None for key in transformation_dictionary]
print(new_sequence)
for key in transformation_dictionary:
new_sequence[transformation_dictionary[key]] = a[key]
return new_sequence
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment