From b5cc5681eddc7e46a616db29c27da4392d58981f Mon Sep 17 00:00:00 2001 From: "Luke A. Patton" <lap368@drexel.edu> Date: Thu, 11 Mar 2021 17:21:19 +0000 Subject: [PATCH] Uploaded Transformer.py --- Transformers/Transformer.py | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Transformers/Transformer.py diff --git a/Transformers/Transformer.py b/Transformers/Transformer.py new file mode 100644 index 0000000..b593382 --- /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 -- GitLab