Created
April 4, 2018 19:08
-
-
Save BoeingX/033f0b22a6c758d007da63e46e1db69a to your computer and use it in GitHub Desktop.
Example of pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pipeline import pipeline | |
| class Cleaner(object): | |
| def __init__(self): | |
| self.pipeline = pipeline | |
| def add_pipeline(self, p): | |
| self.pipeline.append(p) | |
| def __call__(self, s): | |
| for p in pipeline: | |
| s = p(s) | |
| return s | |
| def __repr__(self): | |
| return ' '.join([p.__name__ for p in self.pipeline]) | |
| if __name__ == '__main__': | |
| print(pipeline) | |
| s = 'TEST me' | |
| cleaner = Cleaner() | |
| print(cleaner) | |
| s = cleaner(s) | |
| print(s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| pipeline = [] | |
| def registry(func): | |
| pipeline.append(func) | |
| return func | |
| @registry | |
| def lowercase(s): | |
| return s.lower() | |
| @registry | |
| def remove_extra_spaces(s): | |
| return re.sub('\s+', ' ', s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment