diff --git a/Transformers/Transformer.py b/Transformers/Transformer.py new file mode 100644 index 0000000000000000000000000000000000000000..b593382acb3e85ce12b482e30674bb30fc9b16f6 --- /dev/null +++ b/Transformers/Transformer.py @@ -0,0 +1,58 @@ +#!/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