Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Steiner Triples and Sat Solvers
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lucy Anne Patton
Steiner Triples and Sat Solvers
Commits
b5cc5681
Commit
b5cc5681
authored
4 years ago
by
Lucy Anne Patton
Browse files
Options
Downloads
Patches
Plain Diff
Uploaded Transformer.py
parent
8daa3c97
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Transformers/Transformer.py
+58
-0
58 additions, 0 deletions
Transformers/Transformer.py
with
58 additions
and
0 deletions
Transformers/Transformer.py
0 → 100644
+
58
−
0
View file @
b5cc5681
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment