Skip to content

Instantly share code, notes, and snippets.

@BoeingX
Created April 4, 2018 19:08
Show Gist options
  • Select an option

  • Save BoeingX/033f0b22a6c758d007da63e46e1db69a to your computer and use it in GitHub Desktop.

Select an option

Save BoeingX/033f0b22a6c758d007da63e46e1db69a to your computer and use it in GitHub Desktop.
Example of pipeline
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)
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